diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-12-21 15:17:06 +1100 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-12-21 15:17:06 +1100 |
commit | b96d851646b0acd9ad0df140823042582ecd1274 (patch) | |
tree | d6de3b61a19f33efb90e9d8d6555220deae94f16 | |
parent | Fix guild features being undefined if not using defaultFeatures (diff) | |
download | server-b96d851646b0acd9ad0df140823042582ecd1274.tar.xz |
Fix the roles bug
-rw-r--r-- | src/api/routes/guilds/#guild_id/members/#member_id/index.ts | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/api/routes/guilds/#guild_id/members/#member_id/index.ts b/src/api/routes/guilds/#guild_id/members/#member_id/index.ts index 8e6c3ce7..f1d343d9 100644 --- a/src/api/routes/guilds/#guild_id/members/#member_id/index.ts +++ b/src/api/routes/guilds/#guild_id/members/#member_id/index.ts @@ -36,17 +36,20 @@ router.patch("/", route({ body: "MemberChangeSchema" }), async (req: Request, re const permission = await getPermission(req.user_id, guild_id); const everyone = await Role.findOneOrFail({ where: { guild_id: guild_id, name: "@everyone", position: 0 } }); - if (body.roles) { + if (body.avatar) body.avatar = await handleFile(`/guilds/${guild_id}/users/${member_id}/avatars`, body.avatar as string); + + member.assign(body); + + if ('roles' in body) { permission.hasThrow("MANAGE_ROLES"); + body.roles = body.roles || []; + body.roles.filter(x => !!x); + if (body.roles.indexOf(everyone.id) === -1) body.roles.push(everyone.id); member.roles = body.roles.map((x) => Role.create({ id: x })); // foreign key constraint will fail if role doesn't exist } - if (body.avatar) body.avatar = await handleFile(`/guilds/${guild_id}/users/${member_id}/avatars`, body.avatar as string); - - member.assign(body); - await member.save(); member.roles = member.roles.filter((x) => x.id !== everyone.id); |