get plantel y carreras
This commit is contained in:
@@ -1,17 +1,37 @@
|
||||
const validador = require('../validador')
|
||||
const Carrera = require('../../db/tables/Carrera')
|
||||
const CarreraPlantel = require('../../db/tables/CarreraPlantel')
|
||||
const Plantel = require('../../db/tables/Plantel')
|
||||
|
||||
const get = async (body) => {
|
||||
return CarreraPlantel.findAll({
|
||||
let idPlantel = await validador.validarId(body.idPlantel).then((res) => res)
|
||||
let busquedaCarrera = {
|
||||
where: { idPlantel: body.idPlantel },
|
||||
include: [{ model: Carrera }],
|
||||
})
|
||||
}
|
||||
let busquedaPlantel = { where: idPlantel }
|
||||
|
||||
return Plantel.findOne(busquedaPlantel)
|
||||
.then((res) => {
|
||||
return res
|
||||
if (!res) validador.error('El plantel no existe.', 400)
|
||||
return CarreraPlantel.findAll(busquedaCarrera)
|
||||
})
|
||||
.then((res) => {
|
||||
let data = []
|
||||
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
let carrera = {
|
||||
idCarreraPlantel: res[i].idCarreraPlantel,
|
||||
Carrera: {
|
||||
idCarrera: res[i].Carrera.idCarrera,
|
||||
carrera: res[i].Carrera.carrera,
|
||||
nivel: res[i].Carrera.nivel,
|
||||
},
|
||||
}
|
||||
data.push(carrera)
|
||||
}
|
||||
return { code: 200, data }
|
||||
})
|
||||
.catch((err) => {})
|
||||
}
|
||||
|
||||
module.exports = get
|
||||
|
||||
// get({ idPlantel: 240 })
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
const Plantel = require('../../db/tables/Plantel')
|
||||
|
||||
const get = async () => {
|
||||
return Plantel.findAll()
|
||||
.then((res) => {
|
||||
return res
|
||||
})
|
||||
.catch((err) => {})
|
||||
return Plantel.findAll().then((res) => {
|
||||
return { code: 200, data: res }
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = get
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
const express = require('express')
|
||||
const app = express()
|
||||
const get = require('../controller/carrera/get')
|
||||
const route = '/carrera'
|
||||
|
||||
app.get(`${route}`, (req, res) => {
|
||||
return get(req.query)
|
||||
.then((data) => {
|
||||
res.status(data.code).json(data.data)
|
||||
})
|
||||
.catch((err) => res.status(err.code).json({ err: err.message }))
|
||||
})
|
||||
|
||||
module.exports = app
|
||||
|
||||
@@ -3,5 +3,7 @@ const app = express()
|
||||
|
||||
// app.use(require('./'))
|
||||
app.use(require('./usuario'))
|
||||
app.use(require('./plantel'))
|
||||
app.use(require('./carrera'))
|
||||
|
||||
module.exports = app
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
const express = require('express')
|
||||
const app = express()
|
||||
const get = require('../controller/plantel/get')
|
||||
const route = '/plantel'
|
||||
|
||||
app.get(`${route}`, (req, res) => {
|
||||
return get()
|
||||
.then((data) => {
|
||||
res.status(data.code).json(data.data)
|
||||
})
|
||||
.catch((err) => res.status(err.code).json({ err: err.message }))
|
||||
})
|
||||
|
||||
module.exports = app
|
||||
|
||||
Reference in New Issue
Block a user