summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMathMan05 <mathmanrm@gmail.com>2025-04-30 22:49:40 -0500
committerRory& <root@rory.gay>2025-05-28 08:46:35 +0200
commit04ddfadbb6287097c26037a4a151bdb18c2fc49e (patch)
treeaab231451e9eb77a1ecfc60c9d81c20cfa9b6bb1 /src
parentfix another stupid bug (diff)
downloadserver-ts-04ddfadbb6287097c26037a4a151bdb18c2fc49e.tar.xz
sort array to make algorithm happy
Diffstat (limited to 'src')
-rw-r--r--src/api/routes/guilds/#guild_id/channels.ts21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/api/routes/guilds/#guild_id/channels.ts b/src/api/routes/guilds/#guild_id/channels.ts

index a2add70fe..2eccb3e1d 100644 --- a/src/api/routes/guilds/#guild_id/channels.ts +++ b/src/api/routes/guilds/#guild_id/channels.ts
@@ -108,13 +108,32 @@ router.patch( async (req: Request, res: Response) => { // changes guild channel position const { guild_id } = req.params; - const body = req.body as ChannelReorderSchema; + let body = req.body as ChannelReorderSchema; const guild = await Guild.findOneOrFail({ where: { id: guild_id }, select: { channel_ordering: true }, }); + body = body.sort((a, b) => { + const apos = + a.position || + (a.parent_id + ? guild.channel_ordering.findIndex( + (_) => _ === a.parent_id, + ) + 1 + : 0); + const bpos = + b.position || + (b.parent_id + ? guild.channel_ordering.findIndex( + (_) => _ === b.parent_id, + ) + 1 + : 0); + console.log(apos, bpos); + return apos - bpos; + }); + // The channels not listed for this query const notMentioned = guild.channel_ordering.filter( (x) => !body.find((c) => c.id == x),