From f601dbb69975d82440d6d7639375ac9de190273b Mon Sep 17 00:00:00 2001 From: adriano Date: Thu, 13 Mar 2025 10:25:59 -0300 Subject: [PATCH] feat: Add soluction to remove 0 at the beginning of the contact before creating call journaling --- backend/controllers/crmController.js | 10 +++++++--- backend/utils/removeZeroInicial.js | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 backend/utils/removeZeroInicial.js diff --git a/backend/controllers/crmController.js b/backend/controllers/crmController.js index 1a78436..b13a7f8 100644 --- a/backend/controllers/crmController.js +++ b/backend/controllers/crmController.js @@ -28,6 +28,8 @@ const whatsappJournalingCRM = require('../utils/whatsappJournalingCRM') const redirectContactLinkCRM = require('../utils/redirectContactLinkCRM') const sfcase = require('../utils/sfCase') const sfCaseUpdate = require('../utils/sfCaseUpdate') +const removeZeroInicial = require('../utils/removeZeroInicial') + const contactCreate = async (req, res) => { @@ -81,8 +83,8 @@ const callJournaling = async (req, res) => { console.log(`[REQ.BODY - ${new Date()}] callJournaling: `, JSON.stringify(req.body, null, 6)) - // test remove - // return res.status(StatusCodes.OK).send() + // Remove 0 from the beginning of the number. Ex: 011996067641 to 11996067641 + crmPhone = removeZeroInicial(crmPhone) // Refactor this in the future. crmPhone = '55' + crmPhone @@ -117,7 +119,7 @@ const callJournaling = async (req, res) => { console.log('update-answer') // Referente a cliente a gabriel, pois os tickets estao sendo abertos diretamente em um botao do hitphone - // if (companyId != "14223") + // if (companyId != "14223") await ticketCRM(companyId, crmPhone, crmAgent, crmFirstName) const resp = await redirectContactLinkCRM(companyId, crmPhone, crmAgent, crmFirstName) @@ -373,6 +375,8 @@ const createTicket = async (req, res) => { let { companyId, crmPhone } = req.body + mustContainProperties(req, ['companyId', 'crmPhone']) + const crmTicketLinks = await ticketCRM(companyId, crmPhone) return res.status(StatusCodes.OK).json({ crmTicketLinks }) diff --git a/backend/utils/removeZeroInicial.js b/backend/utils/removeZeroInicial.js new file mode 100644 index 0000000..693781c --- /dev/null +++ b/backend/utils/removeZeroInicial.js @@ -0,0 +1,6 @@ + +function removeZeroInicial(numero) { + return numero.replace(/^0+/, ''); +} + +module.exports = removeZeroInicial