refactor(client_create): deteled checks on hook
This commit is contained in:
parent
b29261cb75
commit
da14d6064b
|
@ -30,6 +30,7 @@ module.exports = Self => {
|
||||||
require('../methods/client/consumption')(Self);
|
require('../methods/client/consumption')(Self);
|
||||||
require('../methods/client/createReceipt')(Self);
|
require('../methods/client/createReceipt')(Self);
|
||||||
require('../methods/client/updatePortfolio')(Self);
|
require('../methods/client/updatePortfolio')(Self);
|
||||||
|
require('../methods/client/checkDuplicated')(Self);
|
||||||
|
|
||||||
// Validations
|
// Validations
|
||||||
|
|
||||||
|
@ -304,42 +305,6 @@ module.exports = Self => {
|
||||||
const assignmentChanged = workerIdBefore != workerIdAfter;
|
const assignmentChanged = workerIdBefore != workerIdAfter;
|
||||||
if (assignmentChanged)
|
if (assignmentChanged)
|
||||||
await Self.notifyAssignment(instance, workerIdBefore, workerIdAfter);
|
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
|
// Send notification on client worker assignment
|
||||||
|
|
Loading…
Reference in New Issue