mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-06 19:02:33 +01:00
fix(api): working ban list
We should never use await inside loops
This commit is contained in:
parent
39a3eee45d
commit
4294c6a875
@ -33,17 +33,32 @@ router.get("/", route({ permission: "BAN_MEMBERS" }), async (req: Request, res:
|
|||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
|
|
||||||
let bans = await Ban.find({ guild_id: guild_id });
|
let bans = await Ban.find({ guild_id: guild_id });
|
||||||
|
let promisesToAwait: object[] = [];
|
||||||
|
const bansObj: object[] = [];
|
||||||
|
|
||||||
/* Filter secret from database registry.*/
|
bans.filter((ban) => ban.user_id !== ban.executor_id); // pretend self-bans don't exist to prevent victim chasing
|
||||||
|
|
||||||
bans.filter(ban => ban.user_id !== ban.executor_id);
|
bans.forEach((ban) => {
|
||||||
// pretend self-bans don't exist to prevent victim chasing
|
promisesToAwait.push(User.getPublicUser(ban.user_id));
|
||||||
|
|
||||||
bans.forEach((registry: BanRegistrySchema) => {
|
|
||||||
delete registry.ip;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.json(bans);
|
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) => {
|
router.get("/:user", route({ permission: "BAN_MEMBERS" }), async (req: Request, res: Response) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user