endpoint de escolares, login e inscripcion

This commit is contained in:
Andres2908
2022-01-27 00:15:05 -06:00
parent 99652f15e5
commit cbd51968a1
7 changed files with 114 additions and 64 deletions
+17 -40
View File
@@ -5,52 +5,29 @@ const Carrera = require(`${dbPath}/Carrera`);
const Usuario = require(`${dbPath}/Usuario`);
const escolares = async (body) => {
const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
// const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
return Usuario.findOne({
where: { numeroCuenta: numeroCuenta },
where: { numeroCuenta: body.numeroCuenta },
}).then((res) => {
if (!res) {
let usuario = {};
return obtenerAlumno(numeroCuenta)
.then(async (res) => {
usuario = res;
return res;
})
.then(async (res) => {
return obtenerCarrera(res.id_carrera);
})
.then(async (res) => {
if (!usuario) throw new Error('Este número de cuenta no existe.');
if (usuario.vigente != 'si')
throw new Error('Este alumno no esta inscrito este semestre.');
usuario.nombre = usuario.nombre;
usuario.carrera = res.carrera;
usuario.carrera = await Carrera.findOne({
where: { idCarrera: usuario.id_carrera },
}).then((res) => {
if (!res)
return Carrera.create({
idCarrera: usuario.id_carrera,
carrera: usuario.carrera,
});
return res;
});
return Usuario.create({
numeroCuenta: numeroCuenta,
nombre: usuario.nombre,
semestre: 8,
idCarrera: usuario.id_carrera,
});
});
return Usuario.create({
numeroCuenta: body.numeroCuenta,
nombre: body.nombre,
semestre: 8,
carrera: body.carrera,
});
}
return Usuario.findOne({
where: { numeroCuenta: numeroCuenta },
include: [{ model: Carrera }],
attributes: ['idUsuario', 'numeroCuenta', 'nombre'],
where: { numeroCuenta: body.numeroCuenta },
// include: [{ model: Carrera }],
attributes: [
'idUsuario',
'numeroCuenta',
'nombre',
'semestre',
'carrera',
],
});
});
};
@@ -0,0 +1,24 @@
const moment = require('moment');
const { validarNumeroEntero } = 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);
return Inscripcion.create({
idUsuario,
confirmacion: true,
folio: body.folio,
monto: body.monto,
idArea,
fechaIncripcion: ahora.format(),
fechaTicket: ahora.format(),
idFechaInscripcion: body.idFechaInscripcion,
});
};
module.exports = inscripcion;
@@ -0,0 +1,31 @@
const validar = require('../../helper/validar');
const dbPath = '../../db/tablas';
const Carrera = require(`${dbPath}/Carrera`);
const Inscripcion = require(`${dbPath}/Inscripcion`);
const inscripciones = async (body) => {
// const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
return Inscripcion.findOne({
where: { idUsuario: body.idUsuario },
}).then((res) => {
const noInscripcion = {
status: 0,
message: 'Usuario no Inscrito',
};
if (!res) return noInscripcion;
return Inscripcion.findAll({
where: { idUsuario: body.idUsuario },
attributes: [
'idInscripcion',
'validacion',
'confirmacion',
'folio',
'monto',
'idUsuario',
'idArea',
],
});
});
};
module.exports = inscripciones;
+6 -4
View File
@@ -1,12 +1,13 @@
const validar = require('../../helper/validar');
const escolares = require('./escolares');
const axios = require('axios');
const login = async (body) => {
// const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
const data = {
usuario: 'votacionesUser',
password: 'poasfnr*/049_]',
numeroCuenta: body.numeroCuenta,
numeroCuenta: numeroCuenta,
passwordUser: body.passwordUser,
};
@@ -17,8 +18,9 @@ const login = async (body) => {
)
.then((res) => {
const info = res.data;
info.data.numeroCuenta = body.numeroCuenta;
return info;
info.data.numeroCuenta = numeroCuenta;
const datos = escolares(info.data);
return datos;
})
.catch((err) => {
console.log(err);