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

89 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-05-16 22:16:35 -05:00
const {
validarNumeroEntero,
validarNumeroCuenta,
} = require('../../helper/validar');
2022-05-17 12:22:12 -05:00
const {
borrarInscripcion,
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-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-06-14 18:50:40 -05:00
return (
Inscripcion.findOne({
where: { folio },
2022-03-06 20:02:42 -06:00
})
2022-06-14 18:50:40 -05:00
.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-02-04 01:08:23 -06:00
}
2022-06-14 18:50:40 -05:00
})
.then((res) => {
if (res) throw new Error('Este folio ya fue validado');
2022-03-17 00:46:01 -06:00
return Inscripcion.update(
2022-06-14 18:50:40 -05:00
{
validacion: body.validacion,
},
2022-03-17 00:46:01 -06:00
{
where: {
2022-03-22 18:20:38 -06:00
folio,
2022-06-14 18:50:40 -05:00
cancelacion: 0,
2022-03-17 00:46:01 -06:00
},
}
2022-02-22 16:31:40 -06:00
);
2022-06-14 18:50:40 -05:00
})
//el ticket ya fue validado
.then((res) => {
if (body.validacion === 0) {
email = `${numeroCuenta}@pcpuma.acatlan.unam.mx`;
correoDeclinar = correoInscripciones();
borrarInscripcion(numeroCuenta);
borrarRecibo(folio);
borrarDetalleServicio(numeroCuenta);
return Inscripcion.update(
{ motivo: body.motivo },
{
where: {
folio,
},
}
);
}
})
.then((res) => {
if (body.validacion === 1) {
//Insertar en AD
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;