get grupos
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
const { Op } = require('sequelize');
|
||||
const { validarId } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const Grupo = require(`${dbPath}/Grupo`);
|
||||
|
||||
const admin = async (body) => {
|
||||
const idCarrera = validarId(body.idCarrera);
|
||||
|
||||
return Carrera.findOne({ where: { idCarrera } })
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No existe esta carrera.');
|
||||
return Grupo.findAll({
|
||||
where: { idCarrera, grupo: { [Op.like]: '11%' } },
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = admin;
|
||||
@@ -5,7 +5,7 @@ const controllerPath = '../controller/Carrera';
|
||||
const get = require(`${controllerPath}/get`);
|
||||
|
||||
app.get(`${route}`, (req, res) => {
|
||||
return get(req.body)
|
||||
return get()
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const route = '/grupo';
|
||||
const controllerPath = '../controller/Grupo';
|
||||
const get = require(`${controllerPath}/get`);
|
||||
|
||||
app.get(`${route}`, (req, res) => {
|
||||
return get(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
@@ -2,5 +2,6 @@ const express = require('express');
|
||||
const app = express();
|
||||
|
||||
app.use(require('./Carrera'));
|
||||
app.use(require('./Grupo'));
|
||||
|
||||
module.exports = app;
|
||||
|
||||
Reference in New Issue
Block a user