From c6f399c461e76bb5df0c3d9d96d1de52a92e3a24 Mon Sep 17 00:00:00 2001 From: Shahan Arshad <68821506+sazk07@users.noreply.github.com> Date: Wed, 13 Nov 2024 01:12:35 +0500 Subject: [PATCH 1/2] Fix typo: Update index.js Fix typo in condition check --- examples/params/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/params/index.js b/examples/params/index.js index f3cd8457eb5..11f491764e2 100644 --- a/examples/params/index.js +++ b/examples/params/index.js @@ -32,7 +32,7 @@ app.param(['to', 'from'], function(req, res, next, num, name){ // Load user by id app.param('user', function(req, res, next, id){ - if (req.user = users[id]) { + if (req.user === users[id]) { next(); } else { next(createError(404, 'failed to find user')); From 00887b9e1587888df4fb6ec933b91433185f0d78 Mon Sep 17 00:00:00 2001 From: Shahan Arshad <68821506+sazk07@users.noreply.github.com> Date: Wed, 13 Nov 2024 04:41:09 +0500 Subject: [PATCH 2/2] Fix: separate assignment and condition check in Update index.js assignment was being done inside condition check leading to confusion in reading code. --- examples/params/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/params/index.js b/examples/params/index.js index 11f491764e2..11eef51a592 100644 --- a/examples/params/index.js +++ b/examples/params/index.js @@ -32,7 +32,8 @@ app.param(['to', 'from'], function(req, res, next, num, name){ // Load user by id app.param('user', function(req, res, next, id){ - if (req.user === users[id]) { + req.user = users[id] + if (req.user) { next(); } else { next(createError(404, 'failed to find user'));