Files

37 lines
892 B
JavaScript
Raw Permalink Normal View History

2022-03-15 18:26:51 -06:00
const dbPath = '../../db/tablas';
const Inscripcion = require(`${dbPath}/Inscripcion`);
2022-03-15 18:51:51 -06:00
const { validarNumeroEntero } = require('../../helper/validar');
2022-03-15 18:26:51 -06:00
const cancelarInscripcion = async (body) => {
2022-03-15 18:51:51 -06:00
const idInscripcion = validarNumeroEntero(
body.idInscripcion,
'id Inscripcion',
true
);
2022-03-15 18:26:51 -06:00
return Inscripcion.findOne({
2022-03-15 18:51:51 -06:00
where: { idInscripcion },
2022-03-15 18:26:51 -06:00
})
.then((res) => {
if (!res) throw new Error('Lo sentimos esta inscripción no existe.');
return Inscripcion.update(
{
cancelacion: 1,
},
{
where: {
2022-03-15 18:51:51 -06:00
idInscripcion,
2022-03-15 18:26:51 -06:00
},
}
);
})
.then((res) => ({
message: '¡ Esta inscripción fue cancelada de forma correcta !',
}))
.catch((err) => {
throw new Error('¡ No fue posible validar la inscripción !. ');
});
};
module.exports = cancelarInscripcion;