subri carta de termino e informe global listo

This commit is contained in:
2020-11-23 00:52:38 -06:00
parent 2ae79c3962
commit 7973212dbb
10 changed files with 247 additions and 44 deletions
@@ -0,0 +1,58 @@
const validar = require('../../helper/validar');
const drive = require('../../helper/drive');
const Servicio = require('../../db/tablas/Servicio');
const cartaTermino = 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.cartaTermino) throw new Error('Ya se subio la carta de termino.');
switch (res.idStatus) {
case 4:
case 8:
let path = `./server/uploads/${validar.validar(file, 'El archivo')}`;
return drive.uploadFile(
path,
`Carta_Termino.pdf`,
'application/pdf',
res.carpeta
);
case 1:
case 2:
case 3:
throw new Error(
'Aun no se puede subir la carta de termino a este Servicio Social.'
);
case 5:
case 6:
throw new Error(
'Este Servicio Social ya paso la fase de subir la carta de termino.'
);
case 7:
case 9:
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.');
}
})
.then((res) => {
return Servicio.update({ cartaTermino: res }, { where: { idServicio } });
})
.then(async (res) => {
let message = `Se subio el informe global correctamente.`;
message += await validar.validarPreTermino(idServicio);
return { message };
});
};
module.exports = cartaTermino;