manejo de errores

This commit is contained in:
Andres2908
2022-01-31 20:14:12 -06:00
parent f591727f82
commit 4ab56e9a5e
2 changed files with 23 additions and 15 deletions
+22 -13
View File
@@ -11,19 +11,28 @@ const ahora = moment();
const inscripcion = async (body) => {
const idUsuario = validarNumeroEntero(body.idUsuario, 'id Usuario', true);
const idArea = validarNumeroEntero(body.idArea, 'id Area', true);
return Inscripcion.create({
idUsuario,
confirmacion: true,
folio: body.folio,
monto: body.monto,
idArea,
fechaIncripcion: ahora.format(),
fechaTicket: body.fechaTicket,
idFechaInscripcion: body.idFechaInscripcion,
}).then((res) => ({
message: '¡La inscripción se realizo de manera correcta!',
}));
return Inscripcion.findOne({
where: { idArea: body.idArea },
})
.then((res) => {
if (res) throw new Error('Usted ya esta inscrito a esta Area');
return Inscripcion.create({
idUsuario,
confirmacion: true,
folio: body.folio,
monto: body.monto,
idArea,
fechaIncripcion: ahora.format(),
fechaTicket: body.fechaTicket,
idFechaInscripcion: body.idFechaInscripcion,
});
})
.then((res) => ({
message: '¡La inscripción se realizo de manera correcta!',
}))
.catch((err) => {
throw new Error('No es posible realizar esta inscripción. ' + err);
});
};
module.exports = inscripcion;
+1 -2
View File
@@ -5,10 +5,9 @@ const Inscripcion = require(`${dbPath}/Inscripcion`);
const inscripciones = async (body) => {
// const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
return Inscripcion.findOne({
return Inscripcion.findAll({
where: { idUsuario: body.idUsuario },
}).then((res) => {
console.log(res);
if (!res) return [];
return Inscripcion.findAll({
where: { idUsuario: body.idUsuario },