refs #6291 validateTin #1836
|
@ -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),
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue