42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
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;
|