mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 19:59:20 +00:00
improvement: remove tickets logic from useTickets to improve notifications
This commit is contained in:
@@ -4,12 +4,14 @@ import Ticket from "../../models/Ticket";
|
||||
|
||||
interface Request {
|
||||
contactId: number;
|
||||
status?: string;
|
||||
status: string;
|
||||
userId: number;
|
||||
}
|
||||
|
||||
const CreateTicketService = async ({
|
||||
contactId,
|
||||
status
|
||||
status,
|
||||
userId
|
||||
}: Request): Promise<Ticket> => {
|
||||
const defaultWhatsapp = await GetDefaultWhatsApp();
|
||||
|
||||
@@ -19,7 +21,8 @@ const CreateTicketService = async ({
|
||||
|
||||
const { id }: Ticket = await defaultWhatsapp.$create("ticket", {
|
||||
contactId,
|
||||
status
|
||||
status,
|
||||
userId
|
||||
});
|
||||
|
||||
const ticket = await Ticket.findByPk(id, { include: ["contact"] });
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Ticket from "../../models/Ticket";
|
||||
import AppError from "../../errors/AppError";
|
||||
|
||||
const DeleteTicketService = async (id: string): Promise<void> => {
|
||||
const DeleteTicketService = async (id: string): Promise<Ticket> => {
|
||||
const ticket = await Ticket.findOne({
|
||||
where: { id }
|
||||
});
|
||||
@@ -11,6 +11,8 @@ const DeleteTicketService = async (id: string): Promise<void> => {
|
||||
}
|
||||
|
||||
await ticket.destroy();
|
||||
|
||||
return ticket;
|
||||
};
|
||||
|
||||
export default DeleteTicketService;
|
||||
|
||||
@@ -12,10 +12,15 @@ interface Request {
|
||||
ticketId: string;
|
||||
}
|
||||
|
||||
interface Response {
|
||||
ticket: Ticket;
|
||||
oldStatus: string;
|
||||
}
|
||||
|
||||
const UpdateTicketService = async ({
|
||||
ticketData,
|
||||
ticketId
|
||||
}: Request): Promise<Ticket> => {
|
||||
}: Request): Promise<Response> => {
|
||||
const { status, userId } = ticketData;
|
||||
|
||||
const ticket = await Ticket.findOne({
|
||||
@@ -33,12 +38,14 @@ const UpdateTicketService = async ({
|
||||
throw new AppError("No ticket found with this ID.", 404);
|
||||
}
|
||||
|
||||
const oldStatus = ticket.status;
|
||||
|
||||
await ticket.update({
|
||||
status,
|
||||
userId
|
||||
});
|
||||
|
||||
return ticket;
|
||||
return { ticket, oldStatus };
|
||||
};
|
||||
|
||||
export default UpdateTicketService;
|
||||
|
||||
@@ -138,12 +138,15 @@ const handleMessage = async (
|
||||
}
|
||||
|
||||
const io = getIO();
|
||||
io.to(ticket.id.toString()).to("notification").emit("appMessage", {
|
||||
action: "create",
|
||||
message: newMessage,
|
||||
ticket,
|
||||
contact
|
||||
});
|
||||
io.to(ticket.id.toString())
|
||||
.to(ticket.status)
|
||||
.to("notification")
|
||||
.emit("appMessage", {
|
||||
action: "create",
|
||||
message: newMessage,
|
||||
ticket,
|
||||
contact
|
||||
});
|
||||
};
|
||||
|
||||
const isValidMsg = (msg: WbotMessage): boolean => {
|
||||
|
||||
Reference in New Issue
Block a user