Created
January 29, 2017 20:16
-
-
Save crizstian/37c9a50e4cecd9ff32af145281ab54a2 to your computer and use it in GitHub Desktop.
Example of express routes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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