salix/loopback/util/validateNIF.js

15 lines
448 B
JavaScript

const models = require('vn-loopback/server/server').models;
module.exports = async function(fi, isVies, countryFk) {
const filter = {
fields: ['code'],
where: {id: countryFk}
};
const countryCode = fi.toUpperCase().substring(0, 2);
const country = await models.Country.findOne(filter);
const code = country ? country.code : null;
if (isVies && countryCode == code)
return false;
return true;
};