fix: corrections and improvements to support two goal numbers

Details:
- Made corrections and improvements to the codebase to support handling two goal numbers.
gertec
gustavo-gsp 2024-06-19 07:55:41 -03:00
parent da86bbfa33
commit bf2dc3de03
4 changed files with 28 additions and 22 deletions

1
.gitignore vendored
View File

@ -47,3 +47,4 @@ npm-debug.log*
yarn-debug.log* yarn-debug.log*
yarn-error.log* yarn-error.log*
dump.rdb

View File

@ -96,7 +96,7 @@ export const customization = async (
req: Request, req: Request,
res: Response res: Response
): Promise<Response> => { ): Promise<Response> => {
const { ura } = req.body; const { ura, number } = req.body;
if (!ura) throw new AppError("BAD REQUEST", 400); if (!ura) throw new AppError("BAD REQUEST", 400);
@ -184,14 +184,15 @@ export const customization = async (
} }
} }
await set("ura", ura); await set(`ura_${number}`, ura);
const _ura = await get({ key: "ura", parse: true }); const _ura = await get({ key: `ura_${number}`, parse: true });
console.log("_URA: ", _ura); console.log(`ura_${number}`, _ura);
return res.status(200).json({ new_queues }); return res.status(200).json({ new_queues });
}; };
export const show = async (req: Request, res: Response): Promise<Response> => { export const show = async (req: Request, res: Response): Promise<Response> => {
const { queueId } = req.params; const { queueId } = req.params;

View File

@ -13,17 +13,17 @@ async function controllByNumber() {
let controll: any[] = []; let controll: any[] = [];
for (const ticket of tickets) { for (const ticket of tickets) {
let match = ticket.match(/"whatsappId":(\d+)/); let match = ticket?.match(/"whatsappId":(\d+)/);
let whatsappId = match ? match[1] : null; let whatsappId = match ? match[1] : null;
const whatsapp = await get({ const whatsapp = await get({
key: `whatsapp:${whatsappId}` key: `whatsapp:${whatsappId}`
}); });
match = whatsapp.match(/"number":"(\d+)"/); match = whatsapp?.match(/"number":"(\d+)"/);
let number = match ? match[1] : null; let number = match ? match[1] : null;
match = ticket.match(/"id":(\d+)/); match = ticket?.match(/"id":(\d+)/);
let ticketId = match ? match[1] : null; let ticketId = match ? match[1] : null;
number = JSON.parse(number); number = JSON.parse(number);
@ -42,7 +42,7 @@ async function controllByNumber() {
for (const ticketId of ticketIds) { for (const ticketId of ticketIds) {
const ticket: any = await Ticket.findByPk(ticketId); const ticket: any = await Ticket.findByPk(ticketId);
if(ticket){
const { status } = ticket; const { status } = ticket;
if (status == "pending") { if (status == "pending") {
@ -52,6 +52,7 @@ async function controllByNumber() {
}); });
} }
} }
}
set(`remote:controll`, JSON.stringify(ticketIds)); set(`remote:controll`, JSON.stringify(ticketIds));

View File

@ -1,6 +1,6 @@
import { join } from "path"; import { join } from "path";
import { promisify } from "util"; import { promisify } from "util";
import { writeFile } from "fs"; import { writeFile, promises } from "fs";
import * as Sentry from "@sentry/node"; import * as Sentry from "@sentry/node";
import { copyFolder } from "../../helpers/CopyFolder"; import { copyFolder } from "../../helpers/CopyFolder";
@ -8,6 +8,7 @@ import { removeDir } from "../../helpers/DeleteDirectory";
import path from "path"; import path from "path";
import { cpf, cnpj } from 'cpf-cnpj-validator'; import { cpf, cnpj } from 'cpf-cnpj-validator';
import { import {
isHoliday, isHoliday,
isOutBusinessTime, isOutBusinessTime,
@ -108,7 +109,7 @@ import CreateContactService from "../ContactServices/CreateContactService";
import { number } from "yup"; import { number } from "yup";
import AssociateContatctQueue from "../ContactServices/AssociateContatctQueue"; import AssociateContatctQueue from "../ContactServices/AssociateContatctQueue";
import ContactQueue from "../../models/ContactQueues"; import ContactQueue from "../../models/ContactQueues";
import SendWhatsAppMedia from "./SendWhatsAppMedia";
var lst: any[] = getWhatsappIds(); var lst: any[] = getWhatsappIds();
interface Session extends Client { 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){ if(!LGPDSaves && option.id === '1400' && userTyped.toLowerCase() === 'ok' && contactData){
contactData.isLGPDAccepted = true; 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); 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) { if (contactData && contactData.name != userTyped) {
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, ticket,
`O protocolo desse atendimento é: ${ticket?.id}.` `O protocolo desse atendimento é: ${ticket?.id}.`
); );