46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
const moment = require('moment');
|
|
const {
|
|
validarNumeroEntero,
|
|
validarNumeroCuenta,
|
|
} = require('../../helper/validar');
|
|
const dbPath = '../../db/tablas';
|
|
const Carrera = require(`${dbPath}/Carrera`);
|
|
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
|
const ahora = moment();
|
|
|
|
const inscripcion = async (body) => {
|
|
const idUsuario = validarNumeroEntero(body.idUsuario, 'id Usuario', true);
|
|
const idArea = validarNumeroEntero(body.idArea, 'id Area', true);
|
|
const folio = body.folio;
|
|
|
|
return Inscripcion.findOne({
|
|
where: { folio },
|
|
})
|
|
.then((res) => {
|
|
if (res) throw new Error('Este folio ya esta registrado');
|
|
return Inscripcion.findOne({
|
|
where: { idArea },
|
|
}).then((res) => {
|
|
if (res) throw new Error('Ya estas registrado en esta área');
|
|
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;
|