This commit is contained in:
parent
e1864fec09
commit
b8f7f7bd69
|
@ -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();
|
||||
};
|
|
@ -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',
|
||||
|
|
Loading…
Reference in New Issue