validaciones
This commit is contained in:
@@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user