insert mail
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Javi Gallego 2021-08-27 09:01:21 +02:00
parent 072f88d1a5
commit 488ef17559
2 changed files with 14 additions and 0 deletions

View File

@ -0,0 +1 @@
DROP TRIGGER vn.supplierAccount_AfterInsert;

View File

@ -1,4 +1,5 @@
const validateIban = require('vn-loopback/util/validateIban');
const LoopBackContext = require('loopback-context');
module.exports = Self => {
Self.validateAsync('iban', ibanValidation, {
@ -19,4 +20,16 @@ module.exports = Self => {
err();
done();
}
Self.observe('after save', async ctx => {
const loopBackContext = LoopBackContext.getCurrentContext();
const models = Self.app.models;
const user = await models.user.findById(loopBackContext.active.accessToken.userId);
const bankEntity = await models.BankEntity.findById(ctx.instance.bankEntityFk);
await Self.app.models.Mail.create({
sender: 'finanzas@verdnatura.es',
subject: 'Añadida cuenta bancaria al proveedor' + ctx.instance.supplierFk,
body: user.username + ' ha añadido: ' +
ctx.instance.iban + ', entidad: ' + bankEntity.name + ', bic: ' + bankEntity.bic
});
});
};