-
Notifications
You must be signed in to change notification settings - Fork 2
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
NW6 | Zeliha Pala | Full-Stack-Project | Week-2 | DELETE-videos-endpoint #25
Changes from 1 commit
3d7ac5b
676ab6e
2b59f10
574e88d
9f3e408
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,29 @@ | |
res.status(200).json({ success: true, data: { id: newVideoId } }); | ||
}); | ||
|
||
router.delete("/videos/:id", async (req, res) => { | ||
const videoId = req.params.id; | ||
|
||
try { | ||
const checkQuery = await db.query("SELECT * FROM videos WHERE id = $1", [ | ||
`${videoId}`, | ||
]); | ||
if (checkQuery.rows.length === 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good work 👏 |
||
return res.status(404).json({ | ||
message: "Video not found", | ||
}); | ||
} | ||
|
||
const deleteQuery = await db.query("DELETE FROM videos WHERE id = $1", [ | ||
videoId, | ||
]); | ||
|
||
return res.status(204).end(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would normally return 200 here. 204 is very rarely used so users might think its an error |
||
} catch (error) { | ||
res | ||
.status(500) | ||
.json({ message: "Internal server error", error: this.error }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good to see you're sending the error back rather than a boilerplate message. In production proper however, it's worth thinking about what parts of the error object the user actually needs and sending those bits back so that there is only the info they need. No need for this project There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for your reviews I have changed some parts of my codes according to your recommendations. |
||
} | ||
}); | ||
|
||
export default router; |
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.
It's good to see you preventing SQL Injection by using parameters! 🙌 If you’re not sure what I'm on about, Google SQL Injection. @RbAvci This is a good example of preventing SQL Injection.