2022-05-16 22:16:35 -05:00
|
|
|
const {
|
|
|
|
|
validarNumeroEntero,
|
|
|
|
|
validarNumeroCuenta,
|
|
|
|
|
} = require('../../helper/validar');
|
2022-07-29 13:55:35 -05:00
|
|
|
const {
|
|
|
|
|
usuarioInscrito,
|
|
|
|
|
borrarRecibo,
|
|
|
|
|
borrarDetalleServicio,
|
|
|
|
|
} = require('../../config/mariadb.conf');
|
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-07-28 00:48:52 -05:00
|
|
|
const correoInscripcion = require('../../helper/correo');
|
2022-02-04 01:08:23 -06:00
|
|
|
|
|
|
|
|
const validarTicket = async (body) => {
|
2022-05-16 22:16:35 -05:00
|
|
|
const numeroCuenta = validarNumeroCuenta(
|
|
|
|
|
body.numeroCuenta,
|
|
|
|
|
'número de cuenta',
|
|
|
|
|
true
|
|
|
|
|
);
|
2022-07-29 13:59:32 -05:00
|
|
|
const folio = validarNumeroEntero(body.folio, 'folio', true);
|
|
|
|
|
const idArea = validarNumeroEntero(body.idArea, 'IDAREA', true);
|
2022-05-16 22:16:35 -05:00
|
|
|
|
|
|
|
|
let correo = {};
|
|
|
|
|
let email = '';
|
2022-03-21 15:17:20 -06:00
|
|
|
|
2022-07-28 00:48:52 -05:00
|
|
|
return Inscripcion.findOne({
|
|
|
|
|
where: { folio },
|
|
|
|
|
})
|
|
|
|
|
.then((res) => {
|
|
|
|
|
if (!res) throw new Error('Este folio no existe');
|
|
|
|
|
idUsuario = res.idUsuario;
|
|
|
|
|
if (body.validacion == 1) {
|
|
|
|
|
return Inscripcion.findOne({
|
|
|
|
|
where: { folio, validacion: 1 },
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-03-06 20:02:42 -06:00
|
|
|
})
|
2022-07-28 00:48:52 -05:00
|
|
|
.then((res) => {
|
|
|
|
|
if (res) throw new Error('Este folio ya fue validado');
|
|
|
|
|
return Inscripcion.update(
|
|
|
|
|
{
|
|
|
|
|
validacion: body.validacion,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
where: {
|
|
|
|
|
folio,
|
|
|
|
|
cancelacion: 0,
|
|
|
|
|
},
|
2022-02-04 01:08:23 -06:00
|
|
|
}
|
2022-07-28 00:48:52 -05:00
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
.then((res) => {
|
2022-07-28 22:14:06 -05:00
|
|
|
email = `${numeroCuenta}@pcpuma.acatlan.unam.mx`;
|
2022-07-28 00:48:52 -05:00
|
|
|
if (body.validacion === 1) {
|
2022-07-29 13:51:48 -05:00
|
|
|
usuarioInscrito(numeroCuenta, idArea);
|
2022-07-29 13:55:35 -05:00
|
|
|
correo = correoInscripcion();
|
2022-07-28 00:48:52 -05:00
|
|
|
} else {
|
2022-08-03 20:19:00 -05:00
|
|
|
borrarRecibo(folio, numeroCuenta);
|
2022-07-29 13:55:35 -05:00
|
|
|
borrarDetalleServicio(numeroCuenta);
|
2022-07-28 22:14:06 -05:00
|
|
|
correo = correoDeclinar();
|
2022-03-17 00:46:01 -06:00
|
|
|
return Inscripcion.update(
|
2022-07-28 00:48:52 -05: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-07-28 00:48:52 -05:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.then((res) => {
|
2022-07-28 22:14:06 -05:00
|
|
|
gmail(correo.subject, email, correo.msj);
|
2022-07-28 00:48:52 -05:00
|
|
|
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;
|