refs #6291 validateTin
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Carlos Satorres 2023-11-14 11:13:33 +01:00
parent ad07c4ec97
commit b57106af48
2 changed files with 22 additions and 0 deletions

View File

@ -23,4 +23,25 @@ module.exports = Self => {
Self.validatesUniquenessOf('locker', {
message: 'This locker has already been assigned'
});
Self.validateAsync('fi', tinIsValid, {
message: 'Invalid TIN'
});
async function tinIsValid(err, done) {
if (!this.isTaxDataChecked)
return done();
const filter = {
fields: ['code'],
where: {id: this.countryFk}
};
const country = await Self.app.models.Country.findOne(filter);
const code = country ? country.code.toLowerCase() : null;
const countryCode = this.fi?.toLowerCase().substring(0, 2);
if (!this.fi || !validateTin(this.fi, code) || (this.isVies && countryCode == code))
err();
done();
}
};

View File

@ -1,5 +1,6 @@
import ngModule from '../module';
import Section from 'salix/components/section';
const validateTin = require('vn-loopback/util/validateTin');
export default class Controller extends Section {
constructor($element, $) {