From b1ff83b5760928ebea3d1a2eb88a51443177443e Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Wed, 4 May 2022 18:14:28 -0500 Subject: [PATCH 1/5] funcion innecesaria --- server/middleware/autentificacion.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/server/middleware/autentificacion.js b/server/middleware/autentificacion.js index b336d8d..48ea5d8 100644 --- a/server/middleware/autentificacion.js +++ b/server/middleware/autentificacion.js @@ -37,10 +37,4 @@ const crearTokenAdmin = (data) => { }); }; -const crearTokenOperador = (data) => { - return jwt.sign({ data }, process.env.KEY, { - expiresIn: Number(process.env.CADUCIDAD_TOKEN_OPERADOR), - }); -}; - module.exports = { verificaToken, crearToken, crearTokenAdmin }; From 10dc4a0e3c6daf9ee4826ca6abd054b0c716973e Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Fri, 6 May 2022 01:57:46 -0500 Subject: [PATCH 2/5] endponit de impresiones y tabla --- server/controller/Usuario/impresiones.js | 39 ++++++++++++++++ .../controller/Usuario/inscripcionUsuario.js | 16 +++---- server/db/tablas/Impresion.js | 46 +++++++++++++++++++ server/routes/Usuario.js | 10 ++++ server/uploads/reporte.csv | 2 - 5 files changed, 103 insertions(+), 10 deletions(-) create mode 100644 server/controller/Usuario/impresiones.js create mode 100644 server/db/tablas/Impresion.js diff --git a/server/controller/Usuario/impresiones.js b/server/controller/Usuario/impresiones.js new file mode 100644 index 0000000..ed105e6 --- /dev/null +++ b/server/controller/Usuario/impresiones.js @@ -0,0 +1,39 @@ +const moment = require('moment'); +const fs = require('fs'); +const { + validarNumeroEntero, + validarNumero, + validarNumeroCuenta, +} = require('../../helper/validar'); +const dbPath = '../../db/tablas'; +const Impresion = require('../../db/tablas/Impresion'); +const Inscripcion = require(`${dbPath}/Inscripcion`); + +const inscripcion = async (body, file) => { + const idUsuario = validarNumeroEntero(body.idUsuario, 'id Usuario', true); + const folio = validarNumero(body.folio, 'folio', true, 6); + const monto = validarNumero(body.monto, 'monto', true); + const fechaTicket = body.fechaTicket; + + return Inscripcion.findOne({ + where: { folio, cancelacion: 0 }, + }) + .then((res) => { + if (res) throw new Error('Este folio ya fue utilizado'); + return Impresion.create({ + idUsuario, + folio, + monto, + fechaTicket, + }); + }) + .then((res) => ({ + message: + 'Se ah registrado correctamente tu ticket, ahora puedes hacer uso del servicio de impresiones.', + })) + .catch((err) => { + throw new Error('No es posible realizar esta operación. ' + err); + }); +}; + +module.exports = inscripcion; diff --git a/server/controller/Usuario/inscripcionUsuario.js b/server/controller/Usuario/inscripcionUsuario.js index 5730fa1..3e119c1 100644 --- a/server/controller/Usuario/inscripcionUsuario.js +++ b/server/controller/Usuario/inscripcionUsuario.js @@ -68,14 +68,14 @@ const inscripcion = async (body, file) => { .then((res) => { if (file) fs.renameSync(file.path, file.path + '.' + file.mimetype.split('/')[1]); - usuarioInscrito(numeroCuenta, idArea); - agregarRecibo( - folio, - monto, - moment(fechaTicket).format('L'), - numeroCuenta - ); - agregarDetalleServicio(monto, numeroCuenta); + // usuarioInscrito(numeroCuenta, idArea); + // agregarRecibo( + // folio, + // monto, + // moment(fechaTicket).format('L'), + // numeroCuenta + // ); + // agregarDetalleServicio(monto, numeroCuenta); return gmail(correo.subject, email, correo.msj); }) .then((res) => ({ diff --git a/server/db/tablas/Impresion.js b/server/db/tablas/Impresion.js new file mode 100644 index 0000000..a44fa6e --- /dev/null +++ b/server/db/tablas/Impresion.js @@ -0,0 +1,46 @@ +const { DataTypes, Model } = require('sequelize'); +const sequelize = require('../../config/sequelize.conf'); +const Usuario = require('./Usuario'); + +class Impresion extends Model {} +Impresion.init( + { + idImpresion: { + type: DataTypes.INTEGER, + primaryKey: true, + allowNull: false, + unique: true, + autoIncrement: true, + }, + folio: { + type: DataTypes.STRING(10), + allowNull: true, + defaultValue: null, + }, + monto: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + }, + fechaTicket: { + type: DataTypes.DATE, + allowNull: true, + defaultValue: null, + }, + }, + { + sequelize, + modelName: 'Impresion', + tableName: 'impresion', + timestamps: false, + } +); + +Inscripcion.belongsTo(Usuario, { + foreignKey: { + name: 'idUsuario', + type: DataTypes.INTEGER, + allowNull: false, + }, +}); +module.exports = Impresion; diff --git a/server/routes/Usuario.js b/server/routes/Usuario.js index d953f7c..96983ec 100644 --- a/server/routes/Usuario.js +++ b/server/routes/Usuario.js @@ -45,4 +45,14 @@ app.post( } ); +app.post(`${route}/impresiones`, (req, res) => { + return impresiones(req.body) + .then((data) => { + res.status(200).json(data); + }) + .catch((err) => { + res.status(400).json({ message: err.message }); + }); +}); + module.exports = app; diff --git a/server/uploads/reporte.csv b/server/uploads/reporte.csv index ff9f850..e69de29 100644 --- a/server/uploads/reporte.csv +++ b/server/uploads/reporte.csv @@ -1,2 +0,0 @@ -numeroCuenta,idArea,folio,monto,hizoPago,fechaInscripcion,validacion,motivoDeclinacion -419085500,1,123345,12,true,03/22/2022,0,prueba From 21b37735b34de2f0b6c59fbbf96b0dc75b886496 Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Sat, 7 May 2022 02:25:05 -0500 Subject: [PATCH 3/5] correcciones a impresiones --- server/controller/Usuario/impresiones.js | 28 +++++++++++++----------- server/db/install.js | 7 ++++++ server/db/tablas/Impresion.js | 2 +- server/routes/Usuario.js | 21 +++++++++--------- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/server/controller/Usuario/impresiones.js b/server/controller/Usuario/impresiones.js index ed105e6..8dfbb17 100644 --- a/server/controller/Usuario/impresiones.js +++ b/server/controller/Usuario/impresiones.js @@ -1,15 +1,9 @@ -const moment = require('moment'); -const fs = require('fs'); -const { - validarNumeroEntero, - validarNumero, - validarNumeroCuenta, -} = require('../../helper/validar'); +const { validarNumeroEntero, validarNumero } = require('../../helper/validar'); const dbPath = '../../db/tablas'; -const Impresion = require('../../db/tablas/Impresion'); +const Impresion = require(`${dbPath}/Impresion`); const Inscripcion = require(`${dbPath}/Inscripcion`); -const inscripcion = async (body, file) => { +const impresiones = async (body) => { const idUsuario = validarNumeroEntero(body.idUsuario, 'id Usuario', true); const folio = validarNumero(body.folio, 'folio', true, 6); const monto = validarNumero(body.monto, 'monto', true); @@ -19,7 +13,16 @@ const inscripcion = async (body, file) => { where: { folio, cancelacion: 0 }, }) .then((res) => { - if (res) throw new Error('Este folio ya fue utilizado'); + if (res) + throw new Error('Este folio ya fue utilizado en alguna inscripción'); + return Impresion.findOne({ + where: { folio }, + }).then((res) => { + if (res) + throw new Error('Este folio ya fue utilizado para impresiones'); + }); + }) + .then((res) => { return Impresion.create({ idUsuario, folio, @@ -28,12 +31,11 @@ const inscripcion = async (body, file) => { }); }) .then((res) => ({ - message: - 'Se ah registrado correctamente tu ticket, ahora puedes hacer uso del servicio de impresiones.', + message: `Se a registrado correctamente tu ticket, se agregaron $${monto} a tu cuenta, ahora puedes hacer uso del servicio de impresiones.`, })) .catch((err) => { throw new Error('No es posible realizar esta operación. ' + err); }); }; -module.exports = inscripcion; +module.exports = impresiones; diff --git a/server/db/install.js b/server/db/install.js index aeb300e..47f11da 100644 --- a/server/db/install.js +++ b/server/db/install.js @@ -7,6 +7,7 @@ const Area = require('./tablas/Area'); const FechaInscripcion = require('./tablas/FechaInscripcion'); const Inscripcion = require('./tablas/Inscripcion'); const Admin = require('./tablas/Admin'); +const Impresion = require('./tablas/Impresion'); const drop = async () => { console.log('\nPaso 1) Desinstalando la db.'.bold.blue); @@ -28,6 +29,9 @@ const drop = async () => { await Carrera.drop(); console.log('La tabla Carrera se desinstalo correctamente.'.magenta); + + await Impresion.drop(); + console.log('La tabla Carrera se desinstalo correctamente.'.magenta); }; const sync = async () => { @@ -50,6 +54,9 @@ const sync = async () => { await Inscripcion.sync(); console.log('La tabla Inscripcion se instalo correctamente.'.magenta); + + await Impresion.sync(); + console.log('La tabla Inscripcion se instalo correctamente.'.magenta); }; const dataArea = async () => { diff --git a/server/db/tablas/Impresion.js b/server/db/tablas/Impresion.js index a44fa6e..b3f89da 100644 --- a/server/db/tablas/Impresion.js +++ b/server/db/tablas/Impresion.js @@ -36,7 +36,7 @@ Impresion.init( } ); -Inscripcion.belongsTo(Usuario, { +Impresion.belongsTo(Usuario, { foreignKey: { name: 'idUsuario', type: DataTypes.INTEGER, diff --git a/server/routes/Usuario.js b/server/routes/Usuario.js index 96983ec..56d9f45 100644 --- a/server/routes/Usuario.js +++ b/server/routes/Usuario.js @@ -9,6 +9,7 @@ const controllerPath = '../controller/Usuario'; const login = require(`${controllerPath}/login`); const inscripciones = require(`${controllerPath}/inscripciones`); const inscripcionUsuario = require(`${controllerPath}/inscripcionUsuario`); +const impresiones = require(`${controllerPath}/impresiones`); app.post(`${route}/login`, (req, res) => { return login(req.body) @@ -30,6 +31,16 @@ app.get(`${route}/inscripciones`, verificaToken, (req, res) => { }); }); +app.post(`${route}/impresiones`, (req, res) => { + return impresiones(req.body) + .then((data) => { + res.status(200).json(data); + }) + .catch((err) => { + res.status(400).json({ message: err.message }); + }); +}); + app.post( `${route}/inscripcionUsuario`, verificaToken, @@ -45,14 +56,4 @@ app.post( } ); -app.post(`${route}/impresiones`, (req, res) => { - return impresiones(req.body) - .then((data) => { - res.status(200).json(data); - }) - .catch((err) => { - res.status(400).json({ message: err.message }); - }); -}); - module.exports = app; From c3954b0110ed537b9c8ed4dad51ca7cc30493deb Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Tue, 10 May 2022 22:59:06 -0500 Subject: [PATCH 4/5] nuevosEndpoints --- server/controller/Admin/restarCredito.js | 31 ++++++++++ server/controller/Admin/ticketsImpresion.js | 21 +++++++ server/controller/Usuario/agregarCredito.js | 64 +++++++++++++++++++++ server/controller/Usuario/credito.js | 20 +++++++ server/controller/Usuario/impresiones.js | 41 ------------- server/db/install.js | 14 ++--- server/db/tablas/Usuario.js | 19 +++--- server/routes/Admin.js | 21 +++++++ server/routes/Usuario.js | 32 +++++++---- 9 files changed, 197 insertions(+), 66 deletions(-) create mode 100644 server/controller/Admin/restarCredito.js create mode 100644 server/controller/Admin/ticketsImpresion.js create mode 100644 server/controller/Usuario/agregarCredito.js create mode 100644 server/controller/Usuario/credito.js delete mode 100644 server/controller/Usuario/impresiones.js diff --git a/server/controller/Admin/restarCredito.js b/server/controller/Admin/restarCredito.js new file mode 100644 index 0000000..951f6dd --- /dev/null +++ b/server/controller/Admin/restarCredito.js @@ -0,0 +1,31 @@ +const dbPath = '../../db/tablas'; +const Usuario = require(`${dbPath}/Usuario`); +const Inscripcion = require(`${dbPath}/Inscripcion`); +const Impresion = require(`${dbPath}/Impresion`); +const { validarNumeroCuenta, validarNumero } = require('../../helper/validar'); + +const restarCredito = async (body) => { + const creditoUsado = validarNumero(body.monto, 'monto', true); + const numeroCuenta = validarNumeroCuenta( + body.numeroCuenta, + 'número de cuenta', + true + ); + + return Usuario.findOne({ + where: { numeroCuenta }, + }).then(() => { + if (!res) throw new Error('No encontramos este número de cuenta'); + return Usuario.update( + { + credito: res.credito - creditoUsado, + }, + { + where: { numeroCuenta }, + } + ).then((res) => ({ + message: '¡La transaccion se realizo con éxito!', + })); + }); +}; +module.exports = restarCredito; diff --git a/server/controller/Admin/ticketsImpresion.js b/server/controller/Admin/ticketsImpresion.js new file mode 100644 index 0000000..e387992 --- /dev/null +++ b/server/controller/Admin/ticketsImpresion.js @@ -0,0 +1,21 @@ +const { Op } = require('sequelize'); +const dbPath = '../../db/tablas'; +const Usuario = require(`${dbPath}/Usuario`); +const Impresion = require(`${dbPath}/Impresion`); +const { validarNumeroEntero } = require('../../helper/validar'); + +const ticketsImpresion = async (body) => { + const validacion = validarNumeroEntero(body.validacion, 'validacion', true); + return Impresion.findAll({ + where: { validacion }, + include: [ + { + model: Usuario, + where: { numeroCuenta: { [Op.like]: `%${body.numeroCuenta}%` } }, + attributes: ['idUsuario', 'numeroCuenta'], + }, + ], + }); +}; + +module.exports = ticketsImpresion; diff --git a/server/controller/Usuario/agregarCredito.js b/server/controller/Usuario/agregarCredito.js new file mode 100644 index 0000000..e691183 --- /dev/null +++ b/server/controller/Usuario/agregarCredito.js @@ -0,0 +1,64 @@ +const dbPath = '../../db/tablas'; +const Usuario = require(`${dbPath}/Usuario`); +const Inscripcion = require(`${dbPath}/Inscripcion`); +const Impresion = require(`${dbPath}/Impresion`); +const { + validarNumeroEntero, + validarNumeroCuenta, + validarNumero, +} = require('../../helper/validar'); + +const agregarCredito = async (body) => { + const fechaTicket = body.fechaTicket; + const idUsuario = validarNumeroEntero(body.idUsuario, 'usuario', true); + const monto = validarNumero(body.monto, 'monto', true); + const folio = validarNumero(body.folio, 'folio', true, 6); + const numeroCuenta = validarNumeroCuenta( + body.numeroCuenta, + 'número de cuenta', + true + ); + + return Inscripcion.findOne({ + where: { folio, cancelacion: 0 }, + }).then((res) => { + if (res) + throw new Error('Este folio ya fue utilizado en alguna inscripción'); + return Impresion.findOne({ + where: { folio }, + }) + .then((res) => { + if (res) + throw new Error('Este folio ya fue utilizado para impresiones'); + return Usuario.findOne({ where: { numeroCuenta } }).then(() => { + if (!res) + throw new Error( + 'Lo sentimos no pudimos encontrar este número cuenta' + ); + return Usuario.update( + { + credito: res.credito + creditoNuevo, + }, + { + where: { numeroCuenta }, + } + ).then((res) => { + return Impresion.create({ + idUsuario, + folio, + monto, + fechaTicket, + }); + }); + }); + }) + .then((res) => ({ + message: '¡Tu crédito se agrego correctamente!', + })) + .catch((err) => { + throw new Error('¡ No fue posible agregar tu crédito !. '); + }); + }); +}; + +module.exports = agregarCredito; diff --git a/server/controller/Usuario/credito.js b/server/controller/Usuario/credito.js new file mode 100644 index 0000000..bda771e --- /dev/null +++ b/server/controller/Usuario/credito.js @@ -0,0 +1,20 @@ +const dbPath = '../../db/tablas'; +const Usuario = require(`${dbPath}/Usuario`); +const { validarNumeroCuenta } = require('../../helper/validar'); + +const credito = async (body) => { + const numeroCuenta = validarNumeroCuenta( + body.numeroCuenta, + 'número de cuenta', + true + ); + return Usuario.findOne({ + where: { numeroCuenta }, + }).then(() => { + return Usuario.findOne({ + attributes: ['credito', 'nombre', 'numeroCuenta'], + }); + }); +}; + +module.exports = credito; diff --git a/server/controller/Usuario/impresiones.js b/server/controller/Usuario/impresiones.js deleted file mode 100644 index 8dfbb17..0000000 --- a/server/controller/Usuario/impresiones.js +++ /dev/null @@ -1,41 +0,0 @@ -const { validarNumeroEntero, validarNumero } = require('../../helper/validar'); -const dbPath = '../../db/tablas'; -const Impresion = require(`${dbPath}/Impresion`); -const Inscripcion = require(`${dbPath}/Inscripcion`); - -const impresiones = async (body) => { - const idUsuario = validarNumeroEntero(body.idUsuario, 'id Usuario', true); - const folio = validarNumero(body.folio, 'folio', true, 6); - const monto = validarNumero(body.monto, 'monto', true); - const fechaTicket = body.fechaTicket; - - return Inscripcion.findOne({ - where: { folio, cancelacion: 0 }, - }) - .then((res) => { - if (res) - throw new Error('Este folio ya fue utilizado en alguna inscripción'); - return Impresion.findOne({ - where: { folio }, - }).then((res) => { - if (res) - throw new Error('Este folio ya fue utilizado para impresiones'); - }); - }) - .then((res) => { - return Impresion.create({ - idUsuario, - folio, - monto, - fechaTicket, - }); - }) - .then((res) => ({ - message: `Se a registrado correctamente tu ticket, se agregaron $${monto} a tu cuenta, ahora puedes hacer uso del servicio de impresiones.`, - })) - .catch((err) => { - throw new Error('No es posible realizar esta operación. ' + err); - }); -}; - -module.exports = impresiones; diff --git a/server/db/install.js b/server/db/install.js index 47f11da..c55d141 100644 --- a/server/db/install.js +++ b/server/db/install.js @@ -24,14 +24,14 @@ const drop = async () => { await FechaInscripcion.drop(); console.log('La tabla FechaInscripcion se desinstalo correctamente.'.magenta); - await Usuario.drop(); - console.log('La tabla Usuario se desinstalo correctamente.'.magenta); - await Carrera.drop(); console.log('La tabla Carrera se desinstalo correctamente.'.magenta); await Impresion.drop(); - console.log('La tabla Carrera se desinstalo correctamente.'.magenta); + console.log('La tabla Impresion se desinstalo correctamente.'.magenta); + + await Usuario.drop(); + console.log('La tabla Usuario se desinstalo correctamente.'.magenta); }; const sync = async () => { @@ -46,6 +46,9 @@ const sync = async () => { await Usuario.sync(); console.log('La tabla Usuario se instalo correctamente.'.magenta); + await Impresion.sync(); + console.log('La tabla Impresion se instalo correctamente.'.magenta); + await Area.sync(); console.log('La tabla Area se instalo correctamente.'.magenta); @@ -54,9 +57,6 @@ const sync = async () => { await Inscripcion.sync(); console.log('La tabla Inscripcion se instalo correctamente.'.magenta); - - await Impresion.sync(); - console.log('La tabla Inscripcion se instalo correctamente.'.magenta); }; const dataArea = async () => { diff --git a/server/db/tablas/Usuario.js b/server/db/tablas/Usuario.js index e148432..202dc3c 100644 --- a/server/db/tablas/Usuario.js +++ b/server/db/tablas/Usuario.js @@ -34,6 +34,11 @@ Usuario.init( type: DataTypes.STRING(60), allowNull: false, }, + credito: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: 0, + }, }, { sequelize, @@ -43,12 +48,12 @@ Usuario.init( } ); -// Usuario.belongsTo(Carrera, { -// foreignKey: { -// name: 'idCarrera', -// type: DataTypes.INTEGER, -// allowNull: false, -// }, -// }); +Usuario.belongsTo(Carrera, { + foreignKey: { + name: 'idCarrera', + type: DataTypes.INTEGER, + allowNull: false, + }, +}); module.exports = Usuario; diff --git a/server/routes/Admin.js b/server/routes/Admin.js index c91ccd4..b5e18a0 100644 --- a/server/routes/Admin.js +++ b/server/routes/Admin.js @@ -13,6 +13,8 @@ const motivo = require(`${controllerPath}/motivo`); const validarSinTicket = require(`${controllerPath}/validarSinTicket`); const validarTicket = require(`${controllerPath}/validarTicket`); const reporte = require(`${controllerPath}/reporte`); +const restarCredito = require(`${controllerPath}/restarCredito`); +const ticketsImpresion = require(`${controllerPath}/ticketsImpresion`); app.post(`${route}/login`, (req, res) => { return login(req.body) @@ -107,4 +109,23 @@ app.get(`${route}/reporte`, verificaToken, (req, res) => { }); }); +app.put(`${route}/restar_credito`, (req, res) => { + return restarCredito(req.body) + .then((data) => { + res.status(200).json(data); + }) + .catch((err) => { + res.status(400).json({ message: err.message }); + }); +}); + +app.get(`${route}/tickets_impresion`, (req, res) => { + return ticketsImpresion(req.query) + .then((data) => { + res.status(200).json(data); + }) + .catch((err) => { + res.status(400).json({ message: err.message }); + }); +}); module.exports = app; diff --git a/server/routes/Usuario.js b/server/routes/Usuario.js index 56d9f45..b7ab269 100644 --- a/server/routes/Usuario.js +++ b/server/routes/Usuario.js @@ -9,7 +9,8 @@ const controllerPath = '../controller/Usuario'; const login = require(`${controllerPath}/login`); const inscripciones = require(`${controllerPath}/inscripciones`); const inscripcionUsuario = require(`${controllerPath}/inscripcionUsuario`); -const impresiones = require(`${controllerPath}/impresiones`); +const credito = require(`${controllerPath}/credito`); +const agregarCredito = require(`${controllerPath}/agregarCredito`); app.post(`${route}/login`, (req, res) => { return login(req.body) @@ -31,16 +32,6 @@ app.get(`${route}/inscripciones`, verificaToken, (req, res) => { }); }); -app.post(`${route}/impresiones`, (req, res) => { - return impresiones(req.body) - .then((data) => { - res.status(200).json(data); - }) - .catch((err) => { - res.status(400).json({ message: err.message }); - }); -}); - app.post( `${route}/inscripcionUsuario`, verificaToken, @@ -56,4 +47,23 @@ app.post( } ); +app.get(`${route}/credito`, (req, res) => { + return credito(req.query) + .then((data) => { + res.status(200).json(data); + }) + .catch((err) => { + res.status(400).json({ message: err.message }); + }); +}); + +app.put(`${route}/agregar_credito`, (req, res) => { + return agregarCredito(req.body) + .then((data) => { + res.status(200).json(data); + }) + .catch((err) => { + res.status(400).json({ message: err.message }); + }); +}); module.exports = app; From 63fc909859ac40398d8a29951be3d901a4d73494 Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Tue, 10 May 2022 23:36:28 -0500 Subject: [PATCH 5/5] separacion del credito --- server/controller/Admin/credito.js | 20 ++++++++++++++++++++ server/controller/Usuario/credito.js | 2 +- server/routes/Admin.js | 16 ++++++++++++++-- server/routes/Usuario.js | 23 ++++++++++++----------- 4 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 server/controller/Admin/credito.js diff --git a/server/controller/Admin/credito.js b/server/controller/Admin/credito.js new file mode 100644 index 0000000..bda771e --- /dev/null +++ b/server/controller/Admin/credito.js @@ -0,0 +1,20 @@ +const dbPath = '../../db/tablas'; +const Usuario = require(`${dbPath}/Usuario`); +const { validarNumeroCuenta } = require('../../helper/validar'); + +const credito = async (body) => { + const numeroCuenta = validarNumeroCuenta( + body.numeroCuenta, + 'número de cuenta', + true + ); + return Usuario.findOne({ + where: { numeroCuenta }, + }).then(() => { + return Usuario.findOne({ + attributes: ['credito', 'nombre', 'numeroCuenta'], + }); + }); +}; + +module.exports = credito; diff --git a/server/controller/Usuario/credito.js b/server/controller/Usuario/credito.js index bda771e..7ee7d19 100644 --- a/server/controller/Usuario/credito.js +++ b/server/controller/Usuario/credito.js @@ -12,7 +12,7 @@ const credito = async (body) => { where: { numeroCuenta }, }).then(() => { return Usuario.findOne({ - attributes: ['credito', 'nombre', 'numeroCuenta'], + attributes: ['credito'], }); }); }; diff --git a/server/routes/Admin.js b/server/routes/Admin.js index b5e18a0..dc38dae 100644 --- a/server/routes/Admin.js +++ b/server/routes/Admin.js @@ -15,6 +15,7 @@ const validarTicket = require(`${controllerPath}/validarTicket`); const reporte = require(`${controllerPath}/reporte`); const restarCredito = require(`${controllerPath}/restarCredito`); const ticketsImpresion = require(`${controllerPath}/ticketsImpresion`); +const credito = require(`${controllerPath}/credito`); app.post(`${route}/login`, (req, res) => { return login(req.body) @@ -109,7 +110,7 @@ app.get(`${route}/reporte`, verificaToken, (req, res) => { }); }); -app.put(`${route}/restar_credito`, (req, res) => { +app.put(`${route}/restar_credito`, verificaToken, (req, res) => { return restarCredito(req.body) .then((data) => { res.status(200).json(data); @@ -119,7 +120,7 @@ app.put(`${route}/restar_credito`, (req, res) => { }); }); -app.get(`${route}/tickets_impresion`, (req, res) => { +app.get(`${route}/tickets_impresion`, verificaToken, (req, res) => { return ticketsImpresion(req.query) .then((data) => { res.status(200).json(data); @@ -128,4 +129,15 @@ app.get(`${route}/tickets_impresion`, (req, res) => { res.status(400).json({ message: err.message }); }); }); + +app.get(`${route}/credito`, verificaToken, (req, res) => { + return credito(req.query) + .then((data) => { + res.status(200).json(data); + }) + .catch((err) => { + res.status(400).json({ message: err.message }); + }); +}); + module.exports = app; diff --git a/server/routes/Usuario.js b/server/routes/Usuario.js index b7ab269..4fe65e1 100644 --- a/server/routes/Usuario.js +++ b/server/routes/Usuario.js @@ -9,8 +9,8 @@ const controllerPath = '../controller/Usuario'; const login = require(`${controllerPath}/login`); const inscripciones = require(`${controllerPath}/inscripciones`); const inscripcionUsuario = require(`${controllerPath}/inscripcionUsuario`); -const credito = require(`${controllerPath}/credito`); const agregarCredito = require(`${controllerPath}/agregarCredito`); +const credito = require(`${controllerPath}/credito`); app.post(`${route}/login`, (req, res) => { return login(req.body) @@ -47,16 +47,6 @@ app.post( } ); -app.get(`${route}/credito`, (req, res) => { - return credito(req.query) - .then((data) => { - res.status(200).json(data); - }) - .catch((err) => { - res.status(400).json({ message: err.message }); - }); -}); - app.put(`${route}/agregar_credito`, (req, res) => { return agregarCredito(req.body) .then((data) => { @@ -66,4 +56,15 @@ app.put(`${route}/agregar_credito`, (req, res) => { res.status(400).json({ message: err.message }); }); }); + +app.get(`${route}/credito`, verificaToken, (req, res) => { + return credito(req.query) + .then((data) => { + res.status(200).json(data); + }) + .catch((err) => { + res.status(400).json({ message: err.message }); + }); +}); + module.exports = app;