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);
});
};