Files
inscripciones_api/server/controller/Admin/validarTicket.js
T
2022-03-01 00:13:14 -06:00

37 lines
900 B
JavaScript

const dbPath = '../../db/tablas';
const Inscripcion = require(`${dbPath}/Inscripcion`);
const validarTicket = async (body) => {
console.log(body);
return Inscripcion.findOne({
where: { folio: body.folio },
})
.then((res) => {
if (!res) throw new Error('Este folio no existe');
return Inscripcion.update(
{
validacion: body.validacion,
},
{
where: {
folio: body.folio,
},
}
);
})
.then((res) => {
if (body.validacion === 0)
throw new Error(
'El administrador a declinado el ticket, ya que los datos no coinciden.'
);
})
.then((res) => ({
message: '¡ El ticket a sido validado de forma correcta !',
}))
.catch((err) => {
throw new Error('No fue posible validar el ticket. ' + err);
});
};
module.exports = validarTicket;