check if email, phone or mobile already exists in another client
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
e85c0c53c6
commit
c8ae5bca82
|
@ -304,6 +304,42 @@ 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