Skip to content

Commit

Permalink
avoid using let
Browse files Browse the repository at this point in the history
  • Loading branch information
yash-rajpal committed Jan 22, 2024
1 parent 2b0cab0 commit 321eea2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
27 changes: 10 additions & 17 deletions apps/meteor/app/api/server/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1261,28 +1261,21 @@ API.v1.addRoute(
{ authRequired: true, validateParams: isUsersGetNamesParamsGETProps },
{
async get() {
let users: Pick<IUser, '_id' | 'username' | 'name'>[] = [];
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(),
});
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 321eea2

Please sign in to comment.