tercer semestre get alumno
This commit is contained in:
@@ -4,7 +4,7 @@ const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const Grupo = require(`${dbPath}/Grupo`);
|
||||
|
||||
const admin = async (body) => {
|
||||
const get = async (body) => {
|
||||
const idCarrera = validarId(body.idCarrera);
|
||||
|
||||
return Carrera.findOne({ where: { idCarrera } })
|
||||
@@ -19,4 +19,4 @@ const admin = async (body) => {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = admin;
|
||||
module.exports = get;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
const { Op } = require('sequelize');
|
||||
const { validarNumeroCuenta } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const Grupo = require(`${dbPath}/Grupo`);
|
||||
const TercerSemestre = require(`${dbPath}/TercerSemestre`);
|
||||
|
||||
const get = async (body) => {
|
||||
const numeroCuenta = validarNumeroCuenta(body.numeroCuenta);
|
||||
|
||||
return TercerSemestre.findOne({
|
||||
where: { numeroCuenta },
|
||||
include: [{ model: Grupo, include: [{ model: Carrera }] }],
|
||||
}).then((res) => {
|
||||
if (!res) throw new Error('No existe esta alumno.');
|
||||
if (res.deseaAsistir)
|
||||
throw new Error('Ta se registro a este alumno al recorrido.');
|
||||
delete res.dataValues.idGrupo;
|
||||
delete res.dataValues.Grupo.dataValues.idCarrera;
|
||||
return res;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = get;
|
||||
+21
-13
@@ -1,6 +1,6 @@
|
||||
const csv = require('csvtojson');
|
||||
const { Op } = require('sequelize');
|
||||
const dbPath = './db/tablas';
|
||||
const dbPath = './tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const Dia = require(`${dbPath}/Dia`);
|
||||
const DiaHora = require(`${dbPath}/DiaHora`);
|
||||
@@ -15,19 +15,27 @@ const cargaMasiva = async () => {
|
||||
await csv()
|
||||
.fromFile(path)
|
||||
.then(async (alumnos) => {
|
||||
// for (let i = 0; i < alumnos.length; i++) {
|
||||
for (let i = 0; i < 1; i++) {
|
||||
await GrupoDiaHora.findOne({
|
||||
include: [
|
||||
{
|
||||
model: Grupo,
|
||||
include: [
|
||||
{ model: Carrera, where: { carrera: alumnos[i].carrera } },
|
||||
],
|
||||
},
|
||||
{ model: DiaHora, include: [{ model: Dia }, { model: Hora }] },
|
||||
],
|
||||
for (let i = 0; i < alumnos.length; i++) {
|
||||
// for (let i = 0; i < 1; i++) {
|
||||
const grupo = await Grupo.findOne({
|
||||
where: { grupo: alumnos[i].grupo },
|
||||
include: [{ model: Carrera, where: { carrera: alumnos[i].carrera } }],
|
||||
});
|
||||
|
||||
if (!grupo) {
|
||||
console.log(
|
||||
`No exite la carrera o el grupo del alumno ${alumnos[i].cuenta}.`
|
||||
);
|
||||
continue;
|
||||
}
|
||||
await TercerSemestre.create({
|
||||
numeroCuenta: alumnos[i].cuenta,
|
||||
nombre: alumnos[i].nombre,
|
||||
idGrupo: grupo.idGrupo,
|
||||
});
|
||||
console.log(
|
||||
`Se añadio al alumno ${alumnos[i].cuenta} al grupo ${grupo.grupo} con id ${grupo.idGrupo}.`
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const route = '/tercer_semestre';
|
||||
const controllerPath = '../controller/TercerSemestre';
|
||||
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;
|
||||
@@ -3,5 +3,6 @@ const app = express();
|
||||
|
||||
app.use(require('./Carrera'));
|
||||
app.use(require('./Grupo'));
|
||||
app.use(require('./TercerSemestre'));
|
||||
|
||||
module.exports = app;
|
||||
|
||||
Reference in New Issue
Block a user