refactor(client_create): deteled checks on hook

This commit is contained in:
Vicent Llopis 2022-04-01 10:02:23 +02:00
parent b29261cb75
commit da14d6064b
1 changed files with 1 additions and 36 deletions

View File

@ -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