client: dni validation
This commit is contained in:
parent
5874c80e85
commit
79e09e32e3
|
@ -43,7 +43,7 @@ node
|
|||
|
||||
stage ("Stopping/Removing Docker")
|
||||
{
|
||||
sh "docker-compose down --rmi all"
|
||||
sh "docker-compose down --rmi 'all'"
|
||||
}
|
||||
|
||||
stage ("Generar dockers")
|
||||
|
|
|
@ -53,6 +53,11 @@ module.exports = function(Self) {
|
|||
message: 'El iban no tiene el formato correcto'
|
||||
});
|
||||
|
||||
let validateDni = require('../validations/validateDni');
|
||||
Self.validateBinded('fi', validateDni, {
|
||||
message: 'Dni Incorrecto'
|
||||
});
|
||||
|
||||
Self.validate('payMethod', hasSalesMan, {
|
||||
message: 'No se puede cambiar la forma de pago si no hay comercial asignado'
|
||||
});
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
module.exports = fi => {
|
||||
let dni = fi;
|
||||
let getLetterDni = dni => {
|
||||
const regExpDni = 'TRWAGMYFPDXBNJZSQVHLCKE';
|
||||
const letterDni = dni.toUpperCase().substring(0, 1);
|
||||
let positionLetter = parseInt(dni) % 23;
|
||||
let getLetter = regExpDni.substring(positionLetter + 1, positionLetter);
|
||||
switch (letterDni) {
|
||||
case 'X': case 'Y': case 'Z':
|
||||
positionLetter = parseInt(dni.replace(letterDni, letterDni.charCodeAt(0) - 88)) % 23;
|
||||
getLetter = regExpDni.substring(positionLetter + 1, positionLetter);
|
||||
console.log(letterDni.charCodeAt(0));
|
||||
}
|
||||
return getLetter;
|
||||
};
|
||||
|
||||
let getDniSpain = (dniNumeric, dniLetter) => {
|
||||
let returnValue = false;
|
||||
switch (dni.length) {
|
||||
case 9:
|
||||
if (dniLetter === getLetterDni(dni))
|
||||
returnValue = true;
|
||||
}
|
||||
return returnValue;
|
||||
};
|
||||
|
||||
let getDniForeign = (dniNumeric, dniLetter) => {
|
||||
let returnValue = false;
|
||||
switch (dni.length) {
|
||||
case 9:
|
||||
if (dniLetter === getLetterDni(dni))
|
||||
returnValue = true;
|
||||
}
|
||||
return returnValue;
|
||||
};
|
||||
|
||||
let getDniBusiness = () => {
|
||||
if (dni.length == 9)
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
let getDniFrance = dniLetterCountry => {
|
||||
let returnValue = false;
|
||||
switch (dni.length) {
|
||||
case 13:
|
||||
if (dniLetter === 'R')
|
||||
returnValue = true;
|
||||
}
|
||||
return returnValue;
|
||||
};
|
||||
|
||||
let getDniItaly = dniLetterCountry => {
|
||||
let returnValue = false;
|
||||
switch (dni.length) {
|
||||
case 13:
|
||||
if (dniLetter === 'T')
|
||||
returnValue = true;
|
||||
}
|
||||
return returnValue;
|
||||
};
|
||||
|
||||
let getDni = () => {
|
||||
const dniNumeric = dni.substring(0, 8);
|
||||
const dniLetter = dni.substring(8, 9);
|
||||
const dniLetterCountry = dni.substring(0, 1);
|
||||
const dniLetterAscii = parseInt(dniLetterCountry.charCodeAt(0));
|
||||
let dniValue = false;
|
||||
switch (true) {
|
||||
case (dniLetterAscii >= 88 && dniLetterAscii <= 90): // X-Z
|
||||
dniValue = getDniForeign(dniNumeric, dniLetter);
|
||||
break;
|
||||
case (dniLetterAscii === 66): // B
|
||||
dniValue = getDniBusiness();
|
||||
break;
|
||||
case (dniLetterAscii === 70): // F
|
||||
dniValue = getDniFrance(dniLetterCountry);
|
||||
break;
|
||||
case (dniLetterAscii === 73): // I
|
||||
dniValue = getDniItaly(dniLetterCountry);
|
||||
break;
|
||||
case (dniLetterAscii >= 48 && dniLetterAscii <= 57): // 0- 9
|
||||
console.log('dni spain');
|
||||
dniValue = getDniSpain(dniNumeric, dniLetter);
|
||||
break;
|
||||
default:
|
||||
console.log('default');
|
||||
dniValue = true;
|
||||
}
|
||||
return dniValue;
|
||||
};
|
||||
|
||||
return getDni();
|
||||
};
|
Loading…
Reference in New Issue