Skip to content

Instantly share code, notes, and snippets.

@pajtai
Created May 6, 2018 05:44
Show Gist options
  • Save pajtai/e852411ad1712610add2a3422ca1df43 to your computer and use it in GitHub Desktop.
Save pajtai/e852411ad1712610add2a3422ca1df43 to your computer and use it in GitHub Desktop.
'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