Inclusao de try catch para rastrear a origem do tcp_wrap.cc erro

pull/21/head
adriano 2023-04-20 15:48:42 -03:00
parent 5ab5d8d9c3
commit 69da69089a
19 changed files with 972 additions and 862 deletions

View File

@ -25,6 +25,8 @@ const CreateContactService = async ({
extraInfo = [] extraInfo = []
}: Request): Promise<Contact> => { }: Request): Promise<Contact> => {
try {
const numberExists = await Contact.findOne({ const numberExists = await Contact.findOne({
where: { number } where: { number }
}); });
@ -54,6 +56,13 @@ const CreateContactService = async ({
return contact; return contact;
} catch (error: any) {
console.error('===> Error on CreateContactService.ts file: \n', error)
throw new AppError(error.message);
}
}; };
export default CreateContactService; export default CreateContactService;

View File

@ -2,6 +2,8 @@ import { getIO } from "../../libs/socket";
import Contact from "../../models/Contact"; import Contact from "../../models/Contact";
import { createOrUpdateContactCache } from '../../helpers/ContactsCache' import { createOrUpdateContactCache } from '../../helpers/ContactsCache'
import { tr } from "date-fns/locale";
import AppError from "../../errors/AppError";
interface ExtraInfo { interface ExtraInfo {
name: string; name: string;
@ -25,6 +27,9 @@ const CreateOrUpdateContactService = async ({
email = "", email = "",
extraInfo = [] extraInfo = []
}: Request): Promise<Contact> => { }: Request): Promise<Contact> => {
try {
const number = isGroup ? rawNumber : rawNumber.replace(/[^0-9]/g, ""); const number = isGroup ? rawNumber : rawNumber.replace(/[^0-9]/g, "");
const io = getIO(); const io = getIO();
@ -55,7 +60,7 @@ const CreateOrUpdateContactService = async ({
}); });
// TEST DEL // TEST DEL
await createOrUpdateContactCache(`contact:${contact.id}`, {id: contact.id, name, number, profilePicUrl, isGroup, extraInfo, email }) await createOrUpdateContactCache(`contact:${contact.id}`, { id: contact.id, name, number, profilePicUrl, isGroup, extraInfo, email })
// //
@ -66,6 +71,12 @@ const CreateOrUpdateContactService = async ({
} }
return contact; return contact;
} catch (error: any) {
console.error('===> Error on CreateOrUpdateContactService.ts file: \n', error)
throw new AppError(error.message);
}
}; };
export default CreateOrUpdateContactService; export default CreateOrUpdateContactService;

View File

@ -4,6 +4,7 @@ import ContactCustomField from "../../models/ContactCustomField";
import { updateTicketsByContactsCache } from '../../helpers/TicketCache' import { updateTicketsByContactsCache } from '../../helpers/TicketCache'
import { updateContactCacheById } from '../../helpers/ContactsCache' import { updateContactCacheById } from '../../helpers/ContactsCache'
import { tr } from "date-fns/locale";
interface ExtraInfo { interface ExtraInfo {
id?: number; id?: number;
@ -27,6 +28,9 @@ const UpdateContactService = async ({
contactData, contactData,
contactId contactId
}: Request): Promise<Contact> => { }: Request): Promise<Contact> => {
try {
const { email, name, number, extraInfo } = contactData; const { email, name, number, extraInfo } = contactData;
// console.log('email, name, number, extraInfo: ', email, name, number, extraInfo) // console.log('email, name, number, extraInfo: ', email, name, number, extraInfo)
@ -63,19 +67,17 @@ const UpdateContactService = async ({
//Solução para o erro tcp_wrap.cc //Solução para o erro tcp_wrap.cc
// console.log('----------> oldNumber: ', oldNumber) console.log('----------> oldNumber: ', oldNumber)
if (number) { if (number) {
const numberExists = await Contact.findOne({ const numberExists = await Contact.findOne({
where: { number } where: { number }
}); });
if (numberExists) { if (numberExists && numberExists.id != +contactId) {
throw new AppError("ERR_DUPLICATED_CONTACT"); throw new AppError("ERR_DUPLICATED_CONTACT");
} }
} }
//
await contact.update({ await contact.update({
name, name,
@ -83,6 +85,8 @@ const UpdateContactService = async ({
email email
}); });
//TEST DEL //TEST DEL
await updateTicketsByContactsCache(oldNumber, contact.name, contact.number) await updateTicketsByContactsCache(oldNumber, contact.name, contact.number)
// //
@ -99,6 +103,12 @@ const UpdateContactService = async ({
await updateContactCacheById(contact.id, JSON.parse(JSON.stringify(contact))) await updateContactCacheById(contact.id, JSON.parse(JSON.stringify(contact)))
return contact; return contact;
} catch (error: any) {
console.error('===> Error on UpdateContactService.ts file: \n', error)
throw new AppError(error.message);
}
}; };
export default UpdateContactService; export default UpdateContactService;

View File

@ -1,3 +1,4 @@
import AppError from "../../errors/AppError";
import { updateTicketCacheByTicketId } from "../../helpers/TicketCache"; import { updateTicketCacheByTicketId } from "../../helpers/TicketCache";
import { getIO } from "../../libs/socket"; import { getIO } from "../../libs/socket";
import Message from "../../models/Message"; import Message from "../../models/Message";
@ -21,6 +22,8 @@ const CreateMessageService = async ({ messageData }: Request): Promise<Message>
// console.log('UPSERT MESSAGE messageData: ', messageData) // console.log('UPSERT MESSAGE messageData: ', messageData)
try {
await Message.upsert(messageData); await Message.upsert(messageData);
const message = await Message.findByPk(messageData.id, { const message = await Message.findByPk(messageData.id, {
@ -75,6 +78,13 @@ const CreateMessageService = async ({ messageData }: Request): Promise<Message>
return message; return message;
} catch (error: any) {
console.error('===> Error on CreateMessageService.ts file: \n', error)
throw new AppError(error.message);
}
}; };
export default CreateMessageService; export default CreateMessageService;

View File

@ -9,6 +9,9 @@ interface QueueData {
} }
const CreateQueueService = async (queueData: QueueData): Promise<Queue> => { const CreateQueueService = async (queueData: QueueData): Promise<Queue> => {
try {
const { color, name } = queueData; const { color, name } = queueData;
const queueSchema = Yup.object().shape({ const queueSchema = Yup.object().shape({
@ -55,13 +58,19 @@ const CreateQueueService = async (queueData: QueueData): Promise<Queue> => {
try { try {
await queueSchema.validate({ color, name }); await queueSchema.validate({ color, name });
} catch (err) { } catch (err: any) {
throw new AppError(err.message); throw new AppError(err.message);
} }
const queue = await Queue.create(queueData); const queue = await Queue.create(queueData);
return queue; return queue;
} catch (error: any) {
console.error('===> Error on CreateQueueService.ts file: \n', error)
throw new AppError(error.message);
}
}; };
export default CreateQueueService; export default CreateQueueService;

View File

@ -14,6 +14,9 @@ const UpdateQueueService = async (
queueId: number | string, queueId: number | string,
queueData: QueueData queueData: QueueData
): Promise<Queue> => { ): Promise<Queue> => {
try {
const { color, name } = queueData; const { color, name } = queueData;
const queueSchema = Yup.object().shape({ const queueSchema = Yup.object().shape({
@ -59,7 +62,7 @@ const UpdateQueueService = async (
try { try {
await queueSchema.validate({ color, name }); await queueSchema.validate({ color, name });
} catch (err) { } catch (err: any) {
throw new AppError(err.message); throw new AppError(err.message);
} }
@ -68,6 +71,12 @@ const UpdateQueueService = async (
await queue.update(queueData); await queue.update(queueData);
return queue; return queue;
} catch (error: any) {
console.error('===> Error on UpdateQueueService.ts file: \n', error)
throw new AppError(error.message);
}
}; };
export default UpdateQueueService; export default UpdateQueueService;

View File

@ -22,19 +22,21 @@ const CreateSchedulingNotifyService = async ({
message message
}: Request): Promise<SchedulingNotify> => { }: Request): Promise<SchedulingNotify> => {
try {
let schedulingNotify = null; let schedulingNotify = null;
if(schedulingNotifyId){ if (schedulingNotifyId) {
schedulingNotify = await SchedulingNotify.findOne({ where: { id: schedulingNotifyId } }); schedulingNotify = await SchedulingNotify.findOne({ where: { id: schedulingNotifyId } });
if(schedulingNotify){ if (schedulingNotify) {
try{ try {
await schedulingNotify.update({ statusChatEndId, schedulingDate, schedulingTime, message}); await schedulingNotify.update({ statusChatEndId, schedulingDate, schedulingTime, message });
}catch(err){ } catch (err) {
throw new AppError("ERR_NO_SCHEDULING_NOTIFY_FOUND", 404); throw new AppError("ERR_NO_SCHEDULING_NOTIFY_FOUND", 404);
@ -46,7 +48,7 @@ const CreateSchedulingNotifyService = async ({
} }
if(!schedulingNotify){ if (!schedulingNotify) {
schedulingNotify = await SchedulingNotify.create( schedulingNotify = await SchedulingNotify.create(
{ {
@ -63,8 +65,14 @@ const CreateSchedulingNotifyService = async ({
return schedulingNotify return schedulingNotify
} catch (error: any) {
console.error('===> Error on CreateSchedulingNotifyService.ts file: \n', error)
throw new AppError(error.message);
} }
}
@ -85,4 +93,4 @@ const CreateSchedulingNotifyService = async ({
// return schedulingNotify // return schedulingNotify
// } // }
export default CreateSchedulingNotifyService export default CreateSchedulingNotifyService

View File

@ -4,7 +4,7 @@ import SchedulingNotify from "../../models/SchedulingNotify";
interface SchedulingData { interface SchedulingData {
name?: string name?: string
} }
interface Request { interface Request {
schedulingData: SchedulingData schedulingData: SchedulingData
@ -16,6 +16,9 @@ const UpdateSchedulingNotify = async ({
schedulingDataId schedulingDataId
}: Request): Promise<SchedulingNotify> => { }: Request): Promise<SchedulingNotify> => {
try {
const { name } = schedulingData; const { name } = schedulingData;
const updateScheduling = await SchedulingNotify.findOne({ const updateScheduling = await SchedulingNotify.findOne({
@ -34,6 +37,12 @@ const UpdateSchedulingNotify = async ({
}); });
return updateScheduling; return updateScheduling;
} catch (error: any) {
console.error('===> Error on CreateSchedulingNotifyService.ts file: \n', error)
throw new AppError(error.message);
}
}; };
export default UpdateSchedulingNotify; export default UpdateSchedulingNotify;

View File

@ -10,6 +10,8 @@ const UpdateSettingService = async ({
key, key,
value value
}: Request): Promise<Setting | undefined> => { }: Request): Promise<Setting | undefined> => {
try {
const setting = await Setting.findOne({ const setting = await Setting.findOne({
where: { key } where: { key }
}); });
@ -21,6 +23,11 @@ const UpdateSettingService = async ({
await setting.update({ value }); await setting.update({ value });
return setting; return setting;
} catch (error: any) {
console.error('===> Error on UpdateSettingService.ts file: \n', error)
throw new AppError(error.message);
}
}; };
export default UpdateSettingService; export default UpdateSettingService;

View File

@ -29,6 +29,9 @@ const CreateTicketService = async ({
status, status,
userId userId
}: Request): Promise<Ticket> => { }: Request): Promise<Ticket> => {
try {
const defaultWhatsapp = await GetDefaultWhatsApp(userId); const defaultWhatsapp = await GetDefaultWhatsApp(userId);
await CheckContactOpenTickets(contactId); await CheckContactOpenTickets(contactId);
@ -75,11 +78,17 @@ const CreateTicketService = async ({
const io = getIO(); const io = getIO();
io.emit("ticketStatus", { io.emit("ticketStatus", {
action: "update", action: "update",
ticketStatus: {ticketId: ticket.id, status: ticket.status} ticketStatus: { ticketId: ticket.id, status: ticket.status }
}); });
return ticket; return ticket;
} catch (error: any) {
console.error('===> Error on CreateTicketService.ts file: \n', error)
throw new AppError(error.message);
}
}; };
export default CreateTicketService; export default CreateTicketService;

View File

@ -5,6 +5,7 @@ import Contact from "../../models/Contact";
import Ticket from "../../models/Ticket"; import Ticket from "../../models/Ticket";
import ShowWhatsAppService from "../WhatsappService/ShowWhatsAppService"; import ShowWhatsAppService from "../WhatsappService/ShowWhatsAppService";
import ShowTicketService from "./ShowTicketService"; import ShowTicketService from "./ShowTicketService";
import AppError from "../../errors/AppError";
const FindOrCreateTicketService = async ( const FindOrCreateTicketService = async (
@ -13,6 +14,9 @@ const FindOrCreateTicketService = async (
unreadMessages: number, unreadMessages: number,
groupContact?: Contact groupContact?: Contact
): Promise<Ticket> => { ): Promise<Ticket> => {
try {
let ticket = await Ticket.findOne({ let ticket = await Ticket.findOne({
where: { where: {
status: { status: {
@ -109,8 +113,12 @@ const FindOrCreateTicketService = async (
ticket = await ShowTicketService(ticket.id); ticket = await ShowTicketService(ticket.id);
return ticket; return ticket;
} catch (error: any) {
console.error('===> Error on FindOrCreateTicketService.ts file: \n', error)
throw new AppError(error.message);
}
}; };
export default FindOrCreateTicketService; export default FindOrCreateTicketService;

View File

@ -7,6 +7,7 @@ import ShowWhatsAppService from "../WhatsappService/ShowWhatsAppService";
import ShowTicketService from "./ShowTicketService"; import ShowTicketService from "./ShowTicketService";
import { createOrUpdateTicketCache } from '../../helpers/TicketCache' import { createOrUpdateTicketCache } from '../../helpers/TicketCache'
import AppError from "../../errors/AppError";
var flatten = require('flat') var flatten = require('flat')
@ -33,6 +34,9 @@ const UpdateTicketService = async ({
ticketData, ticketData,
ticketId ticketId
}: Request): Promise<Response> => { }: Request): Promise<Response> => {
try {
const { status, userId, queueId, statusChatEnd } = ticketData; const { status, userId, queueId, statusChatEnd } = ticketData;
const ticket = await ShowTicketService(ticketId); const ticket = await ShowTicketService(ticketId);
@ -99,6 +103,12 @@ const UpdateTicketService = async ({
return { ticket, oldStatus, oldUserId }; return { ticket, oldStatus, oldUserId };
} catch (error: any) {
console.error('===> Error on UpdateTicketService.ts file: \n', error)
throw new AppError(error.message);
}
}; };
export default UpdateTicketService; export default UpdateTicketService;

View File

@ -34,7 +34,7 @@ const CreateOrUpdateUserOnlineTime = async ({
status, status,
}: Request): Promise<UserOnlineTime> => { }: Request): Promise<UserOnlineTime> => {
try {
const io = getIO(); const io = getIO();
let userOnlineTime: any = null; let userOnlineTime: any = null;
@ -174,6 +174,12 @@ const CreateOrUpdateUserOnlineTime = async ({
return userOnlineTime return userOnlineTime
} catch (error: any) {
console.error('===> Error on CreateOrUpdateUserOnlineTime.ts file: \n', error)
throw new AppError(error.message);
}
} }

View File

@ -26,6 +26,9 @@ const CreateUserService = async ({
queueIds = [], queueIds = [],
profile = "master" profile = "master"
}: Request): Promise<Response> => { }: Request): Promise<Response> => {
try {
const schema = Yup.object().shape({ const schema = Yup.object().shape({
name: Yup.string().required().min(2), name: Yup.string().required().min(2),
@ -58,7 +61,7 @@ const CreateUserService = async ({
try { try {
await schema.validate({ email, password, name }); await schema.validate({ email, password, name });
} catch (err:any) { } catch (err: any) {
throw new AppError(err.message); throw new AppError(err.message);
} }
@ -79,6 +82,12 @@ const CreateUserService = async ({
const serializedUser = SerializeUser(user); const serializedUser = SerializeUser(user);
return serializedUser; return serializedUser;
} catch (error: any) {
console.error('===> Error on CreateUserService.ts file: \n', error)
throw new AppError(error.message);
}
}; };
export default CreateUserService; export default CreateUserService;

View File

@ -28,6 +28,9 @@ const UpdateUserService = async ({
userData, userData,
userId userId
}: Request): Promise<Response | undefined> => { }: Request): Promise<Response | undefined> => {
try {
const user = await ShowUserService(userId); const user = await ShowUserService(userId);
const schema = Yup.object().shape({ const schema = Yup.object().shape({
@ -86,6 +89,13 @@ const UpdateUserService = async ({
}; };
return serializedUser; return serializedUser;
} catch (error: any) {
console.error('===> Error on UpdateUserService.ts file: \n', error)
throw new AppError(error.message);
}
}; };
export default UpdateUserService; export default UpdateUserService;

View File

@ -41,6 +41,8 @@ const SendWhatsAppMessage = async ({
quotedMsg quotedMsg
}: Request): Promise<WbotMessage | any> => { }: Request): Promise<WbotMessage | any> => {
try {
let timestamp = Math.floor(Date.now() / 1000) let timestamp = Math.floor(Date.now() / 1000)
var timetaken = `########################################${timestamp}| TicketId: ${ticket.id} => Time taken to send the message`; var timetaken = `########################################${timestamp}| TicketId: ${ticket.id} => Time taken to send the message`;
@ -72,7 +74,7 @@ const SendWhatsAppMessage = async ({
if (listWhatsapp.whatsapp && listWhatsapp.whatsapp.status != 'CONNECTED' && listWhatsapp.whatsapps.length > 0) { if (listWhatsapp.whatsapp && listWhatsapp.whatsapp.status != 'CONNECTED' && listWhatsapp.whatsapps.length > 0) {
console.log('kkkkkkkkkkkkkkkkkkkkkkkkkkkk: ', listWhatsapp.whatsapps[0].id) // console.log('kkkkkkkkkkkkkkkkkkkkkkkkkkkk: ', listWhatsapp.whatsapps[0].id)
await ticket.update({ whatsappId: + listWhatsapp.whatsapps[0].id }); await ticket.update({ whatsappId: + listWhatsapp.whatsapps[0].id });
@ -81,22 +83,14 @@ const SendWhatsAppMessage = async ({
} }
if (listWhatsapp.whatsapps.length > 1) { if (listWhatsapp.whatsapps.length > 1) {
const _whatsapp = listWhatsapp.whatsapps[Math.floor(Math.random() * listWhatsapp.whatsapps.length)]; const _whatsapp = listWhatsapp.whatsapps[Math.floor(Math.random() * listWhatsapp.whatsapps.length)];
await ticket.update({ whatsappId: +_whatsapp.id }); await ticket.update({ whatsappId: +_whatsapp.id });
// await ticket.reload();
} }
// console.log('listWhatsapp.whatsapps.length: ', listWhatsapp.whatsapps.length)
// console.log('listWhatsapp.whatsapp.status: ', listWhatsapp.whatsapp.status)
if (listWhatsapp.whatsapps.length == 0 && listWhatsapp.whatsapp.status != 'CONNECTED') { if (listWhatsapp.whatsapps.length == 0 && listWhatsapp.whatsapp.status != 'CONNECTED') {
console.log('listWhatsapp.whatsapps == 0') console.log('listWhatsapp.whatsapps == 0')
@ -122,43 +116,7 @@ const SendWhatsAppMessage = async ({
} }
console.log('1 --------> ticket.whatsappId: ', ticket.whatsappId) console.log('1 --------> send from whatsapp ticket.whatsappId: ', ticket.whatsappId)
// const wbot = await GetTicketWbot(ticket);
/*const whatsapp = await Whatsapp.findByPk(ticket.whatsappId);
if (whatsapp && whatsapp.status != 'CONNECTED') {
let whatsapps = await wbotByUserQueue(ticket.userId)
if (whatsapps.length > 0) {
if (whatsapps.length > 1) {
await ticket.update({ whatsappId: whatsapps[+WhatsIndex(whatsapps)].id });
}
else {
await ticket.update({ whatsappId: whatsapps[0].id });
}
}
}
const wbot = await GetTicketWbot(ticket);
*/
console.log('2 --------> send from whatsapp ticket.whatsappId: ', ticket.whatsappId)
try { try {
@ -168,24 +126,20 @@ const SendWhatsAppMessage = async ({
await updateTicketCacheByTicketId(ticket.id, { lastMessage: body, updatedAt: new Date(ticket.updatedAt).toISOString() }) await updateTicketCacheByTicketId(ticket.id, { lastMessage: body, updatedAt: new Date(ticket.updatedAt).toISOString() })
// const sentMessage = await wbot.sendMessage(`${ticket.contact.number}@${ticket.isGroup ? "g" : "c"}.us`, body, { quotedMessageId: quotedMsgSerializedId, linkPreview: false });
// await ticket.update({ lastMessage: body });
// await updateTicketCacheByTicketId(ticket.id, { lastMessage: body, updatedAt: new Date(ticket.updatedAt).toISOString() })
// return sentMessage;
console.timeEnd(timetaken) console.timeEnd(timetaken)
} catch (err) { } catch (err: any) {
// const whatsapp = await ShowWhatsAppService(ticket.whatsappId);
console.error('0 ===> Error on SendWhatsAppMessage.ts file: \n', err)
throw new AppError("ERR_SENDING_WAPP_MSG"); throw new AppError("ERR_SENDING_WAPP_MSG");
} }
} catch (error: any) {
console.error('===> Error on SendWhatsAppMessage.ts file: \n', error)
throw new AppError(error.message);
}
}; };
export default SendWhatsAppMessage; export default SendWhatsAppMessage;

View File

@ -59,6 +59,7 @@ import autoRestore from "../../helpers/AutoRestore";
import { _restore } from "../../helpers/RestoreControll"; import { _restore } from "../../helpers/RestoreControll";
import sendWhatsAppMessageSocket from "../../helpers/SendWhatsappMessageSocket"; import sendWhatsAppMessageSocket from "../../helpers/SendWhatsappMessageSocket";
import { getWhatsappIds, setWhatsappId } from "../../helpers/WhatsappIdMultiSessionControl"; import { getWhatsappIds, setWhatsappId } from "../../helpers/WhatsappIdMultiSessionControl";
import AppError from "../../errors/AppError";
@ -408,7 +409,7 @@ const _clear_lst = () => {
lst = lst.slice(chunk, chunk + lst.length); lst = lst.slice(chunk, chunk + lst.length);
let whatsappIdsSplited = lst.map((e)=>`${e.id}`).toString() let whatsappIdsSplited = lst.map((e) => `${e.id}`).toString()
setWhatsappId(whatsappIdsSplited, true) setWhatsappId(whatsappIdsSplited, true)
@ -448,11 +449,6 @@ const handleMessage = async (
} }
if (!isValidMsg(msg)) { if (!isValidMsg(msg)) {
return; return;
} }
@ -553,7 +549,14 @@ const handleMessage = async (
// console.log('PARA RESPONDER PELO MEMOS WHATSAPP wbot.id: ', wbot.id, ' | wbot.status: ', wbot.status) // console.log('PARA RESPONDER PELO MEMOS WHATSAPP wbot.id: ', wbot.id, ' | wbot.status: ', wbot.status)
// console.log('WHATSAPP STATUS ticket.whatsappId: ', ticket.whatsappId) // console.log('WHATSAPP STATUS ticket.whatsappId: ', ticket.whatsappId)
try {
await ticket.update({ whatsappId: wbot.id }); await ticket.update({ whatsappId: wbot.id });
} catch (error: any) {
console.error('===> Error on wbotMessageListener.ts into handleMessage fuction file: \n', error)
throw new AppError(error.message);
}
} }
// //

View File

@ -30,6 +30,9 @@ const CreateWhatsAppService = async ({
farewellMessage, farewellMessage,
isDefault = false, isDefault = false,
}: Request): Promise<Response> => { }: Request): Promise<Response> => {
try {
const schema = Yup.object().shape({ const schema = Yup.object().shape({
name: Yup.string() name: Yup.string()
.required() .required()
@ -91,6 +94,13 @@ const CreateWhatsAppService = async ({
await AssociateWhatsappQueue(whatsapp, queueIds); await AssociateWhatsappQueue(whatsapp, queueIds);
return { whatsapp, oldDefaultWhatsapp }; return { whatsapp, oldDefaultWhatsapp };
} catch (error: any) {
console.error('===> Error on CreateWhatsAppService.ts file: \n', error)
throw new AppError(error.message);
}
}; };
export default CreateWhatsAppService; export default CreateWhatsAppService;

View File

@ -37,6 +37,9 @@ const UpdateWhatsAppService = async ({
whatsappData, whatsappData,
whatsappId whatsappId
}: Request): Promise<Response> => { }: Request): Promise<Response> => {
try {
const schema = Yup.object().shape({ const schema = Yup.object().shape({
name: Yup.string().min(2), name: Yup.string().min(2),
status: Yup.string(), status: Yup.string(),
@ -82,7 +85,7 @@ const UpdateWhatsAppService = async ({
// console.log('############## whatsapp: ', JSON.parse(JSON.stringify(whatsapp))) // console.log('############## whatsapp: ', JSON.parse(JSON.stringify(whatsapp)))
if(name && !name.includes(whatsapp.number) && whatsapp.status === 'CONNECTED'){ if (name && !name.includes(whatsapp.number) && whatsapp.status === 'CONNECTED') {
throw new AppError("ERR_WAPP_WRONG_SESSION_NAME"); throw new AppError("ERR_WAPP_WRONG_SESSION_NAME");
@ -111,6 +114,12 @@ const UpdateWhatsAppService = async ({
await AssociateWhatsappQueue(whatsapp, queueIds); await AssociateWhatsappQueue(whatsapp, queueIds);
return { whatsapp, oldDefaultWhatsapp }; return { whatsapp, oldDefaultWhatsapp };
} catch (error: any) {
console.error('===> Error on UpdateWhatsAppService.ts file: \n', error)
throw new AppError(error.message);
}
}; };
export default UpdateWhatsAppService; export default UpdateWhatsAppService;