validaciones

This commit is contained in:
Andres2908
2022-03-21 14:03:30 -06:00
parent 73d661cefc
commit 2cd8c0810c
12 changed files with 65 additions and 98 deletions
+21 -3
View File
@@ -1,5 +1,6 @@
const dbPath = '../../db/tablas';
const { validarNumeroEntero } = require('../../helper/validar');
const { Op } = require('sequelize');
const Inscripcion = require(`${dbPath}/Inscripcion`);
const actualizarTicket = async (body) => {
@@ -9,15 +10,32 @@ const actualizarTicket = async (body) => {
true
);
const monto = validarNumeroEntero(body.monto, 'monto', true);
return Inscripcion.findOne({
where: { idInscripcion },
where: {
idInscripcion,
},
})
.then((res) => {
if (!res) throw new Error('No pudimos encontrar este ticket.');
return Inscripcion.findOne({
where: {
folio: body.folio,
cancelacion: 0,
idInscripcion: {[Op.ne]: idInscripcion}
},
});
})
.then((res) => {
if (res)
throw new Error('¡ Este folio ya fue utilizado por otra inscripción !');
})
.then((res) => {
return Inscripcion.update(
{
folio: body.folio,
monto: body.monto,
monto,
fechaTicket: body.fechaTicket,
},
{
@@ -32,7 +50,7 @@ const actualizarTicket = async (body) => {
'¡ Los datos de la inscripción fueron actualizados de forma correcta !',
}))
.catch((err) => {
throw new Error('No fue posible validar el ticket. ' + err);
throw new Error('No fue posible actualizar los datos del ticket. ' + err);
});
};
+3 -3
View File
@@ -1,15 +1,15 @@
const dbPath = '../../db/tablas';
const Inscripcion = require(`${dbPath}/Inscripcion`);
const { validarNumeroEntero } = require('../../helper/validar');
const motivo = async (body) => {
const folio = body.folio;
return Inscripcion.findOne({
where: { folio: body.folio },
where: { folio },
})
.then((res) => {
if (!res) throw new Error('No pudimos encontrar este ticket.');
return Inscripcion.findOne({
where: { folio: body.folio },
where: { folio, validacion: 0 },
attributes: ['motivo'],
});
})
+11 -23
View File
@@ -29,29 +29,17 @@ const reporte = async (body) => {
],
})
.then(async (res) => {
if (body.tipo === 'CSV') {
for (let i = 0; i < res.length; i++) {
data.push({
numero_cuenta: res[i].Usuario.numeroCuenta,
id_area: res[i].idArea,
folio: res[i].folio,
monto: res[i].monto,
hizo_pago: res[i].hizoPago,
fecha_inscripcion: moment(res[i].fechaInscripcion).format('L'),
});
}
} else {
for (let i = 0; i < res.length; i++) {
data.push({
numeroCuenta: res[i].Usuario.numeroCuenta,
validacion: res[i].validacion,
folio: res[i].folio,
monto: res[i].monto,
hizoPago: res[i].hizoPago,
fechaInscripcion: moment(res[i].fechaInscripcion).format('L'),
idArea: res[i].idArea,
});
}
for (let i = 0; i < res.length; i++) {
data.push({
numeroCuenta: res[i].Usuario.numeroCuenta,
idArea: res[i].idArea,
folio: res[i].folio,
monto: res[i].monto,
hizoPago: res[i].hizoPago,
fechaInscripcion: moment(res[i].fechaInscripcion).format('L'),
validacion: res[i].validacion,
motivoCancelacion: res[i].motivo,
});
}
await helper.eliminarArchivo(path).catch((err) => {});
return helper.crearArchivo(path, convertArrayToCSV(data));
@@ -1,13 +1,16 @@
const validar = require('../../helper/validar');
const {
validarNumeroCuenta,
validarNumeroEntero,
} = require('../../helper/validar');
const { Op } = require('sequelize');
const dbPath = '../../db/tablas';
const Usuario = require(`${dbPath}/Usuario`);
const Inscripcion = require(`${dbPath}/Inscripcion`);
const todasInscripciones = async (body) => {
// const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
const validacion = validarNumeroEntero(body.validacion, 'validacion', true);
return Inscripcion.findAll({
where: { validacion: body.validacion, cancelacion: 0 },
where: { validacion, cancelacion: 0 },
include: [
{
model: Usuario,
+3 -16
View File
@@ -1,29 +1,16 @@
const dbPath = '../../db/tablas';
const Inscripcion = require(`${dbPath}/Inscripcion`);
const Usuario = require(`${dbPath}/Usuario`);
const { usuarioInscrito } = require('../../config/mariadb.conf');
const { validarNumeroEntero } = require('../../helper/helper');
const validarSinTicket = async (body) => {
// return usuarioInscrito(body.numeroCuenta, 0)
// .then((res) => {
// return Inscripcion.update(
// {
// validacion: 1,
// },
// {
// where: {
// idUsuario: body.idUsuario,
// },
// }
// );
// })
const idUsuario = validarNumeroEntero(body.idUsuario, 'usuario', true);
return Inscripcion.update(
{
validacion: 1,
},
{
where: {
idUsuario: body.idUsuario,
idUsuario,
},
}
)