40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
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;
|