58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
const dbPath = '../../db/tablas';
|
|
const { validarNumeroEntero } = require('../../helper/validar');
|
|
const { Op } = require('sequelize');
|
|
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
|
|
|
const actualizarTicket = async (body) => {
|
|
const idInscripcion = validarNumeroEntero(
|
|
body.idInscripcion,
|
|
'id Inscripcion',
|
|
true
|
|
);
|
|
const monto = validarNumeroEntero(body.monto, 'monto', true);
|
|
const folio = validarNumeroEntero(body.folio, 'folio', true);
|
|
|
|
return Inscripcion.findOne({
|
|
where: {
|
|
idInscripcion,
|
|
},
|
|
})
|
|
.then((res) => {
|
|
if (!res) throw new Error('No pudimos encontrar este ticket.');
|
|
return Inscripcion.findOne({
|
|
where: {
|
|
folio,
|
|
cancelacion: 0,
|
|
idInscripcion: { [Op.ne]: idInscripcion },
|
|
},
|
|
});
|
|
})
|
|
.then((res) => {
|
|
if (res)
|
|
throw new Error('¡ Este folio ya fue utilizado por otra inscripción !');
|
|
})
|
|
.then((res) => {
|
|
return Inscripcion.update(
|
|
{
|
|
folio,
|
|
monto,
|
|
fechaTicket: body.fechaTicket,
|
|
},
|
|
{
|
|
where: {
|
|
idInscripcion,
|
|
},
|
|
}
|
|
);
|
|
})
|
|
.then((res) => ({
|
|
message:
|
|
'¡ Los datos de la inscripción fueron actualizados de forma correcta !',
|
|
}))
|
|
.catch((err) => {
|
|
throw new Error('No fue posible actualizar los datos del ticket. ' + err);
|
|
});
|
|
};
|
|
|
|
module.exports = actualizarTicket;
|