58 lines
1.3 KiB
JavaScript
58 lines
1.3 KiB
JavaScript
const dbPath = '../../db/tablas';
|
|
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
|
|
|
const validarTicket = async (body) => {
|
|
return Inscripcion.findOne({
|
|
where: { folio: body.folio },
|
|
})
|
|
.then((res) => {
|
|
if (!res) throw new Error('Este folio no existe');
|
|
idUsuario = res.idUsuario;
|
|
if (body.validacion == 1) {
|
|
return Inscripcion.findOne({
|
|
where: { folio: body.folio, validacion: 1 },
|
|
});
|
|
}
|
|
})
|
|
.then((res) => {
|
|
if (res) throw new Error('Este folio ya fue validado');
|
|
return Inscripcion.update(
|
|
{
|
|
validacion: body.validacion,
|
|
},
|
|
{
|
|
where: {
|
|
folio: body.folio,
|
|
},
|
|
}
|
|
);
|
|
})
|
|
.then((res) => {
|
|
if (body.validacion === 0) {
|
|
return Inscripcion.update(
|
|
{ motivo: body.motivo },
|
|
{
|
|
where: {
|
|
folio: body.folio,
|
|
},
|
|
}
|
|
);
|
|
}
|
|
})
|
|
.then((res) => {
|
|
if (body.validacion === 1)
|
|
return {
|
|
message: '¡El ticket a sido validado de forma correcta!',
|
|
};
|
|
else
|
|
return {
|
|
message: '¡El ticket a sido declinado',
|
|
};
|
|
})
|
|
.catch((err) => {
|
|
throw new Error('No fue posible validar el ticket. ' + err);
|
|
});
|
|
};
|
|
|
|
module.exports = validarTicket;
|