Files
servicio_social_api/server/controller/Servicio/informeGlobal.js
T

68 lines
1.9 KiB
JavaScript

const helperPath = '../../helper';
//const drive = require(`${helperPath}/drive`);
const validar = require(`${helperPath}/validar`);
const Servicio = require('../../db/tablas/Servicio');
const informeGlobal = async (body, file) => {
const idServicio = validar.validarNumeroEntero(
body.idServicio,
'id servicio'
);
const path = `./server/uploads/${validar.validacionBasicaStr(
file,
'archivo',
true,
1000
)}`;
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:
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.'
);
default:
throw new Error('Id status no valido.');
}
})
.then((res) =>
Servicio.update({ informeGlobal: res }, { where: { idServicio } })
)
.then(async (res) => validar.validarPreTermino(idServicio))
.then((res) => ({
message: `Se subio el Informe Global correctamente. ${res}`,
}));
};
module.exports = informeGlobal;