From da14d6064b6433c6d83a482dbb3444a4887083a1 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 1 Apr 2022 10:02:23 +0200 Subject: [PATCH] refactor(client_create): deteled checks on hook --- modules/client/back/models/client.js | 37 +--------------------------- 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index a14631c22..5ccc1ec64 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -30,6 +30,7 @@ module.exports = Self => { require('../methods/client/consumption')(Self); require('../methods/client/createReceipt')(Self); require('../methods/client/updatePortfolio')(Self); + require('../methods/client/checkDuplicated')(Self); // Validations @@ -304,42 +305,6 @@ module.exports = Self => { const assignmentChanged = workerIdBefore != workerIdAfter; if (assignmentChanged) await Self.notifyAssignment(instance, workerIdBefore, workerIdAfter); - - const emails = instance.email ? instance.email.split(',') : null; - - const findParams = []; - if (emails.length) { - for (let email of emails) - findParams.push({email: email}); - } - - if (instance.phone) - findParams.push({phone: instance.phone}); - - if (instance.mobile) - findParams.push({mobile: instance.mobile}); - - const filterObj = { - where: { - and: [ - {or: findParams}, - {id: {neq: instance.id}} - ] - } - }; - - const clientSameData = await Self.findOne(filterObj); - - if (clientSameData) { - await Self.app.models.Mail.create({ - receiver: 'direccioncomercial@verdnatura.es', - subject: `Cliente con email/teléfono/móvil duplicados`, - body: 'El cliente ' + instance.id + ' comparte alguno de estos datos con el cliente ' + clientSameData.id + - '\n- Email: ' + instance.email + - '\n- Teléfono: ' + instance.phone + - '\n- Móvil: ' + instance.mobile - }); - } }); // Send notification on client worker assignment