diff --git a/package-lock.json b/package-lock.json index 7a0b718..edb6a18 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "axios": "^0.21.0", "bcrypt": "^5.0.0", "body-parser": "^1.19.0", "colors": "^1.4.0", @@ -219,6 +220,14 @@ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" }, + "node_modules/axios": { + "version": "0.21.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.0.tgz", + "integrity": "sha512-fmkJBknJKoZwem3/IKSSLpkdNXZeBu5Q7GA/aRsr2btgrptmSCxi2oFjZHqGdK9DoTil9PIHlPIZw2EcRJXRvw==", + "dependencies": { + "follow-redirects": "^1.10.0" + } + }, "node_modules/balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -929,6 +938,20 @@ "node": ">= 0.8" } }, + "node_modules/follow-redirects": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.0.tgz", + "integrity": "sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + } + }, "node_modules/forwarded": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", @@ -3002,6 +3025,14 @@ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" }, + "axios": { + "version": "0.21.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.0.tgz", + "integrity": "sha512-fmkJBknJKoZwem3/IKSSLpkdNXZeBu5Q7GA/aRsr2btgrptmSCxi2oFjZHqGdK9DoTil9PIHlPIZw2EcRJXRvw==", + "requires": { + "follow-redirects": "^1.10.0" + } + }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -3572,6 +3603,11 @@ "unpipe": "~1.0.0" } }, + "follow-redirects": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.0.tgz", + "integrity": "sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==" + }, "forwarded": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", diff --git a/package.json b/package.json index 1c9a7f7..ce683fc 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "author": "cidwa", "license": "ISC", "dependencies": { + "axios": "^0.21.0", "bcrypt": "^5.0.0", "body-parser": "^1.19.0", "colors": "^1.4.0", diff --git a/server/controller/Servicio/admin.js b/server/controller/Servicio/admin.js new file mode 100644 index 0000000..d026aa0 --- /dev/null +++ b/server/controller/Servicio/admin.js @@ -0,0 +1,7 @@ +const Servicio = require('../../db/tablas/Servicio'); + +const serviciosAdmin = (body) => { + Servicio.findAll().then((res) => { + return res; + }); +}; diff --git a/server/controller/Servicio/alumno.js b/server/controller/Servicio/alumno.js new file mode 100644 index 0000000..e69de29 diff --git a/server/controller/Servicio/nuevo.js b/server/controller/Servicio/nuevo.js index e69de29..a573d84 100644 --- a/server/controller/Servicio/nuevo.js +++ b/server/controller/Servicio/nuevo.js @@ -0,0 +1,15 @@ +const Servicio = require('../../db/tablas/Servicio'); + +const nuevo = (body) => { + let idPrograma = body.idUsuarioResponsable; + let idAlumno = body.idAlumno; + let numeroCuenta = body.numeroCuenta; + let creditos = body.creditos; + let nombre = body.nombre; + let correo = body.correo; + let fechaInicio = boyd.fechaInicio; + let fechaFin = boyd.fechaFin; + let cartaAceptacion = body.cartaAceptacion; +}; + +module.exports = nuevo; diff --git a/server/controller/Servicio/responsable.js b/server/controller/Servicio/responsable.js new file mode 100644 index 0000000..e69de29 diff --git a/server/controller/Usuario/escolares.js b/server/controller/Usuario/escolares.js index e69de29..66f6541 100644 --- a/server/controller/Usuario/escolares.js +++ b/server/controller/Usuario/escolares.js @@ -0,0 +1,43 @@ +const validar = require('../../helper/validar'); +require('../../config/config'); +const Usuario = require('../../db/tablas/Usuario'); +const axios = require('axios'); + +const escolares = async (body) => { + let numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta); + let alumno; + + return axios({ + method: 'post', + url: `${process.env.ESCOLARES}${numeroCuenta}`, + data: `${process.env.ESCOLARES_PASS}`, + }) + .then((res) => { + let data = res.data; + + if (!data.nombre || !data.carrconst || !data.avance) + throw new Error( + 'El alumno no cumple con los requicitos para realizar el Servicio Social. Si cree que esto es erroneo comunicate con COESI.' + ); + alumno = { + nombre: data.nombre.trim(), + carrera: data.carrconst.trim(), + creditos: data.avance, + }; + return Usuario.findOne({ where: { usuario: numeroCuenta } }); + }) + .then((res) => { + if (!res) + return Usuario.create({ + usuario: numeroCuenta, + activo: false, + idTipoUsuario: 3, + }); + return res; + }) + .then((res) => { + return { ...alumno, idUsuario: res.idUsuario }; + }); +}; + +module.exports = escolares; diff --git a/server/db/tablas/Usuario.js b/server/db/tablas/Usuario.js index 1664433..ac3010b 100644 --- a/server/db/tablas/Usuario.js +++ b/server/db/tablas/Usuario.js @@ -18,11 +18,17 @@ Usuario.init( }, password: { type: DataTypes.STRING(20), - allowNull: false, + allowNull: true, + defaultValue: null, }, nombre: { type: DataTypes.STRING(20), allowNull: true, + defaultValue: null, + }, + activo: { + type: DataTypes.BOOLEAN, + allowNull: false, }, }, { diff --git a/server/helper/validar.js b/server/helper/validar.js index 93a1885..546c451 100644 --- a/server/helper/validar.js +++ b/server/helper/validar.js @@ -40,6 +40,19 @@ const validarTexto = (texto, campo) => { return texto; }; +const validarNumeroCuenta = (numeroCuenta) => { + let campo = 'numero de cuenta'; + + noHay(numeroCuenta, campo); + if ( + typeof numeroCuenta !== 'string' || + !validator.isNumeric(numeroCuenta, { no_symbols: true }) || + numeroCuenta.length > 9 + ) + noValido(campo); + return numeroCuenta; +}; + module.exports = { validarCorreo, validarId, @@ -47,4 +60,5 @@ module.exports = { yaExiste, noValido, noHay, + validarNumeroCuenta, }; diff --git a/server/routes/Usuario.js b/server/routes/Usuario.js index f0db7e7..2a1746f 100644 --- a/server/routes/Usuario.js +++ b/server/routes/Usuario.js @@ -1,21 +1,32 @@ const express = require('express'); const app = express(); const route = '/usuario'; -const create = require('../controller/Usuario/create'); -const login = require('../controller/Usuario/login'); +const escolares = require('../controller/Usuario/escolares'); +// const create = require('../controller/Usuario/create'); +// const login = require('../controller/Usuario/login'); -app.post(`${route}/create`, (req, res) => { - return create(req.body) - .then((data) => { - res.status(201).json(data); - }) - .catch((err) => { - res.status(400).json({ message: err.message }); - }); -}); +// app.post(`${route}/create`, (req, res) => { +// return create(req.body) +// .then((data) => { +// res.status(201).json(data); +// }) +// .catch((err) => { +// res.status(400).json({ message: err.message }); +// }); +// }); -app.post(`${route}/login`, (req, res) => { - return login(req.body) +// app.post(`${route}/login`, (req, res) => { +// return login(req.body) +// .then((data) => { +// res.status(201).json(data); +// }) +// .catch((err) => { +// res.status(400).json({ message: err.message }); +// }); +// }); + +app.get(`${route}/escolares`, (req, res) => { + return escolares(req.query) .then((data) => { res.status(201).json(data); }) diff --git a/server/routes/index.js b/server/routes/index.js index e072bdc..26cc25d 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -3,6 +3,6 @@ const app = express(); // app.use(require('./')) app.use(require('./Status')); -// app.use(require('./Usuario')); +app.use(require('./Usuario')); module.exports = app;