get horarios
This commit is contained in:
@@ -2,27 +2,25 @@ const moment = require('moment')
|
|||||||
const Horario = require('../../db/tables/Horario')
|
const Horario = require('../../db/tables/Horario')
|
||||||
|
|
||||||
const get = async () => {
|
const get = async () => {
|
||||||
return Horario.findAll()
|
return Horario.findAll().then((res) => {
|
||||||
.then((res) => {
|
let data = []
|
||||||
let data = []
|
let now = moment().add(15, 'minutes')
|
||||||
let now = moment().add(15, 'minutes')
|
|
||||||
|
|
||||||
for (let i = 0; i < res.length; i++) {
|
for (let i = 0; i < res.length; i++) {
|
||||||
let hora = res[i].horario.substr(res[i].horario.indexOf('-') + 1)
|
let hora = res[i].horario.substr(res[i].horario.indexOf('-') + 1)
|
||||||
let horaNumero = Number(hora.substr(0, hora.indexOf(':')))
|
let horaNumero = Number(hora.substr(0, hora.indexOf(':')))
|
||||||
let horaLimite = moment()
|
let horaLimite = moment()
|
||||||
|
|
||||||
horaLimite.set('hour', horaNumero)
|
horaLimite.set('hour', horaNumero)
|
||||||
horaLimite.set('minute', 0)
|
horaLimite.set('minute', 0)
|
||||||
horaLimite.set('second', 0)
|
horaLimite.set('second', 0)
|
||||||
|
|
||||||
/* Para la noche xd */
|
/* Para la noche xd */
|
||||||
// horaLimite.add(1, 'days')
|
horaLimite.add(1, 'days')
|
||||||
if (now < horaLimite) data.push(res[i])
|
if (now < horaLimite) data.push(res[i])
|
||||||
}
|
}
|
||||||
return data
|
return { code: 200, data }
|
||||||
})
|
})
|
||||||
.catch((err) => {})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = get
|
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('./usuario'))
|
||||||
app.use(require('./plantel'))
|
app.use(require('./plantel'))
|
||||||
app.use(require('./carrera'))
|
app.use(require('./carrera'))
|
||||||
|
app.use(require('./horario'))
|
||||||
|
|
||||||
module.exports = app
|
module.exports = app
|
||||||
|
|||||||
Reference in New Issue
Block a user