231801_test_to_master #1519

Merged
alexm merged 490 commits from 231801_test_to_master into master 2023-05-12 06:29:59 +00:00
2 changed files with 26 additions and 13 deletions
Showing only changes of commit b8f7f7bd69 - Show all commits

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