From de3046936fd7c38070bb26e4ea5275f2e947ec1e Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Tue, 14 Jun 2022 18:50:40 -0500 Subject: [PATCH] comentarios oscar --- server/controller/Admin/validarTicket.js | 98 ++++++++++++------------ server/controller/Usuario/escolares.js | 7 +- server/controller/Usuario/login.js | 10 +-- 3 files changed, 58 insertions(+), 57 deletions(-) diff --git a/server/controller/Admin/validarTicket.js b/server/controller/Admin/validarTicket.js index a189d97..54d5e67 100644 --- a/server/controller/Admin/validarTicket.js +++ b/server/controller/Admin/validarTicket.js @@ -23,62 +23,66 @@ const validarTicket = async (body) => { let correo = {}; let email = ''; - return Inscripcion.findOne({ - where: { folio }, - }) - .then((res) => { - if (!res) throw new Error('Este folio no existe'); - idUsuario = res.idUsuario; - if (body.validacion == 1) { - return Inscripcion.findOne({ - where: { folio, validacion: 1 }, - }); - } + return ( + Inscripcion.findOne({ + where: { folio }, }) - .then((res) => { - if (res) throw new Error('Este folio ya fue validado'); - return Inscripcion.update( - { - validacion: body.validacion, - }, - { - where: { - folio, - cancelacion: 0, - }, + .then((res) => { + if (!res) throw new Error('Este folio no existe'); + idUsuario = res.idUsuario; + if (body.validacion == 1) { + return Inscripcion.findOne({ + where: { folio, validacion: 1 }, + }); } - ); - }) - .then((res) => { - if (body.validacion === 0) { - email = `${numeroCuenta}@pcpuma.acatlan.unam.mx`; - correoDeclinar = correoInscripciones(); - borrarInscripcion(numeroCuenta); - borrarRecibo(folio); - borrarDetalleServicio(numeroCuenta); + }) + .then((res) => { + if (res) throw new Error('Este folio ya fue validado'); return Inscripcion.update( - { motivo: body.motivo }, + { + validacion: body.validacion, + }, { where: { folio, + cancelacion: 0, }, } ); - } - }) - .then((res) => { - if (body.validacion === 1) - return { - message: '¡El ticket a sido validado de forma correcta!', - }; - else - return { - message: '¡El ticket a sido declinado', - }; - }) - .catch((err) => { - throw new Error('No fue posible validar el ticket. ' + err); - }); + }) + //el ticket ya fue validado + .then((res) => { + if (body.validacion === 0) { + email = `${numeroCuenta}@pcpuma.acatlan.unam.mx`; + correoDeclinar = correoInscripciones(); + borrarInscripcion(numeroCuenta); + borrarRecibo(folio); + borrarDetalleServicio(numeroCuenta); + return Inscripcion.update( + { motivo: body.motivo }, + { + where: { + folio, + }, + } + ); + } + }) + .then((res) => { + if (body.validacion === 1) { + //Insertar en AD + return { + message: '¡El ticket a sido validado de forma correcta!', + }; + } else + return { + message: '¡El ticket a sido declinado', + }; + }) + .catch((err) => { + throw new Error('No fue posible validar el ticket. ' + err); + }) + ); }; module.exports = validarTicket; diff --git a/server/controller/Usuario/escolares.js b/server/controller/Usuario/escolares.js index 2fc217d..1d9bc58 100644 --- a/server/controller/Usuario/escolares.js +++ b/server/controller/Usuario/escolares.js @@ -1,8 +1,5 @@ const { obtenerDatosUsr } = require('../../config/mariadb.conf'); -const { - validarNumeroCuenta, - validarNumeroEntero, -} = require('../../helper/validar'); +const { validarNumeroCuenta } = require('../../helper/validar'); const dbPath = '../../db/tablas'; const Usuario = require(`${dbPath}/Usuario`); @@ -17,7 +14,7 @@ const escolares = async (body) => { }).then((res) => { if (!res) { return obtenerDatosUsr(numeroCuenta).then(async (res) => { - return Usuario.create({ + await Usuario.create({ numeroCuenta, nombre: body.nombre, generacion: res.generacion, diff --git a/server/controller/Usuario/login.js b/server/controller/Usuario/login.js index 7e1ed2b..5b1eb16 100644 --- a/server/controller/Usuario/login.js +++ b/server/controller/Usuario/login.js @@ -5,16 +5,16 @@ const { crearToken } = require('../../middleware/autentificacion'); const Usuario = require('../../db/tablas/Usuario'); const login = async (body) => { - const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta); + const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta, 'número de cuenta', true); const data = { usuario: 'votacionesUser', password: 'poasfnr*/049_]', numeroCuenta: numeroCuenta, - passwordUser: body.passwordUser, - }; - + passwordUser: body.passwordUser + } + return axios - .post( + .post( `https://venus.acatlan.unam.mx/conexionEscolares_test/ingresarAlumno`, data )