diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-12-30 18:07:56 +1100 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-12-30 18:07:56 +1100 |
commit | a1c07173bbae28676a6b72dce0716fdea45217f3 (patch) | |
tree | 75224b9849e5f9145050042e85bdf1fedcfd8ae7 /src/api | |
parent | Fix `npm ci`!!! (diff) | |
download | server-a1c07173bbae28676a6b72dce0716fdea45217f3.tar.xz |
Fix new roles having duplicate positions
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/routes/guilds/#guild_id/roles/#role_id/index.ts | 9 | ||||
-rw-r--r-- | src/api/routes/guilds/#guild_id/roles/index.ts | 10 |
2 files changed, 13 insertions, 6 deletions
diff --git a/src/api/routes/guilds/#guild_id/roles/#role_id/index.ts b/src/api/routes/guilds/#guild_id/roles/#role_id/index.ts index e274e3d0..cd5959ff 100644 --- a/src/api/routes/guilds/#guild_id/roles/#role_id/index.ts +++ b/src/api/routes/guilds/#guild_id/roles/#role_id/index.ts @@ -63,13 +63,12 @@ router.patch( ); else body.icon = undefined; - const role = Role.create({ + const role = await Role.findOneOrFail({ where: { id: role_id, guild: { id: guild_id } } }); + role.assign({ ...body, - id: role_id, - guild_id, permissions: String( - req.permission!.bitfield & BigInt(body.permissions || "0"), - ), + req.permission!.bitfield & BigInt(body.permissions || "0") + ) }); await Promise.all([ diff --git a/src/api/routes/guilds/#guild_id/roles/index.ts b/src/api/routes/guilds/#guild_id/roles/index.ts index 60399d1b..534a5967 100644 --- a/src/api/routes/guilds/#guild_id/roles/index.ts +++ b/src/api/routes/guilds/#guild_id/roles/index.ts @@ -10,8 +10,10 @@ import { DiscordApiErrors, RoleModifySchema, RolePositionUpdateSchema, + Snowflake, } from "@fosscord/util"; import { route } from "@fosscord/api"; +import { Not } from "typeorm"; const router: Router = Router(); @@ -40,7 +42,7 @@ router.post( const role = Role.create({ // values before ...body are default and can be overriden - position: 0, + position: 1, hoist: false, color: 0, mentionable: false, @@ -53,10 +55,16 @@ router.post( tags: undefined, icon: undefined, unicode_emoji: undefined, + id: Snowflake.generate(), }); await Promise.all([ role.save(), + // Move all existing roles up one position, to accommodate the new role + Role.createQueryBuilder('roles') + .where({ guild: { id: guild_id }, name: Not("@everyone"), id: Not(role.id) }) + .update({ position: () => 'position + 1' }) + .execute(), emitEvent({ event: "GUILD_ROLE_CREATE", guild_id, |