From fd20a9218fbb8ab91f34de898ebe18a649e4fdf2 Mon Sep 17 00:00:00 2001 From: magicbelette Date: Fri, 5 Feb 2021 19:58:24 +0100 Subject: [PATCH] Add the ability to call get_user operation with username --- models/users.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/models/users.js b/models/users.js index 0c8eac69f..f2a98c1b5 100644 --- a/models/users.js +++ b/models/users.js @@ -1460,13 +1460,18 @@ if (Meteor.isServer) { * * @description Only the admin user (the first user) can call the REST API. * - * @param {string} userId the user ID + * @param {string} userId the user ID or username * @return_type Users */ JsonRoutes.add('GET', '/api/users/:userId', function(req, res) { try { Authentication.checkUserId(req.userId); - const id = req.params.userId; + let id = req.params.userId; + let user = Meteor.users.findOne({ _id: id }); + if (!user) { + user = Meteor.users.findOne({ username: id }); + id = user._id; + } // get all boards where the user is member of let boards = Boards.find( @@ -1485,7 +1490,6 @@ if (Meteor.isServer) { return u; }); - const user = Meteor.users.findOne({ _id: id }); user.boards = boards; JsonRoutes.sendResult(res, { code: 200,