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`);
|
2020-11-23 00:52:38 -06:00
|
|
|
const Servicio = require('../../db/tablas/Servicio');
|
|
|
|
|
|
|
|
|
|
const informeGlobal = async (body, file) => {
|
2022-01-02 15:07:49 -06:00
|
|
|
const idServicio = validar.validarNumeroEntero(
|
|
|
|
|
body.idServicio,
|
|
|
|
|
'id servicio'
|
|
|
|
|
);
|
2022-01-02 18:36:46 -06:00
|
|
|
const path = `./server/uploads/${validar.validacionBasicaStr(
|
|
|
|
|
file,
|
|
|
|
|
'archivo',
|
|
|
|
|
true,
|
|
|
|
|
1000
|
|
|
|
|
)}`;
|
2020-11-23 00:52:38 -06:00
|
|
|
|
|
|
|
|
return Servicio.findOne({
|
|
|
|
|
where: { idServicio },
|
|
|
|
|
})
|
|
|
|
|
.then((res) => {
|
|
|
|
|
if (!res) throw new Error('Este servicio no existe.');
|
2020-11-27 18:55:18 -06:00
|
|
|
if (res.informeGlobal) throw new Error('Ya se subio el Informe Global.');
|
2020-11-23 00:52:38 -06:00
|
|
|
switch (res.idStatus) {
|
|
|
|
|
case 4:
|
|
|
|
|
case 9:
|
|
|
|
|
return drive.uploadFile(
|
|
|
|
|
path,
|
|
|
|
|
`Informe_Global.pdf`,
|
|
|
|
|
'application/pdf',
|
|
|
|
|
res.carpeta
|
|
|
|
|
);
|
|
|
|
|
case 1:
|
|
|
|
|
case 2:
|
|
|
|
|
case 3:
|
|
|
|
|
throw new Error(
|
2020-11-27 18:55:18 -06:00
|
|
|
'Aun no se puede subir el Informe Global a este Servicio Social.'
|
2020-11-23 00:52:38 -06:00
|
|
|
);
|
|
|
|
|
case 5:
|
|
|
|
|
throw new Error(
|
2020-11-27 18:55:18 -06:00
|
|
|
'Este Servicio Social ya paso la fase de subir el Informe Global.'
|
2020-11-23 00:52:38 -06:00
|
|
|
);
|
2020-11-27 18:55:18 -06:00
|
|
|
case 6:
|
|
|
|
|
throw new Error('Este Servicio Social ya finalizó.');
|
2020-11-23 00:52:38 -06:00
|
|
|
case 7:
|
|
|
|
|
case 8:
|
|
|
|
|
throw new Error(
|
|
|
|
|
'Este Servicio Social se encuentra rechazado. No se puede avanzar hasta que se corriga lo necesario.'
|
|
|
|
|
);
|
|
|
|
|
case 10:
|
2020-12-08 18:43:06 -06:00
|
|
|
throw new Error(
|
|
|
|
|
'Este Servicio Social esta cancelado. Comunicate con COESI para solucionar tu problema.'
|
|
|
|
|
);
|
2021-02-10 01:59:57 -06:00
|
|
|
default:
|
|
|
|
|
throw new Error('Id status no valido.');
|
2020-11-23 00:52:38 -06:00
|
|
|
}
|
|
|
|
|
})
|
2021-01-12 21:09:37 -06:00
|
|
|
.then((res) =>
|
|
|
|
|
Servicio.update({ informeGlobal: res }, { where: { idServicio } })
|
|
|
|
|
)
|
|
|
|
|
.then(async (res) => validar.validarPreTermino(idServicio))
|
2021-01-14 16:02:57 -06:00
|
|
|
.then((res) => ({
|
|
|
|
|
message: `Se subio el Informe Global correctamente. ${res}`,
|
|
|
|
|
}));
|
2020-11-23 00:52:38 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = informeGlobal;
|