refactor(client_create): added checks on back route
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
da14d6064b
commit
3de9ea2ce5
|
@ -0,0 +1,64 @@
|
||||||
|
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 emails = client.email ? client.email.split(',') : null;
|
||||||
|
|
||||||
|
const findParams = [];
|
||||||
|
if (emails.length) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -12,6 +12,7 @@ export default class Controller extends Section {
|
||||||
return this.$.watcher.submit().then(() => {
|
return this.$.watcher.submit().then(() => {
|
||||||
const query = `Clients/updatePortfolio`;
|
const query = `Clients/updatePortfolio`;
|
||||||
this.$http.get(query);
|
this.$http.get(query);
|
||||||
|
this.$http.get(`Clients/${this.$params.id}/checkDuplicatedData`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,9 @@ export default class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
return this.$.watcher.submit().then(
|
return this.$.watcher.submit()
|
||||||
json => this.$state.go('client.card.basicData', {id: json.data.id})
|
.then(json => this.$state.go('client.card.basicData', {id: json.data.id}))
|
||||||
);
|
.then(() => this.$http.get(`Clients/${this.client.id}/checkDuplicatedData`));
|
||||||
}
|
}
|
||||||
|
|
||||||
get province() {
|
get province() {
|
||||||
|
|
Loading…
Reference in New Issue