Files

93 lines
2.8 KiB
JavaScript
Raw Permalink Normal View History

2021-05-05 18:49:23 -05:00
const helperPath = '../../helper';
const drive = require(`${helperPath}/drive`);
2021-05-13 14:06:07 -05:00
const validar = require(`${helperPath}/validar`);
2021-01-05 23:59:05 -06:00
const Servicio = require('../../db/tablas/Servicio');
const update = async (body, files) => {
2022-01-02 15:07:49 -06:00
const idServicio = validar.validarNumeroEntero(
body.idServicio,
'id servicio'
);
2021-01-14 03:13:37 -06:00
const dataUpdate = {};
2021-01-05 23:59:05 -06:00
return Servicio.findOne({ where: { idServicio } })
.then(async (res) => {
if (!res) throw new Error('Este Servicio Social no existe en la db.');
try {
if (files['cartaAceptacion'][0].filename)
dataUpdate.cartaAceptacion = await drive.uploadFile(
`./server/uploads/${files['cartaAceptacion'][0].filename}`,
`Carta_Aceptacion.pdf`,
'application/pdf',
res.carpeta
);
2021-01-06 00:16:50 -06:00
} catch (err) {}
try {
2021-01-05 23:59:05 -06:00
if (files['cartaTermino'][0].filename)
dataUpdate.cartaTermino = await drive.uploadFile(
`./server/uploads/${files['cartaTermino'][0].filename}`,
`Carta_Termino.pdf`,
'application/pdf',
res.carpeta
);
2021-01-06 00:16:50 -06:00
} catch (err) {}
try {
2021-01-05 23:59:05 -06:00
if (files['informeGlobal'][0].filename)
dataUpdate.informeGlobal = await drive.uploadFile(
`./server/uploads/${files['informeGlobal'][0].filename}`,
`Informe_Global.pdf`,
'application/pdf',
res.carpeta
);
} catch (err) {}
if (body.correo) dataUpdate.correo = validar.validarCorreo(body.correo);
if (body.fechaInicio)
2022-01-02 17:56:42 -06:00
dataUpdate.fechaInicio = validar.validarFecha(
body.fechaInicio,
'fecha de inicio',
false
);
2021-01-05 23:59:05 -06:00
if (body.fechaFin)
2022-01-02 17:56:42 -06:00
dataUpdate.fechaFin = validar.validarFecha(
body.fechaFin,
'fecha fin',
false
);
2021-01-05 23:59:05 -06:00
if (body.fechaNacimiento)
2022-01-02 17:56:42 -06:00
dataUpdate.fechaNacimiento = validar.validarFecha(
body.fechaNacimiento,
'fecha de nacimiento',
false
);
2021-01-05 23:59:05 -06:00
if (body.direccion)
dataUpdate.direccion = validar.validarAlfanumerico(
body.direccion,
2022-01-02 17:45:29 -06:00
'dirección',
false,
2021-01-05 23:59:05 -06:00
200
);
if (body.telefono)
2022-01-02 18:25:31 -06:00
dataUpdate.telefono = validar.validarNumero(
body.telefono,
'teléfono',
true,
15
);
2021-05-13 14:06:07 -05:00
if (validar.validarObjetoVacio(dataUpdate))
2021-01-05 23:59:05 -06:00
throw new Error(
'No se envio nada para actualizar este Servicio Social'
);
return Servicio.update(dataUpdate, { where: { idServicio } });
})
.then(async (res) => {
if (dataUpdate.cartaTermino || dataUpdate.informeGlobal)
return validar.validarPreTermino(idServicio);
return false;
})
2021-01-14 16:02:57 -06:00
.then((res) => ({
2021-02-26 14:17:42 -06:00
message: 'Se guardo correctamente los cambios de este servicio.',
2021-01-14 16:02:57 -06:00
}));
2021-01-05 23:59:05 -06:00
};
module.exports = update;