feat: added delete tickets option

This commit is contained in:
canove
2020-07-30 19:48:45 -03:00
parent 14fed6c4a0
commit 362c4c183c
5 changed files with 165 additions and 40 deletions

View File

@@ -120,3 +120,23 @@ exports.update = async (req, res) => {
res.status(200).json(ticket);
};
exports.delete = async (req, res) => {
const io = getIO();
const { ticketId } = req.params;
const ticket = await Ticket.findByPk(ticketId);
if (!ticket) {
return res.status(400).json({ error: "No ticket found with this ID" });
}
await ticket.destroy();
io.to("notification").emit("ticket", {
action: "delete",
ticketId: ticket.id,
});
res.status(200).json({ message: "ticket deleted" });
};

View File

@@ -11,4 +11,6 @@ routes.post("/tickets", isAuth, TicketController.store);
routes.put("/tickets/:ticketId", isAuth, TicketController.update);
routes.delete("/tickets/:ticketId", isAuth, TicketController.delete);
module.exports = routes;