This commit is contained in:
parent
ad07c4ec97
commit
b57106af48
|
@ -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();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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, $) {
|
||||
|
|
Loading…
Reference in New Issue