mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-10 04:32:35 +01:00
Fix new roles having duplicate positions
This commit is contained in:
parent
b4c222c4eb
commit
17e93b7daa
@ -63,13 +63,12 @@ router.patch(
|
|||||||
);
|
);
|
||||||
else body.icon = undefined;
|
else body.icon = undefined;
|
||||||
|
|
||||||
const role = Role.create({
|
const role = await Role.findOneOrFail({ where: { id: role_id, guild: { id: guild_id } } });
|
||||||
|
role.assign({
|
||||||
...body,
|
...body,
|
||||||
id: role_id,
|
|
||||||
guild_id,
|
|
||||||
permissions: String(
|
permissions: String(
|
||||||
req.permission!.bitfield & BigInt(body.permissions || "0"),
|
req.permission!.bitfield & BigInt(body.permissions || "0")
|
||||||
),
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
|
@ -10,8 +10,10 @@ import {
|
|||||||
DiscordApiErrors,
|
DiscordApiErrors,
|
||||||
RoleModifySchema,
|
RoleModifySchema,
|
||||||
RolePositionUpdateSchema,
|
RolePositionUpdateSchema,
|
||||||
|
Snowflake,
|
||||||
} from "@fosscord/util";
|
} from "@fosscord/util";
|
||||||
import { route } from "@fosscord/api";
|
import { route } from "@fosscord/api";
|
||||||
|
import { Not } from "typeorm";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
@ -40,7 +42,7 @@ router.post(
|
|||||||
|
|
||||||
const role = Role.create({
|
const role = Role.create({
|
||||||
// values before ...body are default and can be overriden
|
// values before ...body are default and can be overriden
|
||||||
position: 0,
|
position: 1,
|
||||||
hoist: false,
|
hoist: false,
|
||||||
color: 0,
|
color: 0,
|
||||||
mentionable: false,
|
mentionable: false,
|
||||||
@ -53,10 +55,16 @@ router.post(
|
|||||||
tags: undefined,
|
tags: undefined,
|
||||||
icon: undefined,
|
icon: undefined,
|
||||||
unicode_emoji: undefined,
|
unicode_emoji: undefined,
|
||||||
|
id: Snowflake.generate(),
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
role.save(),
|
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({
|
emitEvent({
|
||||||
event: "GUILD_ROLE_CREATE",
|
event: "GUILD_ROLE_CREATE",
|
||||||
guild_id,
|
guild_id,
|
||||||
|
Loading…
Reference in New Issue
Block a user