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

77 lines
1.8 KiB
JavaScript
Raw Normal View History

2022-05-16 22:16:35 -05:00
const {
validarNumeroEntero,
validarNumeroCuenta,
} = require('../../helper/validar');
2022-02-04 01:08:23 -06:00
const dbPath = '../../db/tablas';
const Inscripcion = require(`${dbPath}/Inscripcion`);
2022-05-16 22:16:35 -05:00
const gmail = require('../../helper/gmail');
const correoDeclinar = require('../../helper/correoDeclinar');
2022-02-04 01:08:23 -06:00
const validarTicket = async (body) => {
2022-03-21 15:17:20 -06:00
const folio = validarNumeroEntero(body.folio, 'folio', true);
2022-05-16 22:16:35 -05:00
const numeroCuenta = validarNumeroCuenta(
body.numeroCuenta,
'número de cuenta',
true
);
let correo = {};
let email = '';
2022-03-21 15:17:20 -06:00
2022-03-18 00:29:38 -06:00
return Inscripcion.findOne({
2022-03-22 18:20:38 -06:00
where: { folio },
2022-03-18 00:29:38 -06:00
})
.then((res) => {
if (!res) throw new Error('Este folio no existe');
idUsuario = res.idUsuario;
2022-03-22 18:20:38 -06:00
if (body.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-22 18:20:38 -06:00
validacion: body.validacion,
2022-03-18 00:29:38 -06:00
},
{
where: {
2022-03-21 15:17:20 -06:00
folio,
2022-03-29 17:07:04 -06:00
cancelacion: 0,
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-05-16 22:16:35 -05:00
email = `${numeroCuenta}@pcpuma.acatlan.unam.mx`;
correoDeclinar = correoInscripciones();
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: {
2022-03-22 18:20:38 -06:00
folio,
2022-03-17 00:46:01 -06:00
},
}
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;