56 lines
1.9 KiB
JavaScript
56 lines
1.9 KiB
JavaScript
const validar = require('../../helper/validar');
|
|
const CasoEspecial = require('../../db/tablas/CasoEspecial');
|
|
|
|
const update = async (body) => {
|
|
const idCasoEspecial = validar.validarId(body.idCasoEspecial);
|
|
const dataUpdate = {};
|
|
|
|
return CasoEspecial.findOne({ where: { idCasoEspecial } })
|
|
.then(async (res) => {
|
|
if (!res) throw new Error('Este Caso Especial no existe en la db.');
|
|
if (body.correo) dataUpdate.correo = validar.validarCorreo(body.correo);
|
|
if (body.fechaInicio)
|
|
dataUpdate.fechaInicio = validar.validarFecha(body.fechaInicio);
|
|
if (body.fechaFin)
|
|
dataUpdate.fechaFin = validar.validarFecha(body.fechaFin);
|
|
if (body.fechaNacimiento)
|
|
dataUpdate.fechaNacimiento = validar.validarFecha(body.fechaNacimiento);
|
|
if (body.direccion)
|
|
dataUpdate.direccion = validar.validarAlfanumerico(
|
|
body.direccion,
|
|
'La dirección',
|
|
200
|
|
);
|
|
if (body.telefono)
|
|
dataUpdate.telefono = validar.validarNumero(body.telefono, 15);
|
|
if (body.institucion)
|
|
dataUpdate.institucion = validar.validarTexto(
|
|
body.institucion,
|
|
'El texto institucion.',
|
|
200
|
|
);
|
|
if (body.dependencia)
|
|
dataUpdate.dependencia = validar.validarTexto(
|
|
body.dependencia,
|
|
'El texto dependencia.',
|
|
200
|
|
);
|
|
if (body.motivo)
|
|
dataUpdate.motivo = validar.validarNumero(
|
|
body.motivo,
|
|
'El texto motivo.',
|
|
1
|
|
);
|
|
if (validar.validarObjetoVacio(dataUpdate))
|
|
throw new Error(
|
|
'No se envio nada para actualizar este Caso Especial.'
|
|
);
|
|
return CasoEspecial.update(dataUpdate, { where: { idCasoEspecial } });
|
|
})
|
|
.then((res) => ({
|
|
message: 'Se guardo correctamente los cambios de este servicio.',
|
|
}));
|
|
};
|
|
|
|
module.exports = update;
|