Skip to content

Commit

Permalink
adding DELETE request
Browse files Browse the repository at this point in the history
  • Loading branch information
aatmanvaidya committed Sep 10, 2023
1 parent 840dfd4 commit f6adfb2
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions browser-extension/api-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ app.post("/slur/create", async (req, res) => {
// PUT request for slur and category
// https://sequelize.org/docs/v6/core-concepts/model-querying-finders/
// https://sequelize.org/docs/v7/querying/update/
app.put("/slur/:slurId", async (req, res) => {
const slurId = req.params.slurId;
app.put("/slur/:id", async (req, res) => {
const slurId = req.params.id;
const { label, labelMeaning, appropriated, appropriationContext, categories } = req.body;

try {
Expand Down Expand Up @@ -318,6 +318,30 @@ app.put("/slur/:slurId", async (req, res) => {
}
});

// DELETE request for slur and category
app.delete("/slur/:id", async (req, res) => {
const slurId = req.params.id;
try {
const slurToDelete = await slur.findByPk(slurId);
if (!slurToDelete) {
res.status(404).send({ error: "Slur not found" });
return;
}

await category.destroy({
where: {
slurId: slurToDelete.id,
},
});
await slurToDelete.destroy();

res.send();
} catch (error) {
console.error(error);
res.status(500).send({ error: "server error" });
}
});


app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
Expand Down

0 comments on commit f6adfb2

Please sign in to comment.