diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-03 13:23:20 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-03 13:23:20 +0200 |
commit | 4484c75ee2e59986c13405800566e9a49a11b1a6 (patch) | |
tree | 02844f3dc7bae625936a39727d58a7e0d26a2d7b /api/src/routes/guilds/#guild_id | |
parent | :bug: fix member has no roles in guild create (diff) | |
download | server-4484c75ee2e59986c13405800566e9a49a11b1a6.tar.xz |
:bug: fix member roles + list
Diffstat (limited to 'api/src/routes/guilds/#guild_id')
-rw-r--r-- | api/src/routes/guilds/#guild_id/members/#member_id/index.ts | 8 |
1 files changed, 2 insertions, 6 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 aef1c6dc..66c508a2 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 @@ -30,18 +30,14 @@ router.patch("/", check(MemberChangeSchema), async (req: Request, res: Response) const { guild_id, member_id } = req.params; const body = req.body as MemberChangeSchema; + const member = await Member.findOneOrFail({ where: { id: member_id, guild_id }, relations: ["roles", "user"] }); const permission = await getPermission(req.user_id, guild_id); if (body.roles) { permission.hasThrow("MANAGE_ROLES"); - - const roles = await Role.find({ id: In(body.roles) }); - if (body.roles.length !== roles.length) throw new HTTPError("Roles not found", 404); + member.roles = body.roles.map((x) => new Role({ id: x })); // foreign key constraint will fail if role doesn't exist } - const member = await Member.findOneOrFail({ id: member_id, guild_id }); - member.assign(req.body); - Promise.all([ member.save(), emitEvent({ |