From 10dc4a0e3c6daf9ee4826ca6abd054b0c716973e Mon Sep 17 00:00:00 2001 From: Andres2908 Date: Fri, 6 May 2022 01:57:46 -0500 Subject: [PATCH] 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