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

55 lines
1.5 KiB
JavaScript
Raw Normal View History

2022-02-04 01:08:23 -06:00
const dbPath = '../../db/tablas';
const Inscripcion = require(`${dbPath}/Inscripcion`);
2022-03-04 01:05:26 -06:00
const Usuario = require(`${dbPath}/Usuario`);
const { usuarioInscrito } = require('../../config/mariadb.conf');
2022-02-04 01:08:23 -06:00
const validarTicket = async (body) => {
return Inscripcion.findOne({
where: { folio: body.folio },
})
.then((res) => {
if (!res) throw new Error('Este folio no existe');
2022-03-04 01:05:26 -06:00
idUsuario = res.idUsuario;
2022-03-06 20:02:42 -06:00
return Inscripcion.findOne({
where: { folio: body.folio, validacion: 1 },
});
})
.then((res) => {
if (res) throw new Error('Este folio ya fue validado');
2022-02-04 01:08:23 -06:00
return Inscripcion.update(
{
validacion: body.validacion,
},
{
where: {
folio: body.folio,
validacion: 2,
2022-02-04 01:08:23 -06:00
},
}
);
})
.then((res) => {
2022-02-10 00:44:23 -06:00
if (body.validacion === 0)
2022-02-22 16:31:40 -06:00
throw new Error(
'El administrador a declinado el ticket, ya que los datos no coinciden.'
);
2022-02-04 01:08:23 -06:00
})
2022-03-03 23:09:14 -06:00
.then((res) => {
2022-03-04 01:05:26 -06:00
return Usuario.findOne({
where: { idUsuario },
attributes: ['numeroCuenta'],
}).then((res) => {
2022-03-06 20:02:42 -06:00
return usuarioInscrito(res.numeroCuenta, 1).then(async (res) => {
2022-03-04 01:05:26 -06:00
return {
message: '¡ El ticket a sido validado de forma correcta !',
};
});
2022-03-03 23:09:14 -06:00
});
})
2022-02-04 01:08:23 -06:00
.catch((err) => {
2022-02-05 00:28:53 -06:00
throw new Error('No fue posible validar el ticket. ' + err);
2022-02-04 01:08:23 -06:00
});
};
module.exports = validarTicket;