From 6c1f05d77ebd0ba43b2cd7eb323c01c48cb9bcf6 Mon Sep 17 00:00:00 2001 From: Lemuel Marquez Date: Sun, 29 Nov 2020 17:27:25 -0600 Subject: [PATCH] resubir carta de termino --- server/controller/Servicio/cartaAceptacion.js | 64 +++++++++++++++++++ .../controller/Servicio/rechazarAceptacion.js | 5 +- server/controller/Servicio/rechazarInforme.js | 5 +- server/controller/Servicio/rechazarTermino.js | 5 +- 4 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 server/controller/Servicio/cartaAceptacion.js diff --git a/server/controller/Servicio/cartaAceptacion.js b/server/controller/Servicio/cartaAceptacion.js new file mode 100644 index 0000000..1a5bf58 --- /dev/null +++ b/server/controller/Servicio/cartaAceptacion.js @@ -0,0 +1,64 @@ +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.cartaAceptacion) + throw new Error('Ya se subio la Carta de Aceptación.'); + switch (res.idStatus) { + case 7: + let path = `./server/uploads/${ + (validar.validar(file, 'El archivo'), 1000) + }`; + + return drive.uploadFile( + path, + `Carta_Termino.pdf`, + 'application/pdf', + res.carpeta + ); + case 1: + throw new Error( + 'Esta linea de la API solo puede ser usada cuando es estatus del Servicio Social sea 7.' + ); + case 2: + case 3: + case 4: + case 5: + throw new Error( + 'Este Servicio Social ya paso la fase de subir la Carta de Aceptación.' + ); + case 6: + throw new Error('Este Servicio Social ya finalizó.'); + case 8: + 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 fue cancelado. Comunicate con COESI para solucionar tu problema.' + ); + } + }) + .then((res) => { + return Servicio.update({ cartaTermino: res }, { where: { idServicio } }); + }) + .then((res) => { + return validar.validarPreTermino(idServicio); + }) + .then((res) => { + return { + message: `Se subio la Carta de Aceptación correctamente. ${res}`, + }; + }); +}; + +module.exports = cartaTermino; diff --git a/server/controller/Servicio/rechazarAceptacion.js b/server/controller/Servicio/rechazarAceptacion.js index 68987d4..729c57e 100644 --- a/server/controller/Servicio/rechazarAceptacion.js +++ b/server/controller/Servicio/rechazarAceptacion.js @@ -58,7 +58,10 @@ const cancelar = async (body) => { ); }) .then((res) => { - return Servicio.update({ idStatus: 7 }, { where: { idServicio } }); + return Servicio.update( + { idStatus: 7, cartaAceptacion: "" }, + { where: { idServicio } } + ); }) .then((res) => { return { message: 'Se rechazo correctamente la Carta de Aceptación.' }; diff --git a/server/controller/Servicio/rechazarInforme.js b/server/controller/Servicio/rechazarInforme.js index e830322..1953a8c 100644 --- a/server/controller/Servicio/rechazarInforme.js +++ b/server/controller/Servicio/rechazarInforme.js @@ -58,7 +58,10 @@ const cancelar = async (body) => { ); }) .then((res) => { - return Servicio.update({ idStatus: 9 }, { where: { idServicio } }); + return Servicio.update( + { idStatus: 9, informeGlobal: "" }, + { where: { idServicio } } + ); }) .then((res) => { return { message: 'Se rechazo correctamente el Informe Global.' }; diff --git a/server/controller/Servicio/rechazarTermino.js b/server/controller/Servicio/rechazarTermino.js index 3578ebd..8b175a3 100644 --- a/server/controller/Servicio/rechazarTermino.js +++ b/server/controller/Servicio/rechazarTermino.js @@ -58,7 +58,10 @@ const cancelar = async (body) => { ); }) .then((res) => { - return Servicio.update({ idStatus: 8 }, { where: { idServicio } }); + return Servicio.update( + { idStatus: 8, cartaTermino: "" }, + { where: { idServicio } } + ); }) .then((res) => { return { message: 'Se rechazo correctamente la Carta de Termino.' };