refs #6291 dni vn-user
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Satorres 2023-11-21 16:25:48 +01:00
parent b57106af48
commit 7c6798c564
3 changed files with 22 additions and 22 deletions

View File

@ -2,6 +2,7 @@ const vnModel = require('vn-loopback/common/models/vn-model');
const {Email} = require('vn-print');
const ForbiddenError = require('vn-loopback/util/forbiddenError');
const LoopBackContext = require('loopback-context');
const validateTin = require('vn-loopback/util/validateTin');
module.exports = function(Self) {
vnModel(Self);
@ -19,6 +20,27 @@ module.exports = function(Self) {
// Validations
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();
}
Self.validatesFormatOf('email', {
message: 'Invalid email',
allowNull: true,

View File

@ -23,25 +23,4 @@ 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,6 +1,5 @@
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, $) {