fix: resolve issues with WhatsApp creation and editing, message input, and ControlByNumber errors

Details:
- Fixed issue where the 'number' field was not being saved during WhatsApp creation and editing.
- Resolved problem where text in the message input was being cleared upon receiving a new message.
- Addressed errors in ControlByNumber when ticketId was not found.
merge-socket
gustavo-gsp 2024-06-25 10:45:46 -03:00
parent b9f8bfc8d5
commit e30573519d
3 changed files with 24 additions and 19 deletions

View File

@ -377,9 +377,11 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
} else if (!isOfficial) { } else if (!isOfficial) {
phoneNumberId = ""; phoneNumberId = "";
wabaId = ""; wabaId = "";
number = ""; //number = "";
}
if(!number){
number = getNumberFromName(name)
} }
let invalidPhoneName = validatePhoneName(name); let invalidPhoneName = validatePhoneName(name);
if (invalidPhoneName) { if (invalidPhoneName) {
@ -479,9 +481,11 @@ export const update = async (
} else if (!isOfficial) { } else if (!isOfficial) {
whatsappData.phoneNumberId = ""; whatsappData.phoneNumberId = "";
whatsappData.wabaId = ""; whatsappData.wabaId = "";
whatsappData.number = ""; //whatsappData.number = "";
}
if(!whatsappData?.number){
whatsappData.number = getNumberFromName(whatsappData.name)
} }
const { whatsapp, oldDefaultWhatsapp } = await UpdateWhatsAppService({ const { whatsapp, oldDefaultWhatsapp } = await UpdateWhatsAppService({
whatsappData, whatsappData,
whatsappId whatsappId

View File

@ -13,45 +13,46 @@ 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);
ticketId = JSON.parse(ticketId); ticketId = JSON.parse(ticketId);
const index = controll.findIndex((c: any) => c.number == number); const index = controll?.findIndex((c: any) => c.number == number);
if (index == -1) { if (index == -1) {
controll.push({ ticketId, number }); controll?.push({ ticketId, number });
} }
} }
const ticketIds = controll.map((c: any) => c.ticketId); const ticketIds = controll?.map((c: any) => c.ticketId);
console.log("=======> ticketIds: ", ticketIds); //console.log("=======> ticketIds: ", ticketIds);
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 && status == "pending") {
await UpdateTicketService({ await UpdateTicketService({
ticketData: { statusChatEnd: uuidv4() }, ticketData: { statusChatEnd: uuidv4() },
ticketId: ticket.id ticketId: ticket.id
}); });
} }
} }
}
set(`remote:controll`, JSON.stringify(ticketIds)); set(`remote:controll`, JSON.stringify(ticketIds));

View File

@ -247,7 +247,7 @@ const MessageInput = ({ ticketStatus, ticketLastMessage, ticketIsRemote }) => {
setInputMessage(ticketLastMessage) setInputMessage(ticketLastMessage)
} }
else { else {
setInputMessage("") //setInputMessage("")
} }
}, [countTicketMsg, ticketIsRemote, ticketLastMessage]) }, [countTicketMsg, ticketIsRemote, ticketLastMessage])