diff --git a/src/api/routes/guilds/#guild_id/channels.ts b/src/api/routes/guilds/#guild_id/channels.ts
index 179128eb..a38b9ae7 100644
--- a/src/api/routes/guilds/#guild_id/channels.ts
+++ b/src/api/routes/guilds/#guild_id/channels.ts
@@ -120,8 +120,9 @@ router.patch(
(x) => !body.find((c) => c.id == x),
);
- const withParents = body.filter((x) => x.parent_id != undefined);
- const withPositions = body.filter((x) => x.position != undefined);
+ const withParents = body.filter((x) => x.parent_id !== undefined);
+ console.log(body);
+ const withPositions = body.filter((x) => x.position !== undefined);
await Promise.all(
withPositions.map(async (opt) => {
@@ -148,22 +149,30 @@ router.patch(
Channel.findOneOrFail({
where: { id: opt.id },
}),
- Channel.findOneOrFail({
- where: { id: opt.parent_id as string },
- select: { permission_overwrites: true, id: true },
- }),
+ opt.parent_id
+ ? Channel.findOneOrFail({
+ where: { id: opt.parent_id },
+ select: {
+ permission_overwrites: true,
+ id: true,
+ },
+ })
+ : null,
]);
- if (opt.lock_permissions)
+ if (opt.lock_permissions && parent)
await Channel.update(
{ id: channel.id },
{ permission_overwrites: parent.permission_overwrites },
);
-
- const parentPos = notMentioned.indexOf(parent.id);
- notMentioned.splice(parentPos + 1, 0, channel.id);
- channel.position = (parentPos + 1) as number;
- channel.parent = parent;
+ if (parent) {
+ const parentPos = notMentioned.indexOf(parent.id);
+ notMentioned.splice(parentPos + 1, 0, channel.id);
+ channel.position = (parentPos + 1) as number;
+ }
+ channel.parent = parent || undefined;
+ channel.parent_id = null;
+ console.log(channel.parent);
await channel.save();
await emitEvent({
diff --git a/src/util/schemas/ChannelReorderSchema.ts b/src/util/schemas/ChannelReorderSchema.ts
index a026608a..657ed420 100644
--- a/src/util/schemas/ChannelReorderSchema.ts
+++ b/src/util/schemas/ChannelReorderSchema.ts
@@ -20,5 +20,5 @@ export type ChannelReorderSchema = {
id: string;
position?: number;
lock_permissions?: boolean;
- parent_id?: string;
+ parent_id?: null | string;
}[];
|