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 | Bin 642373 -> 642477 bytes assets/schemas.json | Bin 26419270 -> 26419350 bytes src/api/routes/guilds/#guild_id/channels.ts | 33 +++++++++++++------- src/util/schemas/ChannelReorderSchema.ts | 2 +- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/assets/openapi.json b/assets/openapi.json index c3124e1e755a0966205e8c635dc6e5c8f78d374f..09be25e69c384e06469ba68fe0dda04dc18a206b 100644 GIT binary patch delta 102 zcmX>)OMUHZ^@bM4ElkX-rspkYR+^rW!pJ&(!6Ihm>2lwgIHsRp#4J0#p_kcXdV@Wq x(R7CnpppyeKqYT=nI)!Aa9}ZL|GbI`h?#+y1&CRJm<@>8ftX|a=T)3RN&pW4DvtmF delta 80 zcmZ2GTm9%P^@bM4ElkX-reBa?^q<~f&uBC~;SjUh^!4jlBqtwm7MlE_pKrRs4Q7G% d=+#U>%nZaVK+FonY(UHo#2nkBS91m_0RRklA6ozb diff --git a/assets/schemas.json b/assets/schemas.json index 44c77a771df04a52394616f988d1c0f5e8204b19..e95b0ba737ed348285d8c08dbbdf95a950c77c94 100755 GIT binary patch delta 1742 zcmWmEReTm?07miOM~xT*Mh_Om=pHq4)Tq(jqnnLx81TY?0Rw~22E;B5>;Md`Sxm77 z#a0x%m0 zk4(NJD#cKu2^!XQZPGx}qDp zqX&8-1HI52eb5*Ekcs{nfPolMAWmZp_yZQ7W&rkzPM?M(;M(R4DMO}gn~x|(jLyXj$inhev+ z^frA=U(?TIn*L^h8E6KX!6wTLF+X0DlM=9>j(p;=@Wnq)oe4tY&SbhzS(JZncb$q>@j=IK2vD+n*)&(98%X+pP|5%U6c9TY2BJzKKHZdVGGBq?!849l?sE3pczu?ERli*;C!fD~*%DmG#hHX{vN zuoc^oj_ufiJ8&oN!rj=34BUfV*o}K}ANF7`_F+E`;C?)S2k{UN;t(FjBX|^#;V_Qi zaXf*eIELeR5-0E!p2jnH7SG{%ynq++5?;nhWa1QF!K-);uj4e{z!|)Wx9~Qy@DAR^ zdpL{taSqw|03YH!KElWN1Q&1-pW-uI!exApFYqP4!WCS_*Z2nC;yZkgAMhit;V1lz z>-Yt~;y3(`KX3y#@hASmE!@W6_y_;uzqHKkNIFaolhZ_*Tqd{4WAd7OCci0QqD?^) zV+xsAQ`i(SMNKhN+>|gSO(_#+N}DpKtSM*WO?gwnR5X=LWmCmeHPuXYQ^V9WwM=bO z$J90TOnuY9G&GG&W7EVmHO)+O)50W}mZp_yZQ7W&rk!bTI+%{8lj&@_m_*anbTi#e z57W~mnO>&1>0|nuex|<}U2H1X0cgfmYQW|xmjUWnpI}CS!0sTTC>iqH^HQs f4JOrWG@Hz3lV-M !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; }[];