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

NW6 | Zeliha Pala | Full-Stack-Project | Week-2 | DELETE-videos-endpoint #25

Merged
merged 5 commits into from
May 26, 2024

Conversation

zelihapala
Copy link
Collaborator

  • Handle non-existent IDs with 404
  • Return 204 on successful deletion
  • Use parameterized queries
  • Consistent error handling

- Handle non-existent IDs with 404
- Return 204 on successful deletion
- Use parameterized queries
- Consistent error handling
Copy link

netlify bot commented May 16, 2024

Deploy Preview for watch-next-cyf ready!

Name Link
🔨 Latest commit 9f3e408
🔍 Latest deploy log https://app.netlify.com/sites/watch-next-cyf/deploys/6653a7437451dd0008ea1ced
😎 Deploy Preview https://deploy-preview-25--watch-next-cyf.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@zelihapala zelihapala changed the title Add DELETE /api/videos/:id route NW6 | Zeliha Pala | DELETE-videos-endpoint May 16, 2024
Copy link
Collaborator

@Ara225 Ara225 left a comment

Choose a reason for hiding this comment

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

Good work. I have thoughts re improvements, but it seems to work. Do check why the GitHub Actions tests have failed though, always good practice

const videoId = req.params.id;

try {
const checkQuery = await db.query("SELECT * FROM videos WHERE id = $1", [
Copy link
Collaborator

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.

const checkQuery = await db.query("SELECT * FROM videos WHERE id = $1", [
`${videoId}`,
]);
if (checkQuery.rows.length === 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good work 👏

videoId,
]);

return res.status(204).end();
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

server/api.js Outdated
} catch (error) {
res
.status(500)
.json({ message: "Internal server error", error: this.error });
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

@zelihapala zelihapala changed the title NW6 | Zeliha Pala | DELETE-videos-endpoint NW6 | Zeliha Pala | Full-Stack-Project | Week-2 | DELETE-videos-endpoint May 17, 2024
@RbAvci RbAvci merged commit 90cff73 into main May 26, 2024
6 checks passed
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.

3 participants