Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some Basic Routes #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Anuradha-Udatha
Copy link
Collaborator

Added User and Project schema and written code for controllers.

institute String
yearOfStudy Int
interests String[]
isAdmin Boolean
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make the default value of isAdmin to be "false"


model Project {
id Int @id @default(autoincrement())
slug String @unique @default("")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need the default value of slug?

blogRouter.get('/',getAllBlogs);
blogRouter.get('/myblogs',authMiddleware,getMyBlogs);
blogRouter.get('/:slug',getBlogByslug);
blogRouter.get('/userblogs/:username',getUserBlogs);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be done in this way:
To get a blog post - /blog/:slug
To get all of blogs - /blogs
To get the blogs of a user - /blogs/:username (It also covers /blogs/myblogs, so there shouldn't be a need of that)

projectRouter.post('/create', authMiddleware, createProject);
projectRouter.put('/update/:slug',authMiddleware,updateProject);
projectRouter.delete('/delete/:slug',authMiddleware,deleteProject);
projectRouter.get('/myprojects',authMiddleware,getMyProjects);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For update we can just make a PUT request to /:slug and for delete we can make a DELETE request to /:slug.

Here also, we can remove the path /myprojects and just keep /:username (means /projects/:username.

userRouter.get('/',authMiddleware, fetchUserDetails);
userRouter.put('/',authMiddleware,userUpdate);
userRouter.post('/add-bookmark',authMiddleware,addBookmark);
userRouter.delete('/remove-bookmark',authMiddleware,removeBookmark);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just put /bookmark path for both of these requests? As the methods post and delete already convey the we are creating and deleting the bookmark.

institute: zod
.string()
.min(1, "Institute is required")
.max(100, "Institute name must be 100 characters or fewer"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding enum to Institute field? For now we can just put IIT Kharagpur to it?

const createProjectSchema = projectBaseSchema;
const updateProjectSchema = projectBaseSchema.extend({
slug: zod.string().optional(),
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to include the slug in projectBaseSchema only?

const id = decoded.id;
if (isNaN(id)) {
return res.status(400).json({ message: "Invalid ID format", success: false });
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition is not required as we are already checking !decoded.id in the previous condition...

const { email, password } = parseResult.data;
if (!email.endsWith("@iitkgp.ac.in")) {
return res.status(400).json({
message: "Email must end with @iitkgp.ac.in",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The email should end with @kgpian.itkgp.ac.in and I think the message could be Please enter Institute email address

return res.status(400).json({
message: "Invalid inputs",
success:false
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to return the exact error when zod validation fails instead of Invalid inputs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants