refs #6291 validateTin #1836

Merged
carlossa merged 12 commits from 6291-comprobarDNI into dev 2024-01-09 14:03:21 +00:00
2 changed files with 30 additions and 3 deletions

View File

@ -3011,6 +3011,15 @@ INSERT INTO `vn`.`invoiceCorrectionType` (`id`, `description`)
(2, 'Error in sales details'),
(3, 'Error in customer data');
UPDATE `vn`.`client`
SET fi='65004204V'
WHERE id=1;
UPDATE `vn`.`worker`
SET fi='59328808D'
WHERE id=1106;
INSERT INTO `account`.`mailAliasAcl` (`mailAliasFk`, `roleFk`)
VALUES
(1, 1),

View File

@ -1,4 +1,5 @@
module.exports = Self => {
const validateTin = require('vn-loopback/util/validateTin');
require('../methods/worker/filter')(Self);
require('../methods/worker/mySubordinates')(Self);
require('../methods/worker/isSubordinate')(Self);
@ -23,4 +24,21 @@ 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) {
const filter = {
fields: ['code'],
where: {id: this.countryFk}
};
const country = await Self.app.models.Country.findOne(filter);
const code = country ? country.code.toLowerCase() : null;
if (!this.fi || !validateTin(this.fi, code))
err();
done();
}
};