diff options
author | Nobody <17956512+n0bodysec@users.noreply.github.com> | 2022-03-08 12:15:38 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-08 12:15:38 -0300 |
commit | b9be054241786361cfbb678d5b4a1cc580d3eb22 (patch) | |
tree | 50abc4b69194837f8087e7d6580e993869cc68bb /api/src/routes/guilds | |
parent | fix(api): working ban list (diff) | |
parent | Temporary notes fix (diff) | |
download | server-b9be054241786361cfbb678d5b4a1cc580d3eb22.tar.xz |
Merge branch 'master' into fix/ban-list
Diffstat (limited to 'api/src/routes/guilds')
-rw-r--r-- | api/src/routes/guilds/#guild_id/members/#member_id/index.ts | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/api/src/routes/guilds/#guild_id/members/#member_id/index.ts b/api/src/routes/guilds/#guild_id/members/#member_id/index.ts index 24c74af7..34836292 100644 --- a/api/src/routes/guilds/#guild_id/members/#member_id/index.ts +++ b/api/src/routes/guilds/#guild_id/members/#member_id/index.ts @@ -25,13 +25,19 @@ router.patch("/", route({ body: "MemberChangeSchema" }), async (req: Request, re const member = await Member.findOneOrFail({ where: { id: member_id, guild_id }, relations: ["roles", "user"] }); const permission = await getPermission(req.user_id, guild_id); + const everyone = await Role.findOneOrFail({ guild_id: guild_id, name: "@everyone", position: 0 }); if (body.roles) { permission.hasThrow("MANAGE_ROLES"); + + if (body.roles.indexOf(everyone.id) === -1) body.roles.push(everyone.id); member.roles = body.roles.map((x) => new Role({ id: x })); // foreign key constraint will fail if role doesn't exist } await member.save(); + + member.roles = member.roles.filter((x) => x.id !== everyone.id); + // do not use promise.all as we have to first write to db before emitting the event to catch errors await emitEvent({ event: "GUILD_MEMBER_UPDATE", |