diff --git a/backend/src/services/ContactServices/CreateOrUpdateContactService.ts b/backend/src/services/ContactServices/CreateOrUpdateContactService.ts index 50d5d5f..e63085d 100644 --- a/backend/src/services/ContactServices/CreateOrUpdateContactService.ts +++ b/backend/src/services/ContactServices/CreateOrUpdateContactService.ts @@ -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", diff --git a/backend/src/services/TicketServices/FindOrCreateTicketServiceBot.ts b/backend/src/services/TicketServices/FindOrCreateTicketServiceBot.ts index 42d7d53..8599030 100644 --- a/backend/src/services/TicketServices/FindOrCreateTicketServiceBot.ts +++ b/backend/src/services/TicketServices/FindOrCreateTicketServiceBot.ts @@ -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); } diff --git a/backend/src/services/WbotServices/wbotMessageListener.ts b/backend/src/services/WbotServices/wbotMessageListener.ts index 53b50e2..27a5131 100644 --- a/backend/src/services/WbotServices/wbotMessageListener.ts +++ b/backend/src/services/WbotServices/wbotMessageListener.ts @@ -748,8 +748,6 @@ const handleMessage = async ( // console.log('----------> chat: ', JSON.parse(JSON.stringify(chat))) - console - if (chat.isGroup) { // let msgGroupContact;