From 6e84cd0613fd46d913bd5dfc40f09efd3fa83787 Mon Sep 17 00:00:00 2001 From: Manish Date: Wed, 29 Mar 2023 16:25:26 +1100 Subject: [PATCH] fix: send `username` as well in response when insert an exercise --- index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index ba0602a..d59986d 100644 --- a/index.js +++ b/index.js @@ -88,9 +88,10 @@ app.post("/api/users/:_id/exercises", (req, res) => { } exerciseLogs - .exists({ _id: _id }) - .then((userExists) => { - if (userExists) { + .findById(_id) + .select({ username: 1 }) + .then((user) => { + if (user) { exerciseLogs .updateOne( { _id: _id }, @@ -109,6 +110,7 @@ app.post("/api/users/:_id/exercises", (req, res) => { if (excLogs.modifiedCount) { res.json({ _id: _id, + username: user.username, description: description, duration: duration, date: new Date(date).toDateString(),