client: dni validation

This commit is contained in:
Vicente Falco 2017-11-16 12:02:45 +01:00
parent 5874c80e85
commit 79e09e32e3
3 changed files with 100 additions and 1 deletions

2
Jenkinsfile vendored
View File

@ -43,7 +43,7 @@ node
stage ("Stopping/Removing Docker") stage ("Stopping/Removing Docker")
{ {
sh "docker-compose down --rmi all" sh "docker-compose down --rmi 'all'"
} }
stage ("Generar dockers") stage ("Generar dockers")

View File

@ -53,6 +53,11 @@ module.exports = function(Self) {
message: 'El iban no tiene el formato correcto' message: 'El iban no tiene el formato correcto'
}); });
let validateDni = require('../validations/validateDni');
Self.validateBinded('fi', validateDni, {
message: 'Dni Incorrecto'
});
Self.validate('payMethod', hasSalesMan, { Self.validate('payMethod', hasSalesMan, {
message: 'No se puede cambiar la forma de pago si no hay comercial asignado' message: 'No se puede cambiar la forma de pago si no hay comercial asignado'
}); });

View File

@ -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();
};