mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 11:49:19 +00:00
feat: added delete tickets option
This commit is contained in:
@@ -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" });
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user