refs #5540 create validateIban
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Satorres 2023-04-28 09:07:06 +02:00
parent e1864fec09
commit b8f7f7bd69
2 changed files with 26 additions and 13 deletions

View File

@ -0,0 +1,12 @@
module.exports = async function(fi) {
const filter = {
fields: ['code'],
where: {id: this.countryFk}
};
const countryCode = this.fi.toUpperCase().substring(0, 2);
const country = await app.models.Country.findOne(filter);
const code = country ? country.code : null;
if (this.isVies && countryCode == code)
err();
done();
};

View File

@ -4,6 +4,7 @@ const isMultiple = require('vn-loopback/util/hook').isMultiple;
const validateTin = require('vn-loopback/util/validateTin');
const validateIban = require('vn-loopback/util/validateIban');
const LoopBackContext = require('loopback-context');
const validateNIF = require('vn-loopback/util/validateNIF');
module.exports = Self => {
// Methods
@ -23,22 +24,22 @@ module.exports = Self => {
message: 'TIN must be unique'
});
Self.validateAsync('fi', fiInvalid, {
Self.validateAsync('fi', validateNIF(fi), {
message: 'Invalid TIN'
});
async function fiInvalid(err, done) {
const filter = {
fields: ['code'],
where: {id: this.countryFk}
};
const countryCode = this.fi.toUpperCase().substring(0, 2);
const country = await Self.app.models.Country.findOne(filter);
const code = country ? country.code : null;
if (this.isVies && countryCode == code)
err();
done();
}
// async function fiInvalid(err, done) {
// const filter = {
// fields: ['code'],
// where: {id: this.countryFk}
// };
// const countryCode = this.fi.toUpperCase().substring(0, 2);
// const country = await Self.app.models.Country.findOne(filter);
// const code = country ? country.code : null;
// if (this.isVies && countryCode == code)
// err();
// done();
// }
Self.validatesFormatOf('email', {
message: 'Invalid email',