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')}`; 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: case 6: throw new Error( 'Este Servicio Social ya paso la fase de subir el informe global.' ); 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.'); } }) .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;