1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-06 10:52:31 +01:00

fix(api): prevent @everyone role duplication

If user already has @everyone role, then don't push it to the array
This commit is contained in:
Nobody 2022-03-08 09:25:14 -03:00 committed by Erkin Alp Güney
parent 4a617faf02
commit b20746bd17

View File

@ -30,7 +30,7 @@ router.patch("/", route({ body: "MemberChangeSchema" }), async (req: Request, re
permission.hasThrow("MANAGE_ROLES");
const everyone = await Role.findOneOrFail({ guild_id: guild_id, name: "@everyone", position: 0 });
body.roles.push(everyone?.id);
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
}