From 321eea2d8b96264f14e50d0a6e04ebf3ed68b97f Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Tue, 23 Jan 2024 01:36:20 +0530 Subject: [PATCH] avoid using let --- apps/meteor/app/api/server/v1/users.ts | 27 +++++++------------ .../message/content/reactions/Reaction.tsx | 2 +- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/apps/meteor/app/api/server/v1/users.ts b/apps/meteor/app/api/server/v1/users.ts index 4d1b1caed065..063e9f6ad188 100644 --- a/apps/meteor/app/api/server/v1/users.ts +++ b/apps/meteor/app/api/server/v1/users.ts @@ -1261,28 +1261,21 @@ API.v1.addRoute( { authRequired: true, validateParams: isUsersGetNamesParamsGETProps }, { async get() { - let users: Pick[] = []; + const options = { + projection: { + name: 1, + username: 1, + }, + }; if ('userIds' in this.queryParams) { - users = await Users.findByIds(this.queryParams.userIds, { - projection: { - name: 1, - username: 1, - }, - }).toArray(); - } - - if ('usernames' in this.queryParams) { - users = await Users.findByUsernames(this.queryParams.usernames, { - projection: { - name: 1, - username: 1, - }, - }).toArray(); + return API.v1.success({ + users: await Users.findByIds(this.queryParams.userIds, options).toArray(), + }); } return API.v1.success({ - users, + users: await Users.findByUsernames(this.queryParams.usernames, options).toArray(), }); }, }, diff --git a/apps/meteor/client/components/message/content/reactions/Reaction.tsx b/apps/meteor/client/components/message/content/reactions/Reaction.tsx index 065667b33b9c..0275e2dadab4 100644 --- a/apps/meteor/client/components/message/content/reactions/Reaction.tsx +++ b/apps/meteor/client/components/message/content/reactions/Reaction.tsx @@ -61,7 +61,7 @@ const Reaction = ({ hasReacted, counter, name, names, ...props }: ReactionProps) } const users: string[] = showRealName - ? (await getNames({ usernames: names }))?.users?.map((user) => user.name) || names.map((name) => `@${name}`) + ? (await getNames({ usernames: names }))?.users?.map((user) => user.name || '') || names.map((name) => `@${name}`) : names.map((name) => `@${name}`); return users;