Skip to content

Instantly share code, notes, and snippets.

@crizstian
Created January 29, 2017 20:16
Show Gist options
  • Save crizstian/37c9a50e4cecd9ff32af145281ab54a2 to your computer and use it in GitHub Desktop.
Save crizstian/37c9a50e4cecd9ff32af145281ab54a2 to your computer and use it in GitHub Desktop.
Example of express routes
'use strict'
const status = require('http-status')
module.exports = (app, options) => {
const {repo} = options
app.get('/cinemas', (req, res, next) => {
repo.getCinemasByCity(req.query.cityId)
.then(cinemas => {
res.status(status.OK).json(cinemas)
})
.catch(next)
})
app.get('/cinemas/:cinemaId', (req, res, next) => {
repo.getCinemaById(req.params.cinemaId)
.then(cinema => {
res.status(status.OK).json(cinema)
})
.catch(next)
})
app.get('/cinemas/:cityId/:movieId', (req, res, next) => {
const params = {
cityId: req.params.cityId,
movieId: req.params.movieId
}
repo.getCinemaScheduleByMovie(params)
.then(schedules => {
res.status(status.OK).json(schedules)
})
.catch(next)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment