From a318b8ffec7d0ab8d575bd9272fdb3f5525f05a8 Mon Sep 17 00:00:00 2001 From: Manish Date: Wed, 29 Mar 2023 02:34:09 +1100 Subject: [PATCH] Impl: GET users list --- index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/index.js b/index.js index fa2a9d2..1afffc2 100644 --- a/index.js +++ b/index.js @@ -51,6 +51,20 @@ app.post("/api/users", (req, res) => { }); }); +app.get("/api/users", (req, res) => { + exerciseLogs + .find() + .select({ username: true, _id: true }) + .exec() + .then((users) => { + res.json(users); + }) + .catch((err) => { + res.sendStatus(500); + res.json({ error: `Error while retrieving users list:\n${err}` }); + }); +}); + const listener = app.listen(PORT, () => { console.log("Your app is listening on port " + listener.address().port); });