From af70a7f21bb0c0629f56d8590feddc3adde85580 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Wed, 30 Apr 2025 19:10:07 -0500 Subject: [PATCH] channel is nullable fixes --- assets/openapi.json | 5 +++- assets/schemas.json | 5 +++- src/api/routes/guilds/#guild_id/channels.ts | 33 +++++++++++++-------- src/util/schemas/ChannelReorderSchema.ts | 2 +- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/assets/openapi.json b/assets/openapi.json index c3124e1e..09be25e6 100644 --- a/assets/openapi.json +++ b/assets/openapi.json @@ -5171,7 +5171,10 @@ "type": "boolean" }, "parent_id": { - "type": "string" + "type": [ + "null", + "string" + ] } }, "additionalProperties": false, diff --git a/assets/schemas.json b/assets/schemas.json index 44c77a77..e95b0ba7 100755 --- a/assets/schemas.json +++ b/assets/schemas.json @@ -59954,7 +59954,10 @@ "type": "boolean" }, "parent_id": { - "type": "string" + "type": [ + "null", + "string" + ] } }, "additionalProperties": false, 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; }[];