From ff4ec82ef5d9a788912f7b614bf5f1ca55233440 Mon Sep 17 00:00:00 2001 From: JayWll Date: Sun, 23 Feb 2020 15:23:38 -0700 Subject: [PATCH] Video 91: Resource Reading Endpoints: Part I --- 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 4028a1c..db4cdfa 100644 --- a/task-manager/src/index.js +++ b/task-manager/src/index.js @@ -18,6 +18,28 @@ app.post('/users', (req, res) => { }) }) +app.get('/users', (req, res) => { + User.find({}).then((users) => { + res.send(users) + }).catch((e) => { + res.status(500).send() + }) +}) + +app.get('/users/:id', (req, res) => { + const _id = req.params.id + + User.findById(_id).then((user) => { + if (!user) { + return res.status(404).send() + } + + res.send(user) + }).catch((e) => { + res.status(500).send() + }) +}) + app.post('/tasks', (req, res) => { const task = new Task(req.body)