fix: resolve issue of creating multiple contacts for the same WhatsApp number of a client
Details: - Fixed the bug that allowed the creation of more than one contact for the same WhatsApp number of a client.feat-resolve-contact-duplicate
parent
05c9f3af6d
commit
f4f5dad8d2
|
@ -1,5 +1,6 @@
|
|||
import { getIO } from "../../libs/socket";
|
||||
import Contact from "../../models/Contact";
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
import { createOrUpdateContactCache } from '../../helpers/ContactsCache'
|
||||
import { tr } from "date-fns/locale";
|
||||
|
@ -35,15 +36,37 @@ const CreateOrUpdateContactService = async ({
|
|||
const io = getIO();
|
||||
let contact: Contact | null;
|
||||
|
||||
|
||||
contact = await Contact.findOne({ where: { number } });
|
||||
const firstFourDigits = number.slice(0, 4);
|
||||
const lastEightDigits = number.slice(-8);
|
||||
|
||||
//const numberFormat = number?.length === 13 && number[4] == '9' ? number.slice(0, 4) + number.slice(0, 4) : number;
|
||||
//contact = await Contact.findOne({ where: { number } });
|
||||
contact = await Contact.findOne({
|
||||
where: {
|
||||
[Op.and]: [
|
||||
{
|
||||
number: {
|
||||
[Op.like]: `%${firstFourDigits}%`
|
||||
}
|
||||
},
|
||||
{
|
||||
number: {
|
||||
[Op.like]: `%${lastEightDigits}%`
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
if (contact) {
|
||||
contact.update({ profilePicUrl });
|
||||
|
||||
// TEST DEL
|
||||
await createOrUpdateContactCache(`contact:${contact.id}`, { profilePicUrl })
|
||||
//
|
||||
if(contact.number == number){
|
||||
contact.update({ profilePicUrl });
|
||||
await createOrUpdateContactCache(`contact:${contact.id}`, { profilePicUrl })
|
||||
} else{
|
||||
contact.update({ profilePicUrl, number });
|
||||
await createOrUpdateContactCache(`contact:${contact.id}`, { profilePicUrl, number })
|
||||
}
|
||||
|
||||
io.emit("contact", {
|
||||
action: "update",
|
||||
|
|
|
@ -101,8 +101,6 @@ const FindOrCreateTicketServiceBot = async (
|
|||
unreadMessages
|
||||
});
|
||||
|
||||
console.log("lxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
|
||||
|
||||
await dialogFlowStartContext(contact, ticket, botInfo);
|
||||
}
|
||||
}
|
||||
|
@ -128,8 +126,6 @@ const FindOrCreateTicketServiceBot = async (
|
|||
phoneNumberId
|
||||
});
|
||||
|
||||
console.log("yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy");
|
||||
|
||||
await dialogFlowStartContext(contact, ticket, botInfo);
|
||||
}
|
||||
|
||||
|
|
|
@ -748,8 +748,6 @@ const handleMessage = async (
|
|||
// console.log('----------> chat: ', JSON.parse(JSON.stringify(chat)))
|
||||
|
||||
|
||||
console
|
||||
|
||||
if (chat.isGroup) {
|
||||
// let msgGroupContact;
|
||||
|
||||
|
|
Loading…
Reference in New Issue