endpoint de escolares, login e inscripcion
This commit is contained in:
@@ -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;
|
||||
@@ -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);
|
||||
|
||||
@@ -69,12 +69,12 @@ Inscripcion.belongsTo(Area, {
|
||||
},
|
||||
});
|
||||
|
||||
Inscripcion.belongsTo(FechaInscripcion, {
|
||||
foreignKey: {
|
||||
name: 'idFechaInscripcion',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
// Inscripcion.belongsTo(FechaInscripcion, {
|
||||
// foreignKey: {
|
||||
// name: 'idFechaInscripcion',
|
||||
// type: DataTypes.INTEGER,
|
||||
// allowNull: false,
|
||||
// },
|
||||
// });
|
||||
|
||||
module.exports = Inscripcion;
|
||||
|
||||
+15
-11
@@ -17,15 +17,19 @@ Usuario.init(
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
},
|
||||
semestre: {
|
||||
type: DataTypes.STRING(30),
|
||||
allowNull: false,
|
||||
},
|
||||
nombre: {
|
||||
type: DataTypes.STRING(70),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
semestre: {
|
||||
type: DataTypes.STRING(30),
|
||||
allowNull: false,
|
||||
},
|
||||
carrera: {
|
||||
type: DataTypes.STRING(60),
|
||||
allowNull: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
@@ -35,12 +39,12 @@ Usuario.init(
|
||||
}
|
||||
);
|
||||
|
||||
Usuario.belongsTo(Carrera, {
|
||||
foreignKey: {
|
||||
name: 'idCarrera',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
// Usuario.belongsTo(Carrera, {
|
||||
// foreignKey: {
|
||||
// name: 'idCarrera',
|
||||
// type: DataTypes.INTEGER,
|
||||
// allowNull: false,
|
||||
// },
|
||||
// });
|
||||
|
||||
module.exports = Usuario;
|
||||
|
||||
@@ -5,6 +5,8 @@ const route = '/Usuario';
|
||||
const controllerPath = '../controller/Usuario';
|
||||
const login = require(`${controllerPath}/login`);
|
||||
const escolares = require(`${controllerPath}/escolares`);
|
||||
const inscripciones = require(`${controllerPath}/inscripciones`);
|
||||
const inscripcionUsuario = require(`${controllerPath}/inscripcionUsuario`);
|
||||
|
||||
app.post(`${route}/login`, (req, res) => {
|
||||
return login(req.body)
|
||||
@@ -16,8 +18,18 @@ app.post(`${route}/login`, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get(`${route}/escolares`, (req, res) => {
|
||||
return escolares(req.query)
|
||||
app.get(`${route}/inscripciones`, (req, res) => {
|
||||
return inscripciones(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.post(`${route}/inscripcionUsuario`, (req, res) => {
|
||||
return inscripcionUsuario(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user