Files
servicio_social_api/server/controller/Servicio/informeGlobal.js
T
Lemuel Marquez 9b413a116b error lemuel
2020-12-09 18:33:41 -06:00

67 lines
1.9 KiB
JavaScript

const validar = require('../../helper/validar');
const drive = require('../../helper/drive');
const Servicio = require('../../db/tablas/Servicio');
const informeGlobal = async (body, file) => {
let idServicio = validar.validarId(body.idServicio);
return Servicio.findOne({
where: { idServicio },
})
.then((res) => {
if (!res) throw new Error('Este servicio no existe.');
if (res.informeGlobal) throw new Error('Ya se subio el Informe Global.');
switch (res.idStatus) {
case 4:
case 9:
let path = `./server/uploads/${validar.validar(
file,
'El archivo',
1000
)}`;
return drive.uploadFile(
path,
`Informe_Global.pdf`,
'application/pdf',
res.carpeta
);
case 1:
case 2:
case 3:
throw new Error(
'Aun no se puede subir el Informe Global a este Servicio Social.'
);
case 5:
throw new Error(
'Este Servicio Social ya paso la fase de subir el Informe Global.'
);
case 6:
throw new Error('Este Servicio Social ya finalizó.');
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:
throw new Error(
'Este Servicio Social esta cancelado. Comunicate con COESI para solucionar tu problema.'
);
}
})
.then((res) => {
return Servicio.update(
{ informeGlobal: res },
{ where: { idServicio } }
);
})
.then(async (res) => {
return validar.validarPreTermino(idServicio);
})
.then((res) => {
return { message: `Se subio el Informe Global correctamente. ${res}` };
});
};
module.exports = informeGlobal;