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
parent
b9f8bfc8d5
commit
e30573519d
|
@ -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
|
||||||
|
|
|
@ -13,43 +13,44 @@ 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 && status == "pending") {
|
||||||
|
await UpdateTicketService({
|
||||||
if (status == "pending") {
|
ticketData: { statusChatEnd: uuidv4() },
|
||||||
await UpdateTicketService({
|
ticketId: ticket.id
|
||||||
ticketData: { statusChatEnd: uuidv4() },
|
});
|
||||||
ticketId: ticket.id
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -247,7 +247,7 @@ const MessageInput = ({ ticketStatus, ticketLastMessage, ticketIsRemote }) => {
|
||||||
setInputMessage(ticketLastMessage)
|
setInputMessage(ticketLastMessage)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setInputMessage("")
|
//setInputMessage("")
|
||||||
}
|
}
|
||||||
}, [countTicketMsg, ticketIsRemote, ticketLastMessage])
|
}, [countTicketMsg, ticketIsRemote, ticketLastMessage])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue