From 027fddf9ccbd74ba26743d100a36162751fcae15 Mon Sep 17 00:00:00 2001 From: Lemuel Marquez Date: Wed, 10 Feb 2021 01:59:57 -0600 Subject: [PATCH] liberacion y obtener servicios especiales listo --- server/controller/CasoEspecial/liberacion.js | 37 ++++++++++++ .../controller/CasoEspecial/serviciosAdmin.js | 0 .../CasoEspecial/serviciosEspeciales.js | 58 +++++++++++++++++++ .../CasoEspecial/serviciosResponsable.js | 0 server/controller/CuestionarioAlumno/nuevo.js | 2 + .../controller/CuestionarioPrograma/nuevo.js | 2 + server/controller/Servicio/cartaAceptacion.js | 2 + server/controller/Servicio/cartaTermino.js | 2 + server/controller/Servicio/informeGlobal.js | 2 + server/controller/Servicio/liberacion.js | 2 + .../controller/Servicio/rechazarAceptacion.js | 2 + server/controller/Servicio/rechazarInforme.js | 2 + server/controller/Servicio/rechazarTermino.js | 2 + server/controller/Servicio/registro.js | 2 + .../controller/Servicio/registroValidado.js | 2 + 15 files changed, 117 insertions(+) create mode 100644 server/controller/CasoEspecial/liberacion.js delete mode 100644 server/controller/CasoEspecial/serviciosAdmin.js create mode 100644 server/controller/CasoEspecial/serviciosEspeciales.js delete mode 100644 server/controller/CasoEspecial/serviciosResponsable.js diff --git a/server/controller/CasoEspecial/liberacion.js b/server/controller/CasoEspecial/liberacion.js new file mode 100644 index 0000000..962a1b0 --- /dev/null +++ b/server/controller/CasoEspecial/liberacion.js @@ -0,0 +1,37 @@ +const validar = require('../../helper/validar'); +const gmail = require('../../helper/gmail'); +const correos = require('../../helper/correos'); +const Servicio = require('../../db/tablas/Servicio'); +const Usuario = require('../../db/tablas/Usuario'); + +const liberacion = async (body) => { + const idServicio = validar.validarId(body.idServicio); + + return Servicio.findOne({ + where: { idServicio }, + include: [{ model: Usuario }], + }) + .then(async (res) => { + if (!res) throw new Error('No existe este Servicio Social.'); + switch (res.idStatus) { + case 11: + case 12: + let correo = correos.terminoValidado(res.Usuario.nombre); + + return gmail(correo.subject, res.correo, correo.msj); + case 6: + throw new Error( + 'Este Servicio Social ya se encuentra en Liberación.' + ); + default: + throw new Error('Id status no valido.'); + } + }) + .then((res) => Servicio.update({ idStatus: 6 }, { where: { idServicio } })) + .then((res) => ({ + message: + 'Se cambio de estatus correctamente y se envio un correo al alumno informandole de su liberación.', + })); +}; + +module.exports = liberacion; diff --git a/server/controller/CasoEspecial/serviciosAdmin.js b/server/controller/CasoEspecial/serviciosAdmin.js deleted file mode 100644 index e69de29..0000000 diff --git a/server/controller/CasoEspecial/serviciosEspeciales.js b/server/controller/CasoEspecial/serviciosEspeciales.js new file mode 100644 index 0000000..a348132 --- /dev/null +++ b/server/controller/CasoEspecial/serviciosEspeciales.js @@ -0,0 +1,58 @@ +const { Op } = require('sequelize'); +const validar = require('../../helper/validar'); +const CasoEspecial = require('../../db/tablas/CasoEspecial'); +const Usuario = require('../../db/tablas/Usuario'); +const Carrera = require('../../db/tablas/Carrera'); +const Status = require('../../db/tablas/Status'); +const TipoUsuario = require('../../db/tablas/TipoUsuario'); + +const serviciosEspeciales = async (body) => { + const pagina = validar.validarId(body.pagina); + const where = body.idStatus + ? { idStatus: validar.validarId(body.idStatus) } + : { [Op.or]: [{ idStatus: 6 }, { idStatus: { [Op.gt]: 10 } }] }; + const nombre = body.nombre + ? validar.validarTexto(body.nombre, 'El nombre', 60) + : ''; + const numeroCuenta = body.numeroCuenta + ? validar.validarNumeroCuenta(body.numeroCuenta) + : ''; + const data = []; + + return CasoEspecial.findAll({ + include: [ + { + model: Usuario, + include: { model: TipoUsuario }, + where: { + usuario: { [Op.like]: `%${numeroCuenta}%` }, + nombre: { [Op.like]: `%${nombre}%` }, + }, + }, + { model: Carrera }, + { model: Status, where }, + ], + order: [['updatedAt', 'DESC']], + }).then((res) => { + for (let i = pagina * 25 - 25; i < res.length && i < pagina * 25; i++) + data.push({ + idServicio: res[i].idServicio, + createdAt: res[i].createdAt, + Usuario: { + idUsuario: res[i].Usuario.idUsuario, + usuario: res[i].Usuario.usuario, + nombre: res[i].Usuario.nombre, + TipoUsuario: res[i].Usuario.TipoUsuario, + }, + Carrera: res[i].Carrera, + Status: res[i].Status, + }); + return { + registros: res.length, + faltantes: res.length - data.length - (pagina - 1) * 25, + servicios: data, + }; + }); +}; + +module.exports = serviciosEspeciales; diff --git a/server/controller/CasoEspecial/serviciosResponsable.js b/server/controller/CasoEspecial/serviciosResponsable.js deleted file mode 100644 index e69de29..0000000 diff --git a/server/controller/CuestionarioAlumno/nuevo.js b/server/controller/CuestionarioAlumno/nuevo.js index 9af5e8b..6feb5ae 100644 --- a/server/controller/CuestionarioAlumno/nuevo.js +++ b/server/controller/CuestionarioAlumno/nuevo.js @@ -141,6 +141,8 @@ const nuevo = async (body) => { ); case 10: throw new Error('Este Servicio Social fue cancelado.'); + default: + throw new Error('Id status no valido.'); } }) .then((res) => diff --git a/server/controller/CuestionarioPrograma/nuevo.js b/server/controller/CuestionarioPrograma/nuevo.js index 4f47838..55bb2ff 100644 --- a/server/controller/CuestionarioPrograma/nuevo.js +++ b/server/controller/CuestionarioPrograma/nuevo.js @@ -56,6 +56,8 @@ const nuevo = async (body) => { ); case 10: throw new Error('Este Servicio Social fue cancelado.'); + default: + throw new Error('Id status no valido.'); } }) .then((res) => diff --git a/server/controller/Servicio/cartaAceptacion.js b/server/controller/Servicio/cartaAceptacion.js index 9842a5e..9780cb4 100644 --- a/server/controller/Servicio/cartaAceptacion.js +++ b/server/controller/Servicio/cartaAceptacion.js @@ -43,6 +43,8 @@ const cartaTermino = async (body, file) => { throw new Error( 'Este Servicio Social fue cancelado. Comunicate con COESI para solucionar tu problema.' ); + default: + throw new Error('Id status no valido.'); } }) .then((res) => diff --git a/server/controller/Servicio/cartaTermino.js b/server/controller/Servicio/cartaTermino.js index aee1ca8..c9c920d 100644 --- a/server/controller/Servicio/cartaTermino.js +++ b/server/controller/Servicio/cartaTermino.js @@ -42,6 +42,8 @@ const cartaTermino = async (body, file) => { 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) => diff --git a/server/controller/Servicio/informeGlobal.js b/server/controller/Servicio/informeGlobal.js index 1c9fe53..0ea0a56 100644 --- a/server/controller/Servicio/informeGlobal.js +++ b/server/controller/Servicio/informeGlobal.js @@ -42,6 +42,8 @@ const informeGlobal = async (body, file) => { 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) => diff --git a/server/controller/Servicio/liberacion.js b/server/controller/Servicio/liberacion.js index e4388d6..11a2780 100644 --- a/server/controller/Servicio/liberacion.js +++ b/server/controller/Servicio/liberacion.js @@ -44,6 +44,8 @@ const liberacion = async (body) => { ); case 10: throw new Error('Este Servicio Social esta cancelado.'); + default: + throw new Error('Id status no valido.'); } }) .then((res) => Servicio.update(update, { where: { idServicio } })) diff --git a/server/controller/Servicio/rechazarAceptacion.js b/server/controller/Servicio/rechazarAceptacion.js index 4790dd2..5b087df 100644 --- a/server/controller/Servicio/rechazarAceptacion.js +++ b/server/controller/Servicio/rechazarAceptacion.js @@ -50,6 +50,8 @@ const cancelar = async (body) => { ); case 10: throw new Error('Este Servicio Social fue cancelado.'); + default: + throw new Error('Id status no valido.'); } }) .then((res) => diff --git a/server/controller/Servicio/rechazarInforme.js b/server/controller/Servicio/rechazarInforme.js index a88b773..ca00989 100644 --- a/server/controller/Servicio/rechazarInforme.js +++ b/server/controller/Servicio/rechazarInforme.js @@ -51,6 +51,8 @@ const cancelar = async (body) => { ); case 10: throw new Error('Este Servicio Social fue cancelado.'); + default: + throw new Error('Id status no valido.'); } }) .then((res) => diff --git a/server/controller/Servicio/rechazarTermino.js b/server/controller/Servicio/rechazarTermino.js index d240157..a2cb982 100644 --- a/server/controller/Servicio/rechazarTermino.js +++ b/server/controller/Servicio/rechazarTermino.js @@ -51,6 +51,8 @@ const cancelar = async (body) => { ); case 10: throw new Error('Este Servicio Social fue cancelado.'); + default: + throw new Error('Id status no valido.'); } }) .then((res) => diff --git a/server/controller/Servicio/registro.js b/server/controller/Servicio/registro.js index add06ef..e3601d1 100644 --- a/server/controller/Servicio/registro.js +++ b/server/controller/Servicio/registro.js @@ -39,6 +39,8 @@ const registro = async (body) => { ); case 10: throw new Error('Este Servicio Social fue cancelado.'); + default: + throw new Error('Id status no valido.'); } }) .then((res) => { diff --git a/server/controller/Servicio/registroValidado.js b/server/controller/Servicio/registroValidado.js index d562d35..6642178 100644 --- a/server/controller/Servicio/registroValidado.js +++ b/server/controller/Servicio/registroValidado.js @@ -60,6 +60,8 @@ const registroValidado = async (body) => { throw new Error( 'Este Servicio Social fue cancelado. Comunicate con COESI para solucionar tu problema.' ); + default: + throw new Error('Id status no valido.'); } }) .then((res) =>