diff --git a/server/controller/Usuario/escolares.js b/server/controller/Usuario/escolares.js index aa926f9..feff955 100644 --- a/server/controller/Usuario/escolares.js +++ b/server/controller/Usuario/escolares.js @@ -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', + ], }); }); }; diff --git a/server/controller/Usuario/inscripcionUsuario.js b/server/controller/Usuario/inscripcionUsuario.js new file mode 100644 index 0000000..850457f --- /dev/null +++ b/server/controller/Usuario/inscripcionUsuario.js @@ -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; diff --git a/server/controller/Usuario/inscripciones.js b/server/controller/Usuario/inscripciones.js new file mode 100644 index 0000000..0adcd40 --- /dev/null +++ b/server/controller/Usuario/inscripciones.js @@ -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; diff --git a/server/controller/Usuario/login.js b/server/controller/Usuario/login.js index 2a36e66..5ea383e 100644 --- a/server/controller/Usuario/login.js +++ b/server/controller/Usuario/login.js @@ -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); diff --git a/server/db/tablas/Inscripcion.js b/server/db/tablas/Inscripcion.js index bf28c02..066f2c0 100644 --- a/server/db/tablas/Inscripcion.js +++ b/server/db/tablas/Inscripcion.js @@ -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; diff --git a/server/db/tablas/Usuario.js b/server/db/tablas/Usuario.js index 3c50058..a2eef7d 100644 --- a/server/db/tablas/Usuario.js +++ b/server/db/tablas/Usuario.js @@ -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; diff --git a/server/routes/Usuario.js b/server/routes/Usuario.js index 2101d2c..2e4892d 100644 --- a/server/routes/Usuario.js +++ b/server/routes/Usuario.js @@ -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); })