endponit de impresiones y tabla
This commit is contained in:
@@ -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;
|
||||
@@ -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) => ({
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
numeroCuenta,idArea,folio,monto,hizoPago,fechaInscripcion,validacion,motivoDeclinacion
|
||||
419085500,1,123345,12,true,03/22/2022,0,prueba
|
||||
|
||||
|
Reference in New Issue
Block a user