-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Added some Basic Routes #1
Conversation
prisma/schema.prisma
Outdated
institute String | ||
yearOfStudy Int | ||
interests String[] | ||
isAdmin Boolean |
There was a problem hiding this comment.
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"
prisma/schema.prisma
Outdated
|
||
model Project { | ||
id Int @id @default(autoincrement()) | ||
slug String @unique @default("") |
There was a problem hiding this comment.
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?
src/Routers/blogRoute.ts
Outdated
blogRouter.get('/',getAllBlogs); | ||
blogRouter.get('/myblogs',authMiddleware,getMyBlogs); | ||
blogRouter.get('/:slug',getBlogByslug); | ||
blogRouter.get('/userblogs/:username',getUserBlogs); |
There was a problem hiding this comment.
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)
src/Routers/projectRoute.ts
Outdated
projectRouter.post('/create', authMiddleware, createProject); | ||
projectRouter.put('/update/:slug',authMiddleware,updateProject); | ||
projectRouter.delete('/delete/:slug',authMiddleware,deleteProject); | ||
projectRouter.get('/myprojects',authMiddleware,getMyProjects); |
There was a problem hiding this comment.
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
.
src/Routers/userRoute.ts
Outdated
userRouter.get('/',authMiddleware, fetchUserDetails); | ||
userRouter.put('/',authMiddleware,userUpdate); | ||
userRouter.post('/add-bookmark',authMiddleware,addBookmark); | ||
userRouter.delete('/remove-bookmark',authMiddleware,removeBookmark); |
There was a problem hiding this comment.
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.
src/Validation/ZodValidation.ts
Outdated
institute: zod | ||
.string() | ||
.min(1, "Institute is required") | ||
.max(100, "Institute name must be 100 characters or fewer"), |
There was a problem hiding this comment.
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?
src/Validation/ZodValidation.ts
Outdated
const createProjectSchema = projectBaseSchema; | ||
const updateProjectSchema = projectBaseSchema.extend({ | ||
slug: zod.string().optional(), | ||
}) |
There was a problem hiding this comment.
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?
src/middlewares/auth.ts
Outdated
const id = decoded.id; | ||
if (isNaN(id)) { | ||
return res.status(400).json({ message: "Invalid ID format", success: false }); | ||
} |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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 | ||
}); |
There was a problem hiding this comment.
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
Added User and Project schema and written code for controllers.