mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 19:59:20 +00:00
change delete ticket route to typescript
This commit is contained in:
@@ -2,6 +2,7 @@ import { Request, Response } from "express";
|
||||
import GetDefaultWhatsapp from "../helpers/GetDefaultWhatsapp";
|
||||
import Ticket from "../models/Ticket";
|
||||
import CreateTicketService from "../services/TicketServices/CreateTicketService";
|
||||
import DeleteTicketService from "../services/TicketServices/DeleteTicketService";
|
||||
import ListTicketsService from "../services/TicketServices/ListTicketsService";
|
||||
import UpdateTicketService from "../services/TicketServices/UpdateTicketService";
|
||||
// const Sequelize = require("sequelize");
|
||||
@@ -118,28 +119,12 @@ export const update = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<Response> => {
|
||||
// const io = getIO();
|
||||
const { ticketId } = req.params;
|
||||
const ticketData: TicketData = req.body;
|
||||
|
||||
const ticket = await UpdateTicketService({ ticketData, ticketId });
|
||||
|
||||
// const ticket = await Ticket.findByPk(ticketId, {
|
||||
// include: [
|
||||
// {
|
||||
// model: Contact,
|
||||
// as: "contact",
|
||||
// attributes: ["name", "number", "profilePicUrl"]
|
||||
// }
|
||||
// ]
|
||||
// });
|
||||
|
||||
// if (!ticket) {
|
||||
// return res.status(404).json({ error: "No ticket found with this ID" });
|
||||
// }
|
||||
|
||||
// await ticket.update(req.body);
|
||||
|
||||
// const io = getIO();
|
||||
// io.to("notification").emit("ticket", {
|
||||
// action: "updateStatus",
|
||||
// ticket: ticket
|
||||
@@ -148,22 +133,19 @@ export const update = async (
|
||||
return res.status(200).json(ticket);
|
||||
};
|
||||
|
||||
// export const remove = (req: Request, res: Response): Promise<Response> => {
|
||||
// const io = getIO();
|
||||
// const { ticketId } = req.params;
|
||||
export const remove = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<Response> => {
|
||||
const { ticketId } = req.params;
|
||||
|
||||
// const ticket = await Ticket.findByPk(ticketId);
|
||||
await DeleteTicketService(ticketId);
|
||||
|
||||
// if (!ticket) {
|
||||
// return res.status(400).json({ error: "No ticket found with this ID" });
|
||||
// }
|
||||
// const io = getIO();
|
||||
// io.to("notification").emit("ticket", {
|
||||
// action: "delete",
|
||||
// ticketId: ticket.id
|
||||
// });
|
||||
|
||||
// await ticket.destroy();
|
||||
|
||||
// io.to("notification").emit("ticket", {
|
||||
// action: "delete",
|
||||
// ticketId: ticket.id
|
||||
// });
|
||||
|
||||
// return res.status(200).json({ message: "ticket deleted" });
|
||||
// };
|
||||
return res.status(200).json({ message: "ticket deleted" });
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Request, Response } from "express";
|
||||
|
||||
import CreateWhatsAppService from "../services/WhatsappService/CreateWhatsAppService";
|
||||
import DeleteWhatsApprService from "../services/WhatsappService/DeleteWhatsApprService";
|
||||
import DeleteWhatsAppService from "../services/WhatsappService/DeleteWhatsAppService";
|
||||
import ListWhatsAppsService from "../services/WhatsappService/ListWhatsAppsService";
|
||||
import FindWhatsAppService from "../services/WhatsappService/FindWhatsAppService";
|
||||
import UpdateWhatsAppService from "../services/WhatsappService/UpdateWhatsAppService";
|
||||
@@ -91,7 +91,7 @@ export const remove = async (
|
||||
// const io = getIO();
|
||||
const { whatsappId } = req.params;
|
||||
|
||||
await DeleteWhatsApprService(whatsappId);
|
||||
await DeleteWhatsAppService(whatsappId);
|
||||
// removeWbot(whatsapp.id);
|
||||
|
||||
// io.emit("whatsapp", {
|
||||
|
||||
@@ -11,6 +11,6 @@ ticketRoutes.post("/tickets", isAuth, TicketController.store);
|
||||
|
||||
ticketRoutes.put("/tickets/:ticketId", isAuth, TicketController.update);
|
||||
|
||||
// ticketRoutes.delete("/tickets/:ticketId", isAuth, TicketController.remove);
|
||||
ticketRoutes.delete("/tickets/:ticketId", isAuth, TicketController.remove);
|
||||
|
||||
export default ticketRoutes;
|
||||
|
||||
16
backend/src/services/TicketServices/DeleteTicketService.ts
Normal file
16
backend/src/services/TicketServices/DeleteTicketService.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import Ticket from "../../models/Ticket";
|
||||
import AppError from "../../errors/AppError";
|
||||
|
||||
const DeleteTicketService = async (id: string): Promise<void> => {
|
||||
const ticket = await Ticket.findOne({
|
||||
where: { id }
|
||||
});
|
||||
|
||||
if (!ticket) {
|
||||
throw new AppError("No ticket found with this ID.", 404);
|
||||
}
|
||||
|
||||
await ticket.destroy();
|
||||
};
|
||||
|
||||
export default DeleteTicketService;
|
||||
@@ -1,4 +1,5 @@
|
||||
import AppError from "../../errors/AppError";
|
||||
import Contact from "../../models/Contact";
|
||||
import Ticket from "../../models/Ticket";
|
||||
|
||||
interface TicketData {
|
||||
@@ -18,7 +19,14 @@ const UpdateTicketService = async ({
|
||||
const { status, userId } = ticketData;
|
||||
|
||||
const ticket = await Ticket.findOne({
|
||||
where: { id: ticketId }
|
||||
where: { id: ticketId },
|
||||
include: [
|
||||
{
|
||||
model: Contact,
|
||||
as: "contact",
|
||||
attributes: ["name", "number", "profilePicUrl"]
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
if (!ticket) {
|
||||
|
||||
Reference in New Issue
Block a user