Skip to content

Commit

Permalink
complete the delete endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
adniyaYousaf committed Apr 30, 2024
1 parent 498a32c commit 12b1638
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ router.get("/videos", async (_, res) => {
result
? res.send(result.rows)
: res
.status(500)
.send({ success: "false", error: "Could not connect to database" });
.status(500)
.send({ success: "false", error: "Could not connect to database" });
});

router.post("/videos", async (req, res) => {
Expand All @@ -22,4 +22,16 @@ router.post("/videos", async (req, res) => {
);
});

router.delete("/videos/:id", async (req, res) => {
const id = req.params.id;

const deletedVideo = await db.query(
`DELETE FROM videos WHERE id='${id}'`
);

deletedVideo
? res.status(200).send({ success: "Deleted the video successfully" })
: res.status(404).send({ error: "Id for the video does not exist" })
})

export default router;

0 comments on commit 12b1638

Please sign in to comment.