fixes #5437 Desactivar correos "Cliente con email/teléfono/móvil duplicados" #1420
|
@ -1,63 +0,0 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('checkDuplicatedData', {
|
||||
description: 'Checks if a client has same email, mobile or phone than other client and send an email',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The client id'
|
||||
}],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
verb: 'GET',
|
||||
path: '/:id/checkDuplicatedData'
|
||||
}
|
||||
});
|
||||
|
||||
Self.checkDuplicatedData = async function(id, options) {
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const client = await Self.app.models.Client.findById(id, myOptions);
|
||||
|
||||
const findParams = [];
|
||||
if (client.email) {
|
||||
const emails = client.email.split(',');
|
||||
for (let email of emails)
|
||||
findParams.push({email: email});
|
||||
}
|
||||
|
||||
if (client.phone)
|
||||
findParams.push({phone: client.phone});
|
||||
|
||||
if (client.mobile)
|
||||
findParams.push({mobile: client.mobile});
|
||||
|
||||
const filterObj = {
|
||||
where: {
|
||||
and: [
|
||||
{or: findParams},
|
||||
{id: {neq: client.id}}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
const clientSameData = await Self.findOne(filterObj, myOptions);
|
||||
|
||||
if (clientSameData) {
|
||||
await Self.app.models.Mail.create({
|
||||
receiver: 'direccioncomercial@verdnatura.es',
|
||||
subject: `Cliente con email/teléfono/móvil duplicados`,
|
||||
body: 'El cliente ' + client.id + ' comparte alguno de estos datos con el cliente ' + clientSameData.id +
|
||||
'\n- Email: ' + client.email +
|
||||
'\n- Teléfono: ' + client.phone +
|
||||
'\n- Móvil: ' + client.mobile
|
||||
}, myOptions);
|
||||
}
|
||||
};
|
||||
};
|
|
@ -1,24 +0,0 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('client checkDuplicated()', () => {
|
||||
it('should send an mail if mobile/phone/email is duplicated', async() => {
|
||||
const tx = await models.Client.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const id = 1110;
|
||||
const mailModel = models.Mail;
|
||||
spyOn(mailModel, 'create');
|
||||
|
||||
await models.Client.checkDuplicatedData(id, options);
|
||||
|
||||
expect(mailModel.create).toHaveBeenCalled();
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -2,7 +2,6 @@ module.exports = Self => {
|
|||
require('../methods/client/addressesPropagateRe')(Self);
|
||||
require('../methods/client/canBeInvoiced')(Self);
|
||||
require('../methods/client/canCreateTicket')(Self);
|
||||
require('../methods/client/checkDuplicated')(Self);
|
||||
require('../methods/client/confirmTransaction')(Self);
|
||||
require('../methods/client/consumption')(Self);
|
||||
require('../methods/client/createAddress')(Self);
|
||||
|
|
|
@ -9,9 +9,7 @@ export default class Controller extends Section {
|
|||
}
|
||||
|
||||
onSubmit() {
|
||||
return this.$.watcher.submit().then(() => {
|
||||
this.$http.get(`Clients/${this.$params.id}/checkDuplicatedData`);
|
||||
});
|
||||
return this.$.watcher.submit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ export default class Controller extends Section {
|
|||
onSubmit() {
|
||||
return this.$.watcher.submit().then(json => {
|
||||
this.$state.go('client.card.basicData', {id: json.data.id});
|
||||
this.$http.get(`Clients/${this.client.id}/checkDuplicatedData`);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue