pre registro sin subir achrivo

This commit is contained in:
2020-11-17 10:12:30 -06:00
parent 8f0aa05388
commit b96fabb078
8 changed files with 74 additions and 25 deletions
+23 -7
View File
@@ -2,7 +2,7 @@ const validator = require('validator');
const moment = require('moment');
const noValido = (campo) => {
throw new Error(`El ${campo} no es valido.`);
throw new Error(`${campo} no es valido.`);
};
const noHay = (variable, campo) => {
@@ -10,11 +10,11 @@ const noHay = (variable, campo) => {
};
const yaExiste = (campo) => {
throw new Error(`El ${campo} ya se encuentra en uso.`);
throw new Error(`${campo} ya se encuentra en uso.`);
};
const validarId = (id) => {
let campo = 'id';
let campo = 'El id';
noHay(id, campo);
if (typeof id === 'number') id = id.toString();
@@ -24,7 +24,7 @@ const validarId = (id) => {
};
const validarCorreo = (correo) => {
let campo = 'correo';
let campo = 'El correo';
noHay(correo, campo);
if (typeof correo !== 'string' || !validator.isEmail(correo)) noValido(campo);
@@ -42,7 +42,7 @@ const validarTexto = (texto, campo) => {
};
const validarNumeroCuenta = (numeroCuenta) => {
let campo = 'numero de cuenta';
let campo = 'El numero de cuenta';
noHay(numeroCuenta, campo);
if (
@@ -55,14 +55,26 @@ const validarNumeroCuenta = (numeroCuenta) => {
};
const validarFecha = (fecha) => {
let campo = 'fecha';
let campo = 'La fecha';
let fechaMoment = moment(fecha);
noHay(fecha, campo);
if (fechaMoment.isValid()) noValido(campo);
if (!fechaMoment.isValid()) noValido(campo);
return fechaMoment;
};
const validarNumero = (numero) => {
let campo = 'El numero';
noHay(numero, campo);
if (
typeof numero !== 'string' ||
!validator.isNumeric(numero, { no_symbols: true })
)
noValido(campo);
return numero;
};
module.exports = {
noValido,
yaExiste,
@@ -72,4 +84,8 @@ module.exports = {
validarTexto,
validarNumeroCuenta,
validarFecha,
validarNumero,
};
// console.log(moment('2020-01-01').format());
// 2020-01-01T00:00:00-06:00