Created
May 6, 2018 05:44
-
-
Save pajtai/e852411ad1712610add2a3422ca1df43 to your computer and use it in GitHub Desktop.
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 express = require('express'); | |
module.exports = (app) => { | |
const router = express.Router(); | |
router.get('/', (req, res) => { | |
app.models.todos | |
.find() | |
.then((docs) => res.json(docs)) | |
.catch((error) => res.status(500).send(error)); | |
}); | |
router.post('/', (req, res) => { | |
const todo = app.models.todos(req.body); | |
todo | |
.save() | |
.then(doc => res.json(doc)) | |
.catch(sendError(res)); | |
}); | |
return router; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment