get horarios
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user