From ab196e07cfba415714f732a94e8a5be120b9c9cd Mon Sep 17 00:00:00 2001 From: "Lemuel H. Marquez Rosas" Date: Sun, 4 Oct 2020 23:38:22 -0500 Subject: [PATCH] get horarios --- src/controller/horario/get.js | 34 ++++++++++++++++------------------ src/routes/horario.js | 14 ++++++++++++++ src/routes/index.js | 1 + 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/controller/horario/get.js b/src/controller/horario/get.js index eb3241e..c8748af 100644 --- a/src/controller/horario/get.js +++ b/src/controller/horario/get.js @@ -2,27 +2,25 @@ const moment = require('moment') const Horario = require('../../db/tables/Horario') const get = async () => { - return Horario.findAll() - .then((res) => { - let data = [] - let now = moment().add(15, 'minutes') + return Horario.findAll().then((res) => { + let data = [] + let now = moment().add(15, 'minutes') - for (let i = 0; i < res.length; i++) { - let hora = res[i].horario.substr(res[i].horario.indexOf('-') + 1) - let horaNumero = Number(hora.substr(0, hora.indexOf(':'))) - let horaLimite = moment() + for (let i = 0; i < res.length; i++) { + let hora = res[i].horario.substr(res[i].horario.indexOf('-') + 1) + let horaNumero = Number(hora.substr(0, hora.indexOf(':'))) + let horaLimite = moment() - horaLimite.set('hour', horaNumero) - horaLimite.set('minute', 0) - horaLimite.set('second', 0) + horaLimite.set('hour', horaNumero) + horaLimite.set('minute', 0) + horaLimite.set('second', 0) - /* Para la noche xd */ - // horaLimite.add(1, 'days') - if (now < horaLimite) data.push(res[i]) - } - return data - }) - .catch((err) => {}) + /* Para la noche xd */ + horaLimite.add(1, 'days') + if (now < horaLimite) data.push(res[i]) + } + return { code: 200, data } + }) } module.exports = get diff --git a/src/routes/horario.js b/src/routes/horario.js index e69de29..3f569d4 100644 --- a/src/routes/horario.js +++ b/src/routes/horario.js @@ -0,0 +1,14 @@ +const express = require('express') +const app = express() +const get = require('../controller/horario/get') +const route = '/horario' + +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 diff --git a/src/routes/index.js b/src/routes/index.js index 2a1f04d..bc609c4 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -5,5 +5,6 @@ const app = express() app.use(require('./usuario')) app.use(require('./plantel')) app.use(require('./carrera')) +app.use(require('./horario')) module.exports = app