summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMathMan05 <mathmanrm@gmail.com>2025-04-30 19:10:07 -0500
committerRory& <root@rory.gay>2025-05-28 08:46:35 +0200
commitaf70a7f21bb0c0629f56d8590feddc3adde85580 (patch)
tree1d93f73cc3523519e76fffd4721bf8a0f75a2439 /src
parentforgot to test on rebuild (diff)
downloadserver-ts-af70a7f21bb0c0629f56d8590feddc3adde85580.tar.xz
channel is nullable fixes
Diffstat (limited to 'src')
-rw-r--r--src/api/routes/guilds/#guild_id/channels.ts33
-rw-r--r--src/util/schemas/ChannelReorderSchema.ts2
2 files changed, 22 insertions, 13 deletions
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; }[];