From bf2dc3de03526dee5a96f200bc4ab67619d7ab6a Mon Sep 17 00:00:00 2001 From: gustavo-gsp Date: Wed, 19 Jun 2024 07:55:41 -0300 Subject: [PATCH] fix: corrections and improvements to support two goal numbers Details: - Made corrections and improvements to the codebase to support handling two goal numbers. --- .gitignore | 1 + backend/src/controllers/QueueController.ts | 11 ++++---- backend/src/helpers/controllByNumber.ts | 25 ++++++++++--------- .../WbotServices/wbotMessageListener.ts | 13 ++++++---- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 19b5ead..889de44 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,4 @@ npm-debug.log* yarn-debug.log* yarn-error.log* +dump.rdb diff --git a/backend/src/controllers/QueueController.ts b/backend/src/controllers/QueueController.ts index 9ee3eaa..b939cd0 100644 --- a/backend/src/controllers/QueueController.ts +++ b/backend/src/controllers/QueueController.ts @@ -96,7 +96,7 @@ export const customization = async ( req: Request, res: Response ): Promise => { - const { ura } = req.body; + const { ura, number } = req.body; if (!ura) throw new AppError("BAD REQUEST", 400); @@ -183,15 +183,16 @@ export const customization = async ( // await set("ura", ura); } } + + await set(`ura_${number}`, ura); - await set("ura", ura); - - const _ura = await get({ key: "ura", parse: true }); - console.log("_URA: ", _ura); + const _ura = await get({ key: `ura_${number}`, parse: true }); + console.log(`ura_${number}`, _ura); return res.status(200).json({ new_queues }); }; + export const show = async (req: Request, res: Response): Promise => { const { queueId } = req.params; diff --git a/backend/src/helpers/controllByNumber.ts b/backend/src/helpers/controllByNumber.ts index e202f6f..0f48e2b 100644 --- a/backend/src/helpers/controllByNumber.ts +++ b/backend/src/helpers/controllByNumber.ts @@ -13,17 +13,17 @@ async function controllByNumber() { let controll: any[] = []; for (const ticket of tickets) { - let match = ticket.match(/"whatsappId":(\d+)/); + let match = ticket?.match(/"whatsappId":(\d+)/); let whatsappId = match ? match[1] : null; const whatsapp = await get({ key: `whatsapp:${whatsappId}` }); - match = whatsapp.match(/"number":"(\d+)"/); + match = whatsapp?.match(/"number":"(\d+)"/); let number = match ? match[1] : null; - match = ticket.match(/"id":(\d+)/); + match = ticket?.match(/"id":(\d+)/); let ticketId = match ? match[1] : null; number = JSON.parse(number); @@ -42,17 +42,18 @@ async function controllByNumber() { for (const ticketId of ticketIds) { const ticket: any = await Ticket.findByPk(ticketId); - - const { status } = ticket; - - if (status == "pending") { - await UpdateTicketService({ - ticketData: { statusChatEnd: uuidv4() }, - ticketId: ticket.id - }); + if(ticket){ + const { status } = ticket; + + if (status == "pending") { + await UpdateTicketService({ + ticketData: { statusChatEnd: uuidv4() }, + ticketId: ticket.id + }); + } } } - + set(`remote:controll`, JSON.stringify(ticketIds)); return { ticketIds, tickets }; diff --git a/backend/src/services/WbotServices/wbotMessageListener.ts b/backend/src/services/WbotServices/wbotMessageListener.ts index c4d723b..272e673 100644 --- a/backend/src/services/WbotServices/wbotMessageListener.ts +++ b/backend/src/services/WbotServices/wbotMessageListener.ts @@ -1,6 +1,6 @@ import { join } from "path"; import { promisify } from "util"; -import { writeFile } from "fs"; +import { writeFile, promises } from "fs"; import * as Sentry from "@sentry/node"; import { copyFolder } from "../../helpers/CopyFolder"; @@ -8,6 +8,7 @@ import { removeDir } from "../../helpers/DeleteDirectory"; import path from "path"; import { cpf, cnpj } from 'cpf-cnpj-validator'; + import { isHoliday, isOutBusinessTime, @@ -108,7 +109,7 @@ import CreateContactService from "../ContactServices/CreateContactService"; import { number } from "yup"; import AssociateContatctQueue from "../ContactServices/AssociateContatctQueue"; import ContactQueue from "../../models/ContactQueues"; - +import SendWhatsAppMedia from "./SendWhatsAppMedia"; var lst: any[] = getWhatsappIds(); interface Session extends Client { @@ -1167,7 +1168,8 @@ const menu = async (userTyped: string, whatsappId: any, contactId: any, ticket: if(!LGPDSaves && option.id === '1400' && userTyped.toLowerCase() === 'ok' && contactData){ contactData.isLGPDAccepted = true; - await updateContactService({contactData, contactId}); + const plainContactData = contactData.get({ plain: true }); + await updateContactService({contactData: plainContactData, contactId}); } let history: any = await historyUra(whatsappId, contactId, response.id); @@ -1268,9 +1270,10 @@ const menu = async (userTyped: string, whatsappId: any, contactId: any, ticket: if (contactData && contactData.name != userTyped) { contactData.name = userTyped; - await updateContactService({contactData, contactId}); + const plainContactData = contactData.get({ plain: true }); + await updateContactService({contactData: plainContactData, contactId}); } - botSendMessage( + await botSendMessage( ticket, `O protocolo desse atendimento é: ${ticket?.id}.` );