Skip to content

Commit

Permalink
Fechamento automático do ticket enviado por meio do endpoint api/mess…
Browse files Browse the repository at this point in the history
…ages/send
  • Loading branch information
rtenorioh authored May 19, 2022
1 parent 4f98ba2 commit e330105
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions backend/src/controllers/ApiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import CheckContactNumber from "../services/WbotServices/CheckNumber";
import GetProfilePicUrl from "../services/WbotServices/GetProfilePicUrl";
import SendWhatsAppMedia from "../services/WbotServices/SendWhatsAppMedia";
import SendWhatsAppMessage from "../services/WbotServices/SendWhatsAppMessage";
import UpdateTicketService from "../services/TicketServices/UpdateTicketService";

type WhatsappData = {
whatsappId: number;
Expand Down Expand Up @@ -50,14 +51,14 @@ const createContact = async (

const contact = await CreateOrUpdateContactService(contactData);

let whatsapp:Whatsapp | null;
let whatsapp: Whatsapp | null;

if(whatsappId === undefined) {
if (whatsappId === undefined) {
whatsapp = await GetDefaultWhatsApp();
} else {
whatsapp = await Whatsapp.findByPk(whatsappId);

if(whatsapp === null) {
if (whatsapp === null) {
throw new AppError(`whatsapp #${whatsappId} not found`);
}
}
Expand Down Expand Up @@ -107,5 +108,11 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
await SendWhatsAppMessage({ body, ticket: contactAndTicket, quotedMsg });
}

return res.send();
setTimeout(async () => {
await UpdateTicketService({
ticketId: contactAndTicket.id,
ticketData: { status: "closed" }
});
}, 1000);
return res.send({ error: "SUCCESS" });
};

0 comments on commit e330105

Please sign in to comment.