From b4f47db7ab8b1245f79b03d4ed3c5389a4aea9d8 Mon Sep 17 00:00:00 2001 From: JayWll Date: Sun, 23 Feb 2020 15:33:15 -0700 Subject: [PATCH] Video 92: Resource Reading Endpoints: Part II --- task-manager/src/index.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/task-manager/src/index.js b/task-manager/src/index.js index db4cdfa..7738a69 100644 --- a/task-manager/src/index.js +++ b/task-manager/src/index.js @@ -50,6 +50,28 @@ app.post('/tasks', (req, res) => { }) }) +app.get('/tasks', (req, res) => { + Task.find({}).then((tasks) => { + res.send(tasks) + }).catch((e) => { + res.status(500).send() + }) +}) + +app.get('/tasks/:id', (req, res) => { + const _id = req.params.id + + Task.findById(_id).then((task) => { + if (!task) { + return res.status(404).send() + } + + res.send(task) + }).catch((e) => { + res.status(500).send() + }) +}) + app.listen(port, () => { console.log('Server is up on port ' + port) })