diff options
author | Erkin Alp Güney <erkinalp9035@gmail.com> | 2022-03-08 22:46:14 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-08 22:46:14 +0300 |
commit | fbe177c1cab99c63b2c80f6b51fc1688668cb533 (patch) | |
tree | a44382bd76be49018cb5e1ac1ecbaff855fe9c43 /api/src | |
parent | Change premium_since to bigint (diff) | |
parent | Merge branch 'master' into fix/ban-list (diff) | |
download | server-fbe177c1cab99c63b2c80f6b51fc1688668cb533.tar.xz |
Merge pull request #675 from nobodylabs/fix/ban-list
Fix(api): working ban list
Diffstat (limited to 'api/src')
-rw-r--r-- | api/src/routes/guilds/#guild_id/bans.ts | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/api/src/routes/guilds/#guild_id/bans.ts b/api/src/routes/guilds/#guild_id/bans.ts index 99adf5ae..1ce41936 100644 --- a/api/src/routes/guilds/#guild_id/bans.ts +++ b/api/src/routes/guilds/#guild_id/bans.ts @@ -33,21 +33,32 @@ router.get("/", route({ permission: "BAN_MEMBERS" }), async (req: Request, res: const { guild_id } = req.params; let bans = await Ban.find({ guild_id: guild_id }); - - // pretend self-bans don't exist to prevent victim chasing - bans.filter(ban => ban.user_id !== ban.executor_id); - - /* Create an separate array to modify and return */ - - var bans_array: object[] = []; + let promisesToAwait: object[] = []; + const bansObj: object[] = []; - for (const ban of bans) { - const banned_user = await User.getPublicUser(ban.user_id); - var ban_object = {user: {id: banned_user.id, username: banned_user.username, avatar: banned_user.avatar, discriminator: banned_user.discriminator, public_flags: banned_user.public_flags}, reason: ban.reason}; - bans_array.push(ban_object) - } - - return res.json(bans_array); + bans.filter((ban) => ban.user_id !== ban.executor_id); // pretend self-bans don't exist to prevent victim chasing + + bans.forEach((ban) => { + promisesToAwait.push(User.getPublicUser(ban.user_id)); + }); + + const bannedUsers: object[] = await Promise.all(promisesToAwait); + + bans.forEach((ban, index) => { + const user = bannedUsers[index] as User; + bansObj.push({ + reason: ban.reason, + user: { + username: user.username, + discriminator: user.discriminator, + id: user.id, + avatar: user.avatar, + public_flags: user.public_flags + } + }); + }); + + return res.json(bansObj); }); router.get("/:user", route({ permission: "BAN_MEMBERS" }), async (req: Request, res: Response) => { |