datos al at despues de validar
This commit is contained in:
@@ -1,19 +1,25 @@
|
||||
const moment = require('moment');
|
||||
const {
|
||||
validarNumeroEntero,
|
||||
validarNumeroCuenta,
|
||||
} = require('../../helper/validar');
|
||||
const {
|
||||
borrarInscripcion,
|
||||
borrarRecibo,
|
||||
borrarDetalleServicio,
|
||||
usuarioInscrito,
|
||||
agregarRecibo,
|
||||
agregarDetalleServicio,
|
||||
} = require('../../config/mariadb.conf');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||
const gmail = require('../../helper/gmail');
|
||||
const correoDeclinar = require('../../helper/correoDeclinar');
|
||||
const correoInscripcion = require('../../helper/correo');
|
||||
|
||||
const validarTicket = async (body) => {
|
||||
const folio = validarNumeroEntero(body.folio, 'folio', true);
|
||||
const idArea = validarNumeroEntero(body.idArea, 'IDAREA', true);
|
||||
const monto = validarNumeroEntero(body.monto, 'monto', true);
|
||||
const fechaTicket = body.fechaTicket;
|
||||
|
||||
const numeroCuenta = validarNumeroCuenta(
|
||||
body.numeroCuenta,
|
||||
'número de cuenta',
|
||||
@@ -23,66 +29,73 @@ const validarTicket = async (body) => {
|
||||
let correo = {};
|
||||
let email = '';
|
||||
|
||||
return (
|
||||
Inscripcion.findOne({
|
||||
where: { folio },
|
||||
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 },
|
||||
});
|
||||
}
|
||||
})
|
||||
.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 },
|
||||
});
|
||||
}
|
||||
})
|
||||
.then((res) => {
|
||||
if (res) throw new Error('Este folio ya fue validado');
|
||||
return Inscripcion.update(
|
||||
{
|
||||
validacion: body.validacion,
|
||||
.then((res) => {
|
||||
if (res) throw new Error('Este folio ya fue validado');
|
||||
return Inscripcion.update(
|
||||
{
|
||||
validacion: body.validacion,
|
||||
},
|
||||
{
|
||||
where: {
|
||||
folio,
|
||||
cancelacion: 0,
|
||||
},
|
||||
}
|
||||
);
|
||||
})
|
||||
.then((res) => {
|
||||
if (body.validacion === 1) {
|
||||
email = `${numeroCuenta}@pcpuma.acatlan.unam.mx`;
|
||||
correo = correoInscripcion();
|
||||
usuarioInscrito(numeroCuenta, idArea);
|
||||
agregarRecibo(
|
||||
folio,
|
||||
monto,
|
||||
moment(fechaTicket).format('L'),
|
||||
numeroCuenta
|
||||
);
|
||||
agregarDetalleServicio(monto, numeroCuenta);
|
||||
} else {
|
||||
email = `${numeroCuenta}@pcpuma.acatlan.unam.mx`;
|
||||
correoDeclinar = correoDeclinar();
|
||||
return Inscripcion.update(
|
||||
{ motivo: body.motivo },
|
||||
{
|
||||
where: {
|
||||
folio,
|
||||
cancelacion: 0,
|
||||
},
|
||||
}
|
||||
);
|
||||
})
|
||||
//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);
|
||||
})
|
||||
);
|
||||
}
|
||||
})
|
||||
.then((res) => {
|
||||
if (body.validacion === 1) {
|
||||
return {
|
||||
message: '¡El ticket a sido validado de forma correcta!',
|
||||
};
|
||||
} else
|
||||
return {
|
||||
message: '¡El ticket a sido declinado',
|
||||
};
|
||||
})
|
||||
.then((res) => {
|
||||
return gmail(correo.subject, email, correo.msj);
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new Error('No fue posible validar el ticket. ' + err);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = validarTicket;
|
||||
|
||||
@@ -1,18 +1,11 @@
|
||||
const moment = require('moment');
|
||||
const fs = require('fs');
|
||||
const {
|
||||
usuarioInscrito,
|
||||
agregarRecibo,
|
||||
agregarDetalleServicio,
|
||||
} = require('../../config/mariadb.conf');
|
||||
const {
|
||||
validarNumeroEntero,
|
||||
validarNumero,
|
||||
validarNumeroCuenta,
|
||||
} = require('../../helper/validar');
|
||||
const { eliminarArchivo } = require('../../helper/helper');
|
||||
const gmail = require('../../helper/gmail');
|
||||
const correoInscripciones = require('../../helper/correo');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||
|
||||
@@ -41,8 +34,7 @@ const inscripcion = async (body, file) => {
|
||||
where: { idUsuario, idArea, cancelacion: 0 },
|
||||
}).then((res) => {
|
||||
if (res) throw new Error('Ya estas registrado en esta área');
|
||||
email = `${numeroCuenta}@pcpuma.acatlan.unam.mx`;
|
||||
correo = correoInscripciones();
|
||||
|
||||
if (file && folio && fechaTicket) {
|
||||
return Inscripcion.create({
|
||||
idUsuario,
|
||||
@@ -68,15 +60,6 @@ const inscripcion = async (body, file) => {
|
||||
.then((res) => {
|
||||
if (file)
|
||||
fs.renameSync(file.path, file.path + '.' + file.mimetype.split('/')[1]);
|
||||
usuarioInscrito(numeroCuenta, idArea);
|
||||
agregarRecibo(
|
||||
folio,
|
||||
monto,
|
||||
moment(fechaTicket).format('L'),
|
||||
numeroCuenta
|
||||
);
|
||||
agregarDetalleServicio(monto, numeroCuenta);
|
||||
return gmail(correo.subject, email, correo.msj);
|
||||
})
|
||||
.then((res) => ({
|
||||
message:
|
||||
|
||||
Reference in New Issue
Block a user