🐛 fix member roles + list

This commit is contained in:
Flam3rboy
2021-09-03 13:23:20 +02:00
parent f83f4416b8
commit a446837679
4 changed files with 9 additions and 13 deletions
@@ -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({