Files
inscripciones_api/server/controller/Admin/validarTicket.js
T

62 lines
1.5 KiB
JavaScript
Raw Normal View History

2022-03-21 15:17:20 -06:00
const { validarNumeroEntero } = require('../../helper/validar');
2022-02-04 01:08:23 -06:00
const dbPath = '../../db/tablas';
const Inscripcion = require(`${dbPath}/Inscripcion`);
const validarTicket = async (body) => {
2022-03-21 15:17:20 -06:00
const validacion = validarNumeroEntero(body.validacion, 'validacion', true);
const folio = validarNumeroEntero(body.folio, 'folio', true);
2022-03-18 00:29:38 -06:00
return Inscripcion.findOne({
where: { folio: body.folio },
})
.then((res) => {
if (!res) throw new Error('Este folio no existe');
idUsuario = res.idUsuario;
2022-03-21 15:17:20 -06:00
if (validacion == 1) {
2022-03-18 00:29:38 -06:00
return Inscripcion.findOne({
2022-03-21 15:17:20 -06:00
where: { folio, validacion: 1 },
2022-03-18 00:29:38 -06:00
});
}
2022-03-06 20:02:42 -06:00
})
2022-03-18 00:29:38 -06:00
.then((res) => {
if (res) throw new Error('Este folio ya fue validado');
return Inscripcion.update(
{
2022-03-21 15:17:20 -06:00
validacion,
2022-03-18 00:29:38 -06:00
},
{
where: {
2022-03-21 15:17:20 -06:00
folio,
2022-03-18 00:29:38 -06:00
},
2022-02-04 01:08:23 -06:00
}
2022-03-18 00:29:38 -06:00
);
})
.then((res) => {
if (body.validacion === 0) {
2022-03-17 00:46:01 -06:00
return Inscripcion.update(
2022-03-18 00:29:38 -06:00
{ motivo: body.motivo },
2022-03-17 00:46:01 -06:00
{
where: {
folio: body.folio,
},
}
2022-02-22 16:31:40 -06:00
);
2022-03-18 00:29:38 -06:00
}
})
.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);
});
2022-02-04 01:08:23 -06:00
};
module.exports = validarTicket;