escolares
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
const Servicio = require('../../db/tablas/Servicio');
|
||||
|
||||
const serviciosAdmin = (body) => {
|
||||
Servicio.findAll().then((res) => {
|
||||
return res;
|
||||
});
|
||||
};
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
+24
-13
@@ -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);
|
||||
})
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user