diff --git a/server/controller/CuestionarioAlumno/get.js b/server/controller/CuestionarioAlumno/get.js index cbda239..10961f5 100644 --- a/server/controller/CuestionarioAlumno/get.js +++ b/server/controller/CuestionarioAlumno/get.js @@ -6,9 +6,12 @@ const CuestionarioAlumno = require('../../db/tablas/CuestionarioAlumno'); const Servicio = require('../../db/tablas/Servicio'); const Programa = require('../../db/tablas/Programa'); const Usuario = require('../../db/tablas/Usuario'); +const { EROFS } = require('constants'); const get = async (body) => { - let year = validar.validarNumero(body.year, 4); + const year = validar.validarNumero(body.year, 4); + const path = `csv/${year}_cuestionario_alumno.csv`; + const data = []; return Servicio.findAll({ include: [ @@ -20,18 +23,13 @@ const get = async (body) => { { model: Usuario }, ], }).then((res) => { - let data = []; - let csvString = ''; - let path = `csv/${year}_cuestionarios_alumno.csv`; - - for (let i = 0; i < res.length; i++) { + for (let i = 0; i < res.length; i++) data.push({ idServicio: res[i].idServicio, clavePrograma: res[i].Programa.clavePrograma, usuario: res[i].Usuario.usuario, nombre: res[i].Usuario.nombre, - idCuestionarioAlumno: - res[i].CuestionarioAlumno.idCuestionarioAlumno, + idCuestionarioAlumno: res[i].CuestionarioAlumno.idCuestionarioAlumno, sexo: res[i].CuestionarioAlumno.sexo, edad: res[i].CuestionarioAlumno.edad, servicioMedico: res[i].CuestionarioAlumno.servicioMedico, @@ -67,19 +65,16 @@ const get = async (body) => { p30: res[i].CuestionarioAlumno.p30, createdAt: res[i].CuestionarioAlumno.createdAt, }); - } try { fs.unlinkSync(path); - } catch (err) {} - csvString = convertArrayToCSV(data); - fs.appendFile(path, csvString, (err) => { - if (err) { - console.log(err); - throw new Error('hubo un problema al crear el archivo csv.'); - } + } catch (err) { + throw new Error(err); + } + fs.appendFile(path, convertArrayToCSV(data), (err) => { + if (err) throw new Error(err); }); return { - message: `Se creo/actualizo correctamente el csv del cuestionario de programa del año ${year}`, + message: `Se creo/actualizo correctamente el csv del cuestionario de alumno del año ${year}.`, }; }); }; diff --git a/server/controller/CuestionarioAlumno/nuevo.js b/server/controller/CuestionarioAlumno/nuevo.js index b70e11a..9af5e8b 100644 --- a/server/controller/CuestionarioAlumno/nuevo.js +++ b/server/controller/CuestionarioAlumno/nuevo.js @@ -3,31 +3,30 @@ const CuestionarioAlumno = require('../../db/tablas/CuestionarioAlumno'); const Servicio = require('../../db/tablas/Servicio'); const nuevo = async (body) => { - let idServicio = validar.validarId(body.idServicio); - - let sexo = body.sexo; - let edad = body.edad; - let servicioMedico = body.servicioMedico; - let p1 = body.p1; - let p2 = body.p2; - let p4 = body.p4; - let p6 = body.p6; - let p7 = body.p7; - let p9 = body.p9; - let p10 = body.p10; - let p11 = body.p11; - let p12 = body.p12; - let p13 = body.p13; - let p16 = body.p16; - let p18 = body.p18; - let p19 = body.p19; - let p20 = body.p20; - let p25 = body.p25; - let p26 = body.p26; - let p27 = body.p27; - let p28 = body.p28; - let p29 = body.p29; - let p30 = body.p30; + const idServicio = validar.validarId(body.idServicio); + const sexo = body.sexo; + const edad = body.edad; + const servicioMedico = body.servicioMedico; + const p1 = body.p1; + const p2 = body.p2; + const p4 = body.p4; + const p6 = body.p6; + const p7 = body.p7; + const p9 = body.p9; + const p10 = body.p10; + const p11 = body.p11; + const p12 = body.p12; + const p13 = body.p13; + const p16 = body.p16; + const p18 = body.p18; + const p19 = body.p19; + const p20 = body.p20; + const p25 = body.p25; + const p26 = body.p26; + const p27 = body.p27; + const p28 = body.p28; + const p29 = body.p29; + const p30 = body.p30; let p3 = ''; let p5 = ''; let p8 = ''; @@ -43,52 +42,42 @@ const nuevo = async (body) => { p3 += body.p3[i]; if (i < body.p3.length - 1) p3 += ','; } - for (let i = 0; i < body.p5.length; i++) { p5 += body.p5[i]; if (i < body.p5.length - 1) p5 += ','; } - for (let i = 0; i < body.p8.length; i++) { p8 += body.p8[i]; if (i < body.p8.length - 1) p8 += ','; } - for (let i = 0; i < body.p14.length; i++) { p14 += body.p14[i]; if (i < body.p14.length - 1) p14 += ','; } - for (let i = 0; i < body.p15.length; i++) { p15 += body.p15[i]; if (i < body.p15.length - 1) p15 += ','; } - for (let i = 0; i < body.p17.length; i++) { p17 += body.p17[i]; if (i < body.p17.length - 1) p17 += ','; } - for (let i = 0; i < body.p21.length; i++) { p21 += body.p21[i]; if (i < body.p21.length - 1) p21 += ','; } - for (let i = 0; i < body.p22.length; i++) { p22 += body.p22[i]; if (i < body.p22.length - 1) p22 += ','; } - for (let i = 0; i < body.p23.length; i++) { p23 += body.p23[i]; if (i < body.p23.length - 1) p23 += ','; } - for (let i = 0; i < body.p24.length; i++) { p24 += body.p24[i]; if (i < body.p24.length - 1) p24 += ','; } - return Servicio.findOne({ where: { idServicio } }) .then((res) => { if (!res) throw new Error('No existe este Servicio Social.'); @@ -154,18 +143,16 @@ const nuevo = async (body) => { throw new Error('Este Servicio Social fue cancelado.'); } }) - .then((res) => { - return Servicio.update( + .then((res) => + Servicio.update( { idCuestionarioAlumno: res.idCuestionarioAlumno }, { where: { idServicio } } - ); - }) - .then((res) => { - return validar.validarPreTermino(idServicio); - }) - .then((res) => { - return { message: `Se guardaron tus respuestas correctamente. ${res}` }; - }); + ) + ) + .then((res) => validar.validarPreTermino(idServicio)) + .then((res) => ({ + message: `Se guardaron tus respuestas correctamente. ${res}`, + })); }; module.exports = nuevo; diff --git a/server/controller/CuestionarioPrograma/get.js b/server/controller/CuestionarioPrograma/get.js index 8bc0cb4..d5deeb4 100644 --- a/server/controller/CuestionarioPrograma/get.js +++ b/server/controller/CuestionarioPrograma/get.js @@ -8,7 +8,9 @@ const Programa = require('../../db/tablas/Programa'); const Usuario = require('../../db/tablas/Usuario'); const get = async (body) => { - let year = validar.validarNumero(body.year, 4); + const year = validar.validarNumero(body.year, 4); + const path = `csv/${year}_cuestionario_programa.csv`; + const data = []; return Servicio.findAll({ include: [ @@ -20,10 +22,6 @@ const get = async (body) => { { model: Usuario }, ], }).then((res) => { - let data = []; - let csvString = ''; - let path = `csv/${year}_cuestionarios_programa.csv`; - for (let i = 0; i < res.length; i++) data.push({ idServicio: res[i].idServicio, @@ -44,16 +42,14 @@ const get = async (body) => { }); try { fs.unlinkSync(path); - } catch (err) {} - csvString = convertArrayToCSV(data); - fs.appendFile(path, csvString, (err) => { - if (err) { - console.log(err); - throw new Error('hubo un problema al crear el archivo csv.'); - } + } catch (err) { + throw new Error(err); + } + fs.appendFile(path, convertArrayToCSV(data), (err) => { + if (err) throw new Error(err); }); return { - message: `Se creo/actualizo correctamente el csv del cuestionario de programa del año ${year}`, + message: `Se creo/actualizo correctamente el csv del cuestionario de programa del año ${year}.`, }; }); }; diff --git a/server/controller/CuestionarioPrograma/nuevo.js b/server/controller/CuestionarioPrograma/nuevo.js index 281bf5e..4f47838 100644 --- a/server/controller/CuestionarioPrograma/nuevo.js +++ b/server/controller/CuestionarioPrograma/nuevo.js @@ -3,21 +3,20 @@ const CuestionarioPrograma = require('../../db/tablas/CuestionarioPrograma'); const Servicio = require('../../db/tablas/Servicio'); const nuevo = async (body) => { - let idServicio = validar.validarId(body.idServicio); - let actividad1 = body.actividad1; - let actividad2 = body.actividad2; - let actividad3 = body.actividad3; - let actividad4 = body.actividad4; - let actividad5 = body.actividad5; + const idServicio = validar.validarId(body.idServicio); + const actividad1 = body.actividad1; + const actividad2 = body.actividad2; + const actividad3 = body.actividad3; + const actividad4 = body.actividad4; + const actividad5 = body.actividad5; + const p6 = body.p6; + const p7 = body.p7; let retroalimentacion = ''; - let p6 = body.p6; - let p7 = body.p7; for (let i = 0; i < body.retroalimentacion.length; i++) { retroalimentacion += body.retroalimentacion[i]; if (i < body.retroalimentacion.length - 1) retroalimentacion += ','; } - return Servicio.findOne({ where: { idServicio } }) .then((res) => { if (!res) throw new Error('No existe este Servicio Social.'); @@ -59,18 +58,16 @@ const nuevo = async (body) => { throw new Error('Este Servicio Social fue cancelado.'); } }) - .then((res) => { - return Servicio.update( + .then((res) => + Servicio.update( { idCuestionarioPrograma: res.idCuestionarioPrograma }, { where: { idServicio } } - ); - }) - .then((res) => { - return validar.validarPreTermino(idServicio); - }) - .then((res) => { - return { message: `Se guradaron tus respuestas correctamente. ${res}` }; - }); + ) + ) + .then((res) => validar.validarPreTermino(idServicio)) + .then((res) => ({ + message: `Se guradaron tus respuestas correctamente. ${res}`, + })); }; module.exports = nuevo; diff --git a/server/controller/Programa/cargaMasiva.js b/server/controller/Programa/cargaMasiva.js index 287748d..647f0b7 100644 --- a/server/controller/Programa/cargaMasiva.js +++ b/server/controller/Programa/cargaMasiva.js @@ -20,7 +20,10 @@ const cargaMasiva = async (file) => { let usuario = ''; let clavePrograma = programas[i].clave; let acatlan = false; - let busquedaPrograma = {}; + let busquedaPrograma = { + where: { clavePrograma: programas[i].clave }, + include: [{ model: Usuario }], + }; mensaje += `Linea ${i + 2}\n`; try { @@ -55,21 +58,8 @@ const cargaMasiva = async (file) => { }); await gmail(correo.subject, usuario, correo.msj); } - if (clavePrograma.substr(4) === '-12/20-91') acatlan = true; - if (acatlan) { - busquedaPrograma = { - where: { - clavePrograma: programas[i].clave, - idUsuario: dataUsuario.idUsuario, - }, - include: [{ model: Usuario }], - }; - } else { - busquedaPrograma = { - where: { clavePrograma: programas[i].clave }, - include: [{ model: Usuario }], - }; - } + if (clavePrograma.substr(4, 7) === '-12/20-') acatlan = true; + if (acatlan) busquedaPrograma.where.idUsuario = dataUsuario.idUsuario; await Programa.findOne(busquedaPrograma).then(async (res) => { let dataPrograma = res; diff --git a/server/controller/Programa/programasAdmin.js b/server/controller/Programa/programasAdmin.js index 2f4613a..14d0a31 100644 --- a/server/controller/Programa/programasAdmin.js +++ b/server/controller/Programa/programasAdmin.js @@ -3,7 +3,7 @@ const Programa = require('../../db/tablas/Programa'); const Usuario = require('../../db/tablas/Usuario'); const programasAdmin = async (body) => { - let idUsuario = validar.validarId(body.idUsuario); + const idUsuario = validar.validarId(body.idUsuario); return Usuario.findOne({ where: { idUsuario }, diff --git a/server/controller/Programa/programasResponsable.js b/server/controller/Programa/programasResponsable.js index 6eebd78..a81ad02 100644 --- a/server/controller/Programa/programasResponsable.js +++ b/server/controller/Programa/programasResponsable.js @@ -3,7 +3,7 @@ const Programa = require('../../db/tablas/Programa'); const Usuario = require('../../db/tablas/Usuario'); const programasResponsable = async (body) => { - let idUsuario = validar.validarId(body.idUsuario); + const idUsuario = validar.validarId(body.idUsuario); return Usuario.findOne({ where: { idUsuario }, diff --git a/server/controller/Servicio/admin.js b/server/controller/Servicio/admin.js index f833722..9c1bcf7 100644 --- a/server/controller/Servicio/admin.js +++ b/server/controller/Servicio/admin.js @@ -7,7 +7,7 @@ const Status = require('../../db/tablas/Status'); const Programa = require('../../db/tablas/Programa'); const admin = async (body) => { - let idServicio = validar.validarId(body.idServicio); + const idServicio = validar.validarId(body.idServicio); return Servicio.findOne({ where: { idServicio }, @@ -19,51 +19,13 @@ const admin = async (body) => { ], }).then((res) => { if (!res) throw new Error('No existe este servicio social.'); - return { - idServicio: res.idServicio, - creditos: res.creditos, - correo: res.correo, - telefono: res.telefono, - direccion: res.direccion, - fechaInicio: res.fechaInicio, - fechaFin: res.fechaFin, - fechaNacimiento: res.fechaNacimiento, - cartaAceptacion: res.cartaAceptacion, - cartaTermino: res.cartaTermino, - informeGlobal: res.informeGlobal, - programaInterno: res.programaInterno, - profesor: res.profesor, - vistoBuenoAcatlan: res.vistoBuenoAcatlan, - createdAt: res.createdAt, - updatedAt: res.updatedAt, - idCuestionarioAlumno: res.idCuestionarioAlumno, - idCuestionarioPrograma: res.idCuestionarioPrograma, - Usuario: { - idUsuario: res.Usuario.idUsuario, - usuario: res.Usuario.usuario, - nombre: res.Usuario.nombre, - TipoUsuario: { - idTipoUsuario: res.Usuario.TipoUsuario.idTipoUsuario, - tipoUsuario: res.Usuario.TipoUsuario.tipoUsuario, - }, - }, - Carrera: { - idCarrera: res.Carrera.idCarrera, - carrera: res.Carrera.carrera, - }, - Status: { - idStatus: res.Status.idStatus, - status: res.Status.status, - }, - Programa: { - idPrograma: res.Programa.idPrograma, - institucion: res.Programa.institucion, - dependencia: res.Programa.dependencia, - programa: res.Programa.programa, - clavePrograma: res.Programa.clavePrograma, - acatlan: res.Programa.acatlan, - }, - }; + delete res.dataValues.Usuario.dataValues.password; + delete res.dataValues.Programa.dataValues.idUsuario; + delete res.dataValues.idUsuario; + delete res.dataValues.idCarrera; + delete res.dataValues.idStatus; + delete res.dataValues.idPrograma; + return res; }); }; diff --git a/server/controller/Servicio/alumno.js b/server/controller/Servicio/alumno.js index 9b08bec..c76c6b0 100644 --- a/server/controller/Servicio/alumno.js +++ b/server/controller/Servicio/alumno.js @@ -13,52 +13,26 @@ const alumno = async (body) => { .then((res) => { if (!res) throw new Error('No existe este usuario.'); if (res.idTipoUsuario !== 3) - throw new Error('No es un usuaior de tipo alumno.'); + throw new Error('No es un usuario de tipo alumno.'); return Servicio.findOne({ where: { idUsuario, idStatus: { [Op.not]: 10 } }, - include: [ - { model: Usuario }, - { model: Carrera }, - { model: Status }, - { model: Programa }, - ], + include: [{ model: Carrera }, { model: Status }, { model: Programa }], }); }) .then((res) => { if (!res) throw new Error('No existe este servicio social.'); - return { - idServicio: res.idServicio, - creditos: res.creditos, - correo: res.correo, - telefono: res.telefono, - direccion: res.direccion, - fechaInicio: res.fechaInicio, - fechaFin: res.fechaFin, - fechaNacimiento: res.fechaNacimiento, - informeGlobal: res.informeGlobal, - programaInterno: res.programaInterno, - profesor: res.profesor, - createdAt: res.createdAt, - updatedAt: res.updatedAt, - idCuestionarioAlumno: res.idCuestionarioAlumno, - Carrera: { - idCarrera: res.Carrera.idCarrera, - carrera: res.Carrera.carrera, - }, - Status: { - idStatus: res.Status.idStatus, - status: res.Status.status, - }, - Programa: { - idPrograma: res.Programa.idPrograma, - institucion: res.Programa.institucion, - dependencia: res.Programa.dependencia, - programa: res.Programa.programa, - clavePrograma: res.Programa.clavePrograma, - acatlan: res.Programa.acatlan, - activo: res.Programa.activo, - }, - }; + delete res.dataValues.idUsuario; + delete res.dataValues.idCarrera; + delete res.dataValues.idStatus; + delete res.dataValues.idPrograma; + delete res.dataValues.updatedAt; + delete res.dataValues.carpeta; + delete res.dataValues.cartaAceptacion; + delete res.dataValues.cartaTermino; + delete res.dataValues.vistoBuenoAcatlan; + delete res.dataValues.idCuestionarioPrograma; + delete res.dataValues.Programa.idUsuario; + return res; }); }; diff --git a/server/controller/Servicio/cancelar.js b/server/controller/Servicio/cancelar.js index 3830b84..d38b4f2 100644 --- a/server/controller/Servicio/cancelar.js +++ b/server/controller/Servicio/cancelar.js @@ -6,9 +6,10 @@ const Usuario = require('../../db/tablas/Usuario'); const Programa = require('../../db/tablas/Programa'); const cancelar = async (body) => { - let idServicio = validar.validarId(body.idServicio); - let mensaje = validar.validarAlfanumerico(body.mensaje, 'El mensaje', 800); + const idServicio = validar.validarId(body.idServicio); + const mensaje = validar.validarAlfanumerico(body.mensaje, 'El mensaje', 800); let correoResponsable = {}; + let correoAlumno = {}; let emailResponsable = ''; let idUsuario; @@ -27,10 +28,8 @@ const cancelar = async (body) => { throw new Error( 'Este Servicio Social ya fue finalizado, no se puede cancelar.' ); - - let correoAlumno = correos.canceladoAlumno(mensaje, res.Usuario.nombre); - idUsuario = res.idUsuario; + correoAlumno = correos.canceladoAlumno(mensaje, res.Usuario.nombre); correoResponsable = correos.canceladoResponsable( mensaje, res.Usuario.nombre @@ -38,25 +37,19 @@ const cancelar = async (body) => { emailResponsable = res.Programa.Usuario.usuario; return gmail(correoAlumno.subject, res.correo, correoAlumno.msj); }) - .then((res) => { - return gmail( - correoResponsable.subject, - emailResponsable, - correoResponsable.msj - ); - }) - .then((res) => { - return Usuario.update( + .then((res) => + gmail(correoResponsable.subject, emailResponsable, correoResponsable.msj) + ) + .then((res) => + Usuario.update( { activo: false, password: null }, { where: { idUsuario } } - ); - }) - .then((res) => { - return Servicio.update({ idStatus: 10 }, { where: { idServicio } }); - }) - .then((res) => { - return { message: 'Se cancelo correctamente este Servicio Social.' }; - }); + ) + ) + .then((res) => Servicio.update({ idStatus: 10 }, { where: { idServicio } })) + .then((res) => ({ + message: 'Se cancelo correctamente este Servicio Social.', + })); }; module.exports = cancelar; diff --git a/server/controller/Servicio/cartaAceptacion.js b/server/controller/Servicio/cartaAceptacion.js index 82fc3d1..9842a5e 100644 --- a/server/controller/Servicio/cartaAceptacion.js +++ b/server/controller/Servicio/cartaAceptacion.js @@ -3,7 +3,8 @@ const drive = require('../../helper/drive'); const Servicio = require('../../db/tablas/Servicio'); const cartaTermino = async (body, file) => { - let idServicio = validar.validarId(body.idServicio); + const idServicio = validar.validarId(body.idServicio); + const path = `./server/uploads/${validar.validar(file, 'El archivo', 1000)}`; return Servicio.findOne({ where: { idServicio }, @@ -14,12 +15,6 @@ const cartaTermino = async (body, file) => { 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_Aceptacion.pdf`, @@ -50,17 +45,15 @@ const cartaTermino = async (body, file) => { ); } }) - .then((res) => { - return Servicio.update( + .then((res) => + Servicio.update( { cartaAceptacion: res, idStatus: 1 }, { where: { idServicio } } - ); - }) - .then((res) => { - return { - message: `Se subio la Carta de Aceptación correctamente.`, - }; - }); + ) + ) + .then((res) => ({ + message: `Se subio la Carta de Aceptación correctamente.`, + })); }; module.exports = cartaTermino; diff --git a/server/controller/Servicio/cartaTermino.js b/server/controller/Servicio/cartaTermino.js index ba35541..aee1ca8 100644 --- a/server/controller/Servicio/cartaTermino.js +++ b/server/controller/Servicio/cartaTermino.js @@ -3,7 +3,8 @@ const drive = require('../../helper/drive'); const Servicio = require('../../db/tablas/Servicio'); const cartaTermino = async (body, file) => { - let idServicio = validar.validarId(body.idServicio); + const idServicio = validar.validarId(body.idServicio); + const path = `./server/uploads/${validar.validar(file, 'El archivo', 1000)}`; return Servicio.findOne({ where: { idServicio }, @@ -14,12 +15,6 @@ const cartaTermino = async (body, file) => { switch (res.idStatus) { case 4: case 8: - let path = `./server/uploads/${validar.validar( - file, - 'El archivo', - 1000 - )}`; - return drive.uploadFile( path, `Carta_Termino.pdf`, @@ -49,15 +44,13 @@ const cartaTermino = async (body, file) => { ); } }) - .then((res) => { - return Servicio.update({ cartaTermino: res }, { where: { idServicio } }); - }) - .then((res) => { - return validar.validarPreTermino(idServicio); - }) - .then((res) => { - return { message: `Se subio la Carta de Termino correctamente. ${res}` }; - }); + .then((res) => + Servicio.update({ cartaTermino: res }, { where: { idServicio } }) + ) + .then((res) => validar.validarPreTermino(idServicio)) + .then((res) => ({ + message: `Se subio la Carta de Termino correctamente. ${res}`, + })); }; module.exports = cartaTermino; diff --git a/server/controller/Servicio/informeGlobal.js b/server/controller/Servicio/informeGlobal.js index 3b32398..1c9fe53 100644 --- a/server/controller/Servicio/informeGlobal.js +++ b/server/controller/Servicio/informeGlobal.js @@ -3,7 +3,8 @@ const drive = require('../../helper/drive'); const Servicio = require('../../db/tablas/Servicio'); const informeGlobal = async (body, file) => { - let idServicio = validar.validarId(body.idServicio); + const idServicio = validar.validarId(body.idServicio); + const path = `./server/uploads/${validar.validar(file, 'El archivo', 1000)}`; return Servicio.findOne({ where: { idServicio }, @@ -14,12 +15,6 @@ const informeGlobal = async (body, file) => { switch (res.idStatus) { case 4: case 9: - let path = `./server/uploads/${validar.validar( - file, - 'El archivo', - 1000 - )}`; - return drive.uploadFile( path, `Informe_Global.pdf`, @@ -49,18 +44,13 @@ const informeGlobal = async (body, file) => { ); } }) - .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}` }; - }); + .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; diff --git a/server/controller/Servicio/liberacion.js b/server/controller/Servicio/liberacion.js index 1121ee1..e4388d6 100644 --- a/server/controller/Servicio/liberacion.js +++ b/server/controller/Servicio/liberacion.js @@ -6,7 +6,9 @@ const Usuario = require('../../db/tablas/Usuario'); const Programa = require('../../db/tablas/Programa'); const liberacion = async (body) => { - let idServicio = validar.validarId(body.idServicio); + const idServicio = validar.validarId(body.idServicio); + const update = { idStatus: 6 }; + let correo = {}; return Servicio.findOne({ where: { idServicio }, @@ -14,16 +16,14 @@ const liberacion = async (body) => { }) .then(async (res) => { if (!res) throw new Error('No existe este Servicio Social.'); - if (res.Programa.acatlan && !body.vistoBuenoAcatlan) throw new Error( - 'El programa de este Servicio Solcial es Acatlán Contigo y no se envio la variable validando este servicio.' + 'El programa de este Servicio Social es Acatlán Contigo y no se envio la variable validando este servicio.' ); - switch (res.idStatus) { case 5: - let correo = correos.terminoValidado(res.Usuario.nombre); - + correo = correos.terminoValidado(res.Usuario.nombre); + if (body.vistoBuenoAcatlan) update.vistoBuenoAcatlan = true; return gmail(correo.subject, res.correo, correo.msj); case 1: case 2: @@ -46,18 +46,11 @@ const liberacion = async (body) => { throw new Error('Este Servicio Social esta cancelado.'); } }) - .then((res) => { - let update = { idStatus: 6 }; - - if (body.vistoBuenoAcatlan) update.vistoBuenoAcatlan = true; - return Servicio.update(update, { where: { idServicio } }); - }) - .then((res) => { - return { - message: - 'Se cambio de estatus correctamente y se envio un correo al alumno informandole de su liberación.', - }; - }); + .then((res) => Servicio.update(update, { 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/Servicio/nuevo.js b/server/controller/Servicio/nuevo.js index 7c2da8b..bc2cfac 100644 --- a/server/controller/Servicio/nuevo.js +++ b/server/controller/Servicio/nuevo.js @@ -7,26 +7,26 @@ const Carrera = require('../../db/tablas/Carrera'); const validar = require('../../helper/validar'); const nuevo = async (body, file) => { - let idUsuario = validar.validarId(body.idUsuario); - let idPrograma = validar.validarId(body.idPrograma); - let idCarrera = validar.validarId(body.idCarrera); - let numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta); - let creditos = validar.validarNumero(body.creditos); - let correo = validar.validarCorreo(body.correo); - let fechaInicio = validar.validarFecha(body.fechaInicio); - let fechaFin = validar.validarFecha(body.fechaFin); - let path = `./server/uploads/${validar.validar(file, 'El archivo', 1000)}`; - let carpeta = ''; - let programaInterno = body.programaInterno + const idUsuario = validar.validarId(body.idUsuario); + const idPrograma = validar.validarId(body.idPrograma); + const idCarrera = validar.validarId(body.idCarrera); + const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta); + const creditos = validar.validarNumero(body.creditos); + const correo = validar.validarCorreo(body.correo); + const fechaInicio = validar.validarFecha(body.fechaInicio); + const fechaFin = validar.validarFecha(body.fechaFin); + const path = `./server/uploads/${validar.validar(file, 'El archivo', 1000)}`; + const programaInterno = body.programaInterno ? validar.validarTexto( body.programaInterno, 'El texto programa interno.', 80 ) : ''; - let profesor = body.profesor + const profesor = body.profesor ? validar.validarTexto(body.profesor, 'El texto de profesor.', 50) : ''; + let carpeta = ''; return Usuario.findOne({ where: { idUsuario }, @@ -61,8 +61,8 @@ const nuevo = async (body, file) => { carpeta ); }) - .then((res) => { - return Servicio.create({ + .then((res) => + Servicio.create({ idUsuario, idPrograma, idCarrera, @@ -74,13 +74,11 @@ const nuevo = async (body, file) => { cartaAceptacion: res, profesor, programaInterno, - }); - }) - .then((res) => { - return { - message: `Se Pre-Registro correctamente al alumno.`, - }; - }); + }) + ) + .then((res) => ({ + message: `Se Pre-Registro correctamente al alumno.`, + })); }; module.exports = nuevo; diff --git a/server/controller/Servicio/rechazarAceptacion.js b/server/controller/Servicio/rechazarAceptacion.js index 7280879..363852e 100644 --- a/server/controller/Servicio/rechazarAceptacion.js +++ b/server/controller/Servicio/rechazarAceptacion.js @@ -6,9 +6,10 @@ const Usuario = require('../../db/tablas/Usuario'); const Programa = require('../../db/tablas/Programa'); const cancelar = async (body) => { - let idServicio = validar.validarId(body.idServicio); - let mensaje = validar.validarAlfanumerico(body.mensaje, 'El mensaje', 800); + const idServicio = validar.validarId(body.idServicio); + const mensaje = validar.validarAlfanumerico(body.mensaje, 'El mensaje', 800); let correoResponsable = {}; + let correoAlumno = {}; let emailResponsable = ''; return Servicio.findOne({ @@ -20,14 +21,12 @@ const cancelar = async (body) => { }) .then((res) => { if (!res) throw new Error('No existe este Servicio Social.'); - switch (res.idStatus) { case 1: - let correoAlumno = correos.preRegistroRechazadoAlumno( + correoAlumno = correos.preRegistroRechazadoAlumno( mensaje, res.Usuario.nombre ); - correoResponsable = correos.preRegistroRechazadoResponsable( mensaje, res.Usuario.nombre @@ -53,22 +52,18 @@ const cancelar = async (body) => { throw new Error('Este Servicio Social fue cancelado.'); } }) - .then((res) => { - return gmail( - correoResponsable.subject, - emailResponsable, - correoResponsable.msj - ); - }) - .then((res) => { - return Servicio.update( - { idStatus: 7, cartaAceptacion: '' }, + .then((res) => + gmail(correoResponsable.subject, emailResponsable, correoResponsable.msj) + ) + .then((res) => + Servicio.update( + { idStatus: 7, cartaAceptacion: null }, { where: { idServicio } } - ); - }) - .then((res) => { - return { message: 'Se rechazo correctamente la Carta de Aceptación.' }; - }); + ) + ) + .then((res) => ({ + message: 'Se rechazo correctamente la Carta de Aceptación.', + })); }; module.exports = cancelar; diff --git a/server/controller/Servicio/rechazarInforme.js b/server/controller/Servicio/rechazarInforme.js index 58054da..470fa3f 100644 --- a/server/controller/Servicio/rechazarInforme.js +++ b/server/controller/Servicio/rechazarInforme.js @@ -6,9 +6,10 @@ const Usuario = require('../../db/tablas/Usuario'); const Programa = require('../../db/tablas/Programa'); const cancelar = async (body) => { - let idServicio = validar.validarId(body.idServicio); - let mensaje = validar.validarAlfanumerico(body.mensaje, 'El mensaje', 800); + const idServicio = validar.validarId(body.idServicio); + const mensaje = validar.validarAlfanumerico(body.mensaje, 'El mensaje', 800); let correoResponsable = {}; + let correoAlumno = {}; let emailResponsable = ''; return Servicio.findOne({ @@ -22,11 +23,10 @@ const cancelar = async (body) => { if (!res) throw new Error('No existe este Servicio Social.'); switch (res.idStatus) { case 5: - let correoAlumno = correos.terminoRechazadoAlumno( + correoAlumno = correos.terminoRechazadoAlumno( mensaje, res.Usuario.nombre ); - correoResponsable = correos.terminoRechazadoResponsable( mensaje, res.Usuario.nombre @@ -53,22 +53,18 @@ const cancelar = async (body) => { throw new Error('Este Servicio Social fue cancelado.'); } }) - .then((res) => { - return gmail( - correoResponsable.subject, - emailResponsable, - correoResponsable.msj - ); - }) - .then((res) => { - return Servicio.update( - { idStatus: 9, informeGlobal: "" }, + .then((res) => + gmail(correoResponsable.subject, emailResponsable, correoResponsable.msj) + ) + .then((res) => + Servicio.update( + { idStatus: 9, informeGlobal: null }, { where: { idServicio } } - ); - }) - .then((res) => { - return { message: 'Se rechazo correctamente el Informe Global.' }; - }); + ) + ) + .then((res) => ({ + message: 'Se rechazo correctamente el Informe Global.', + })); }; module.exports = cancelar; diff --git a/server/controller/Servicio/rechazarTermino.js b/server/controller/Servicio/rechazarTermino.js index cc7cf44..43e37a4 100644 --- a/server/controller/Servicio/rechazarTermino.js +++ b/server/controller/Servicio/rechazarTermino.js @@ -6,9 +6,10 @@ const Usuario = require('../../db/tablas/Usuario'); const Programa = require('../../db/tablas/Programa'); const cancelar = async (body) => { - let idServicio = validar.validarId(body.idServicio); - let mensaje = validar.validarAlfanumerico(body.mensaje, 'El mensaje', 800); + const idServicio = validar.validarId(body.idServicio); + const mensaje = validar.validarAlfanumerico(body.mensaje, 'El mensaje', 800); let correoResponsable = {}; + let correoAlumno = {}; let emailResponsable = ''; return Servicio.findOne({ @@ -22,11 +23,10 @@ const cancelar = async (body) => { if (!res) throw new Error('No existe este Servicio Social.'); switch (res.idStatus) { case 5: - let correoAlumno = correos.terminoRechazadoAlumno( + correoAlumno = correos.terminoRechazadoAlumno( mensaje, res.Usuario.nombre ); - correoResponsable = correos.terminoRechazadoResponsable( mensaje, res.Usuario.nombre @@ -53,22 +53,18 @@ const cancelar = async (body) => { throw new Error('Este Servicio Social fue cancelado.'); } }) - .then((res) => { - return gmail( - correoResponsable.subject, - emailResponsable, - correoResponsable.msj - ); - }) - .then((res) => { - return Servicio.update( - { idStatus: 8, cartaTermino: "" }, + .then((res) => + gmail(correoResponsable.subject, emailResponsable, correoResponsable.msj) + ) + .then((res) => + Servicio.update( + { idStatus: 8, cartaTermino: null }, { where: { idServicio } } - ); - }) - .then((res) => { - return { message: 'Se rechazo correctamente la Carta de Termino.' }; - }); + ) + ) + .then((res) => ({ + message: 'Se rechazo correctamente la Carta de Termino.', + })); }; module.exports = cancelar; diff --git a/server/controller/Servicio/registro.js b/server/controller/Servicio/registro.js index 367f110..add06ef 100644 --- a/server/controller/Servicio/registro.js +++ b/server/controller/Servicio/registro.js @@ -6,8 +6,8 @@ const Servicio = require('../../db/tablas/Servicio'); const Usuario = require('../../db/tablas/Usuario'); const registro = async (body) => { - let idServicio = validar.validarId(body.idServicio); - let password = ''; + const idServicio = validar.validarId(body.idServicio); + const password = encriptar.generarPassword(); let correo = {}; let idUsuario; @@ -20,7 +20,6 @@ const registro = async (body) => { switch (res.idStatus) { case 1: - password = encriptar.generarPassword(); correo = correos.preRegistro(password, res.Usuario.nombre); idUsuario = res.idUsuario; return gmail(correo.subject, res.correo, correo.msj); @@ -48,15 +47,11 @@ const registro = async (body) => { { where: { idUsuario } } ); }) - .then((res) => { - return Servicio.update({ idStatus: 2 }, { where: { idServicio } }); - }) - .then((res) => { - return { - message: - 'Se cambio de estatus correctamente y se envio un correo al alumno con sus credenciales.', - }; - }); + .then((res) => Servicio.update({ idStatus: 2 }, { where: { idServicio } })) + .then((res) => ({ + message: + 'Se cambio de estatus correctamente y se envio un correo al alumno con sus credenciales.', + })); }; module.exports = registro; diff --git a/server/controller/Servicio/registroValidado.js b/server/controller/Servicio/registroValidado.js index 6fbe05c..850cdf1 100644 --- a/server/controller/Servicio/registroValidado.js +++ b/server/controller/Servicio/registroValidado.js @@ -6,15 +6,16 @@ const Usuario = require('../../db/tablas/Usuario'); const Programa = require('../../db/tablas/Programa'); const registroValidado = async (body) => { - let idServicio = validar.validarId(body.idServicio); - let fechaNacimiento = validar.validarFecha(body.fechaNacimiento); - let telefono = validar.validarNumero(body.telefono, 15); - let direccion = validar.validarAlfanumerico( + const idServicio = validar.validarId(body.idServicio); + const fechaNacimiento = validar.validarFecha(body.fechaNacimiento); + const telefono = validar.validarNumero(body.telefono, 15); + const direccion = validar.validarAlfanumerico( body.direccion, 'La dirección', 200 ); let correoResponsable = {}; + let correoAlumno = {}; let emailResponsable = ''; return Servicio.findOne({ @@ -26,11 +27,9 @@ const registroValidado = async (body) => { }) .then((res) => { if (!res) throw new Error('No existe este Servicio Social.'); - switch (res.idStatus) { case 2: - let correoAlumno = correos.registroValidadoAlumno(res.Usuario.nombre); - + correoAlumno = correos.registroValidadoAlumno(res.Usuario.nombre); correoResponsable = correos.registroValidadoResponsable( res.Usuario.nombre ); @@ -63,26 +62,21 @@ const registroValidado = async (body) => { ); } }) - .then((res) => { - return gmail( - correoResponsable.subject, - emailResponsable, - correoResponsable.msj - ); - }) - .then((res) => { - return Servicio.update( + .then((res) => + gmail(correoResponsable.subject, emailResponsable, correoResponsable.msj) + ) + .then((res) => + Servicio.update( + // Producción // { idStatus: 3, direccion, telefono, fechaNacimiento }, + // Pruebas { idStatus: 4, direccion, telefono, fechaNacimiento }, { where: { idServicio } } - ); - }) - .then((res) => { - return { - message: - 'Haz terminado el registro de tu Servicio Social correctamente.', - }; - }); + ) + ) + .then((res) => ({ + message: 'Haz terminado el registro de tu Servicio Social correctamente.', + })); }; module.exports = registroValidado; diff --git a/server/controller/Servicio/serviciosAdmin.js b/server/controller/Servicio/serviciosAdmin.js index 92e2b39..6001940 100644 --- a/server/controller/Servicio/serviciosAdmin.js +++ b/server/controller/Servicio/serviciosAdmin.js @@ -7,17 +7,18 @@ const Status = require('../../db/tablas/Status'); const TipoUsuario = require('../../db/tablas/TipoUsuario'); const serviciosAdmin = async (body) => { - let pagina = validar.validarId(body.pagina); - let idStatus = body.idStatus ? validar.validarId(body.idStatus) : null; - let nombre = body.nombre + const pagina = validar.validarId(body.pagina); + const where = body.idStatus + ? { idStatus: validar.validarId(body.idStatus) } + : {}; + const nombre = body.nombre ? validar.validarTexto(body.nombre, 'El nombre', 60) : ''; - let numeroCuenta = body.numeroCuenta + const numeroCuenta = body.numeroCuenta ? validar.validarNumeroCuenta(body.numeroCuenta) : ''; - let where = {}; + const data = []; - if (idStatus) where.idStatus = idStatus; return Servicio.findAll({ where, include: [ @@ -32,31 +33,22 @@ const serviciosAdmin = async (body) => { { model: Carrera }, { model: Status }, ], + order: [['updatedAt', 'DESC']], }).then((res) => { - let data = []; - for (let i = pagina * 25 - 25; i < res.length && i < pagina * 25; i++) data.push({ idServicio: res[i].idServicio, fechaInicio: res[i].fechaInicio, fechaFin: res[i].fechaFin, + createdAt: res[i].createdAt, Usuario: { idUsuario: res[i].Usuario.idUsuario, usuario: res[i].Usuario.usuario, nombre: res[i].Usuario.nombre, - TipoUsuario: { - idTipoUsuario: res[i].Usuario.TipoUsuario.idTipoUsuario, - tipoUsuario: res[i].Usuario.TipoUsuario.tipoUsuario, - }, - }, - Carrera: { - idCarrera: res[i].Carrera.idCarrera, - carrera: res[i].Carrera.carrera, - }, - Status: { - idStatus: res[i].Status.idStatus, - status: res[i].Status.status, + TipoUsuario: res[i].Usuario.TipoUsuario, }, + Carrera: res[i].Carrera, + Status: res[i].Status, }); return { registros: res.length, diff --git a/server/controller/Servicio/serviciosResponsable.js b/server/controller/Servicio/serviciosResponsable.js index 864b301..18e91d8 100644 --- a/server/controller/Servicio/serviciosResponsable.js +++ b/server/controller/Servicio/serviciosResponsable.js @@ -8,18 +8,20 @@ const TipoUsuario = require('../../db/tablas/TipoUsuario'); const Programa = require('../../db/tablas/Programa'); const serviciosResponsable = async (body) => { - let pagina = validar.validarId(body.pagina); - let idUsuario = validar.validarId(body.idUsuario); - let idStatus = body.idStatus ? validar.validarId(body.idStatus) : null; - let nombre = body.nombre + const pagina = validar.validarId(body.pagina); + const idUsuario = validar.validarId(body.idUsuario); + const where = body.idStatus + ? { idStatus: validar.validarId(body.idStatus) } + : {}; + + const nombre = body.nombre ? validar.validarTexto(body.nombre, 'El nombre', 60) : ''; - let numeroCuenta = body.numeroCuenta + const numeroCuenta = body.numeroCuenta ? validar.validarNumeroCuenta(body.numeroCuenta) : ''; - let where = { [Op.and]: [{ idStatus: { [Op.ne]: 10 } }] }; + const data = []; - if (idStatus) where[Op.and].push({ idStatus }); return Usuario.findOne({ where: { idUsuario } }) .then((res) => { if (!res) throw new Error('No existe este usuario.'); @@ -40,11 +42,10 @@ const serviciosResponsable = async (body) => { { model: Carrera }, { model: Status }, ], + order: [['updatedAt', 'DESC']], }); }) .then((res) => { - let data = []; - for (let i = pagina * 25 - 25; i < res.length && i < pagina * 25; i++) data.push({ idServicio: res[i].idServicio, @@ -56,19 +57,10 @@ const serviciosResponsable = async (body) => { idUsuario: res[i].Usuario.idUsuario, usuario: res[i].Usuario.usuario, nombre: res[i].Usuario.nombre, - TipoUsuario: { - idTipoUsuario: res[i].Usuario.TipoUsuario.idTipoUsuario, - tipoUsuario: res[i].Usuario.TipoUsuario.tipoUsuario, - }, - }, - Carrera: { - idCarrera: res[i].Carrera.idCarrera, - carrera: res[i].Carrera.carrera, - }, - Status: { - idStatus: res[i].Status.idStatus, - status: res[i].Status.status, + TipoUsuario: res[i].Usuario.TipoUsuario, }, + Carrera: res[i].Carrera, + Status: res[i].Status, }); return { registros: res.length, diff --git a/server/controller/Servicio/update.js b/server/controller/Servicio/update.js index 5274607..53357b2 100644 --- a/server/controller/Servicio/update.js +++ b/server/controller/Servicio/update.js @@ -1,17 +1,14 @@ const drive = require('../../helper/drive'); const validar = require('../../helper/validar'); const Servicio = require('../../db/tablas/Servicio'); -const Usuario = require('../../db/tablas/Usuario'); const update = async (body, files) => { - let idServicio = validar.validarId(body.idServicio); - let dataUpdate = {}; - console.log('hola2'); + const idServicio = validar.validarId(body.idServicio); + const dataUpdate = {}; return Servicio.findOne({ where: { idServicio } }) .then(async (res) => { if (!res) throw new Error('Este Servicio Social no existe en la db.'); - try { if (files['cartaAceptacion'][0].filename) dataUpdate.cartaAceptacion = await drive.uploadFile( @@ -54,18 +51,15 @@ const update = async (body, files) => { ); if (body.telefono) dataUpdate.telefono = validar.validarNumero(body.telefono, 15); - if (validar.isObjectEmpty(dataUpdate)) throw new Error( 'No se envio nada para actualizar este Servicio Social' ); return Servicio.update(dataUpdate, { where: { idServicio } }); }) - .then((res) => { - return { - message: 'Se guadro correctamente los cambios de este servicio.', - }; - }); + .then((res) => ({ + message: 'Se guadro correctamente los cambios de este servicio.', + })); }; module.exports = update; diff --git a/server/controller/Status/get.js b/server/controller/Status/get.js index b3e3c8c..a096322 100644 --- a/server/controller/Status/get.js +++ b/server/controller/Status/get.js @@ -1,9 +1,5 @@ const Status = require('../../db/tablas/Status'); -const get = () => { - return Status.findAll().then((res) => { - return res; - }); -}; +const get = () => Status.findAll(); module.exports = get; diff --git a/server/controller/Usuario/escolares.js b/server/controller/Usuario/escolares.js index 8cf80b3..5644a25 100644 --- a/server/controller/Usuario/escolares.js +++ b/server/controller/Usuario/escolares.js @@ -5,7 +5,7 @@ const Usuario = require('../../db/tablas/Usuario'); const Carrera = require('../../db/tablas/Carrera'); const escolares = async (body) => { - let numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta); + const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta); let alumno; return axios({ @@ -14,16 +14,14 @@ const escolares = async (body) => { data: `${process.env.ESCOLARES_PASS}`, }) .then((res) => { - let data = res.data; - - if (!data.nombre || !data.carrconst || !data.avance) + if (!res.data.nombre || !res.data.carrconst || !res.data.avance) throw new Error( 'El alumno no cumple con los requicitos para realizar el Servicio Social. Si cree que esto es erroneo comunicate con COESI.' ); alumno = { - nombre: data.nombre.trim(), - creditos: data.avance, - carrera: data.carrconst.trim(), + nombre: res.data.nombre.trim(), + creditos: res.data.avance, + carrera: res.data.carrconst.trim(), }; return Carrera.findOne({ where: { carrera: alumno.carrera } }); }) @@ -45,9 +43,7 @@ const escolares = async (body) => { }); return res; }) - .then((res) => { - return { ...alumno, idUsuario: res.idUsuario }; - }); + .then((res) => ({ ...alumno, idUsuario: res.idUsuario })); }; module.exports = escolares; diff --git a/server/controller/Usuario/login.js b/server/controller/Usuario/login.js index cf6f444..3627937 100644 --- a/server/controller/Usuario/login.js +++ b/server/controller/Usuario/login.js @@ -5,28 +5,28 @@ const Usuario = require('../../db/tablas/Usuario'); const TipoUsuario = require('../../db/tablas/TipoUsuario'); const login = async (body) => { - let usuario = validar.validar(body.usuario, 'El usuario', 60); - let password = validar.validarAlfanumerico(body.password, 'El password', 20); + const usuario = validar.validar(body.usuario, 'El usuario', 60); + const password = validar.validarAlfanumerico( + body.password, + 'El password', + 20 + ); return Usuario.findOne({ - where: { usuario, activo: true }, + where: { usuario }, include: [{ model: TipoUsuario }], }).then((res) => { if (!res) throw new Error('No existe este usuario.'); + if (!res.activo) throw new Error('Este usuario no esta activo.'); if (encriptar.comparar(password, res.password)) { + delete res.dataValues.password; + delete res.dataValues.activo; return { - Usuario: { - idUsuario: res.idUsuario, - usuario: res.usuario, - nombre: res.nombre, - TipoUsuario: { - idTipoUsuario: res.TipoUsuario.idTipoUsuario, - tipoUsuario: res.TipoUsuario.tipoUsuario, - }, - }, + Usuario: res, token: crearToken(res.idUsuario), }; } + throw new Error('La contraseña es incorrecta'); }); }; diff --git a/server/controller/Usuario/newPasswordAlumno.js b/server/controller/Usuario/newPasswordAlumno.js index 9c9b94a..ddf4088 100644 --- a/server/controller/Usuario/newPasswordAlumno.js +++ b/server/controller/Usuario/newPasswordAlumno.js @@ -6,9 +6,10 @@ const Usuario = require('../../db/tablas/Usuario'); const Servicio = require('../../db/tablas/Servicio'); const newPasswordAlumno = async (body) => { - let idServicio = await validar.validarId(body.idServicio); - let pasword = encriptar.generarPassword(); + const idServicio = validar.validarId(body.idServicio); + const password = encriptar.generarPassword(); let idUsuario; + let correo = {}; return Servicio.findOne({ where: { idServicio }, @@ -18,23 +19,19 @@ const newPasswordAlumno = async (body) => { if (!res) throw new Error('No existe este Servicio Social.'); if (res.Usuario.idTipoUsuario != 3) throw new Error('Este usuario no es de tipo alumno.'); - - let correo = correos.preRegistro(pasword, res.Usuario.nombre); - + correo = correos.preRegistro(password, res.Usuario.nombre); idUsuario = res.idUsuario; return gmail(correo.subject, res.correo, correo.msj); }) - .then((res) => { - return Usuario.update( - { pasword: encriptar.encriptar(pasword) }, + .then((res) => + Usuario.update( + { password: encriptar.encriptar(password) }, { where: { idUsuario } } - ); - }) - .then((res) => { - return { - message: 'Se envio un correo con una contraseña nueva al alumno.', - }; - }); + ) + ) + .then((res) => ({ + message: 'Se envio un correo con una contraseña nueva al alumno.', + })); }; module.exports = newPasswordAlumno; diff --git a/server/controller/Usuario/newPasswordResponsable.js b/server/controller/Usuario/newPasswordResponsable.js index 329069c..45d193a 100644 --- a/server/controller/Usuario/newPasswordResponsable.js +++ b/server/controller/Usuario/newPasswordResponsable.js @@ -5,29 +5,27 @@ const validar = require('../../helper/validar'); const Usuario = require('../../db/tablas/Usuario'); const newPasswordResponsable = async (body) => { - let idUsuario = await validar.validarId(body.idUsuario); - let pasword = encriptar.generarPassword(); + const idUsuario = await validar.validarId(body.idUsuario); + const password = encriptar.generarPassword(); + let correo = {}; return Usuario.findOne({ where: { idUsuario } }) .then((res) => { if (!res) throw new Error('No existe este Usuario.'); - if (res.Usuario.idTipoUsuario != 2) - throw new Error('Este usuario no es de tipo alumno.'); - - let correo = correos.enviarSec(pasword, res.correo, res.nombre); - return gmail(correo.subject, res.correo, correo.msj); + if (res.idTipoUsuario != 2) + throw new Error('Este usuario no es de tipo responsable.'); + correo = correos.enviarSec(password, res.correo, res.nombre); + return gmail(correo.subject, res.usuario, correo.msj); }) - .then((res) => { - return Usuario.update( - { pasword: encriptar.encriptar(pasword) }, + .then((res) => + Usuario.update( + { password: encriptar.encriptar(password) }, { where: { idUsuario } } - ); - }) - .then((res) => { - return { - message: 'Se envio un correo con una contraseña nueva al responsable.', - }; - }); + ) + ) + .then((res) => ({ + message: 'Se envio un correo con una contraseña nueva al responsable.', + })); }; module.exports = newPasswordResponsable; diff --git a/server/controller/Usuario/responsable.js b/server/controller/Usuario/responsable.js index d081c7e..f1e0469 100644 --- a/server/controller/Usuario/responsable.js +++ b/server/controller/Usuario/responsable.js @@ -4,13 +4,14 @@ const Usuario = require('../../db/tablas/Usuario'); const TipoUsuario = require('../../db/tablas/TipoUsuario'); const responsable = async (body) => { - let pagina = validar.validarId(body.pagina); - let nombre = body.nombre + const pagina = validar.validarId(body.pagina); + const nombre = body.nombre ? validar.validarTexto(body.nombre, 'El nombre', 60) : ''; - let correo = body.correo + const correo = body.correo ? validar.validar(body.correo, 'El correo', 1000) : ''; + const data = []; return Usuario.findAll({ where: { @@ -20,19 +21,11 @@ const responsable = async (body) => { }, include: [{ model: TipoUsuario }], }).then((res) => { - let data = []; - - for (let i = pagina * 25 - 25; i < res.length && i < pagina * 25; i++) - data.push({ - idUsuario: res[i].idUsuario, - usuario: res[i].usuario, - nombre: res[i].nombre, - activo: res[i].activo, - TipoUsuario: { - idTipoUsuario: res[i].TipoUsuario.idTipoUsuario, - tipoUsuario: res[i].TipoUsuario.tipoUsuario, - }, - }); + for (let i = pagina * 25 - 25; i < res.length && i < pagina * 25; i++) { + delete res[i].dataValues.password; + delete res[i].dataValues.idTipoUsuario; + data.push(res[i]); + } return { registros: res.length, faltantes: res.length - data.length - (pagina - 1) * 25, diff --git a/server/controller/Usuario/responsableUpdate.js b/server/controller/Usuario/responsableUpdate.js index 016c098..cbc6535 100644 --- a/server/controller/Usuario/responsableUpdate.js +++ b/server/controller/Usuario/responsableUpdate.js @@ -3,8 +3,8 @@ const validar = require('../../helper/validar'); const Usuario = require('../../db/tablas/Usuario'); const responsableUpdate = async (body) => { - let idUsuario = validar.validarId(body.idUsuario); - let dataUpdate = {}; + const idUsuario = validar.validarId(body.idUsuario); + const dataUpdate = {}; return Usuario.findOne({ where: { idUsuario } }) .then(async (res) => { @@ -30,12 +30,10 @@ const responsableUpdate = async (body) => { throw new Error('No se a envio nada para actualizar.'); return Usuario.update(dataUpdate, { where: { idUsuario } }); }) - .then((res) => { - return { - message: - 'Se actualizó la información de este responsable de programas correctamente.', - }; - }); + .then((res) => ({ + message: + 'Se actualizó la información de este responsable de programas correctamente.', + })); }; module.exports = responsableUpdate; diff --git a/server/db/csv.js b/server/db/csv.js index b8f8cdd..b39d3d3 100644 --- a/server/db/csv.js +++ b/server/db/csv.js @@ -7,27 +7,15 @@ const Servicio = require('./tablas/Servicio'); const Usuario = require('./tablas/Usuario'); const guardar = async () => { - let idsProgramas = []; - let idsAlumnos = []; - let idsRegistros = []; - let responsables = await csv() - .fromFile('db/responsable.csv') - .then((res) => res); - let programas = await csv() - .fromFile('db/programa.csv') - .then((res) => res); - let alumnos = await csv() - .fromFile('db/alumno.csv') - .then((res) => res); - let registros = await csv() - .fromFile('db/registro.csv') - .then((res) => res); - let cuestionariosAlumno = await csv() - .fromFile('db/cuestionarioA.csv') - .then((res) => res); - let cuestionariosPrograma = await csv() - .fromFile('db/cuestionarioP.csv') - .then((res) => res); + const idsProgramas = []; + const idsAlumnos = []; + const idsRegistros = []; + const responsables = await csv().fromFile('db/responsable.csv'); + let programas = await csv().fromFile('db/programa.csv'); + let alumnos = await csv().fromFile('db/alumno.csv'); + let registros = await csv().fromFile('db/registro.csv'); + let cuestionariosAlumno = await csv().fromFile('db/cuestionarioA.csv'); + let cuestionariosPrograma = await csv().fromFile('db/cuestionarioP.csv'); for (let i = 0; i < responsables.length; i++) { await Usuario.create({ @@ -50,6 +38,7 @@ const guardar = async () => { clavePrograma: programas[j].clavePrograma, acatlan: responsables[i].acatlanContigo === 'true' ? true : false, activo: true, + // activo: false, idUsuario: res.dataValues.idUsuario, }) .then((res) => { diff --git a/server/routes/Servicio.js b/server/routes/Servicio.js index 6a960e4..a24e951 100644 --- a/server/routes/Servicio.js +++ b/server/routes/Servicio.js @@ -213,7 +213,6 @@ app.put( { name: 'informeGlobal', maxCount: 1 }, ]), (req, res) => { - console.log('hola'); return update(JSON.parse(req.body.data), req.files) .then((data) => { res.status(200).json(data);