From 6bf4637a03c6d251cf43542788de7d3d02374077 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Wed, 4 Oct 2023 23:48:00 +1100 Subject: fucking postgres --- src/api/routes/guilds/#guild_id/channels.ts | 9 ++++++--- src/gateway/opcodes/Identify.ts | 2 +- src/util/entities/Channel.ts | 12 ++++++------ src/util/entities/Guild.ts | 16 ++++++++-------- .../mariadb/1696420827239-guildChannelOrdering.ts | 4 ++-- .../mysql/1696420827239-guildChannelOrdering.ts | 4 ++-- .../postgres/1696420827239-guildChannelOrdering.ts | 4 ++-- 7 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/api/routes/guilds/#guild_id/channels.ts b/src/api/routes/guilds/#guild_id/channels.ts index 671d07ea..68208fee 100644 --- a/src/api/routes/guilds/#guild_id/channels.ts +++ b/src/api/routes/guilds/#guild_id/channels.ts @@ -98,11 +98,11 @@ router.patch( const guild = await Guild.findOneOrFail({ where: { id: guild_id }, - select: { channelOrdering: true }, + select: { channel_ordering: true }, }); // The channels not listed for this query - const notMentioned = guild.channelOrdering.filter( + const notMentioned = guild.channel_ordering.filter( (x) => !body.find((c) => c.id == x), ); @@ -159,7 +159,10 @@ router.patch( }), ); - await Guild.update({ id: guild_id }, { channelOrdering: notMentioned }); + await Guild.update( + { id: guild_id }, + { channel_ordering: notMentioned }, + ); return res.sendStatus(204); }, diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts index 6de5191c..330ce561 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts @@ -273,7 +273,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { return perms.has("VIEW_CHANNEL"); }) .map((channel) => { - channel.position = member.guild.channelOrdering.indexOf( + channel.position = member.guild.channel_ordering.indexOf( channel.id, ); return channel; diff --git a/src/util/entities/Channel.ts b/src/util/entities/Channel.ts index 8efddc73..169eab3d 100644 --- a/src/util/entities/Channel.ts +++ b/src/util/entities/Channel.ts @@ -215,7 +215,7 @@ export class Channel extends BaseClass { where: { id: channel.guild_id }, select: { features: !opts?.skipNameChecks, - channelOrdering: true, + channel_ordering: true, id: true, }, }); @@ -472,27 +472,27 @@ export class Channel extends BaseClass { if (!guild) guild = await Guild.findOneOrFail({ where: { id: guild_id }, - select: { channelOrdering: true }, + select: { channel_ordering: true }, }); - return guild.channelOrdering.findIndex((id) => channel_id == id); + return guild.channel_ordering.findIndex((id) => channel_id == id); } static async getOrderedChannels(guild_id: string, guild?: Guild) { if (!guild) guild = await Guild.findOneOrFail({ where: { id: guild_id }, - select: { channelOrdering: true }, + select: { channel_ordering: true }, }); const channels = await Promise.all( - guild.channelOrdering.map((id) => + guild.channel_ordering.map((id) => Channel.findOneOrFail({ where: { id } }), ), ); return channels.reduce((r, v) => { - v.position = (guild as Guild).channelOrdering.indexOf(v.id); + v.position = (guild as Guild).channel_ordering.indexOf(v.id); r[v.position] = v; return r; }, [] as Array); diff --git a/src/util/entities/Guild.ts b/src/util/entities/Guild.ts index cf28f4ae..fcd6b729 100644 --- a/src/util/entities/Guild.ts +++ b/src/util/entities/Guild.ts @@ -298,7 +298,7 @@ export class Guild extends BaseClass { premium_progress_bar_enabled: boolean = false; @Column({ select: false, type: "simple-array" }) - channelOrdering: string[]; + channel_ordering: string[]; static async createGuild(body: { name?: string; @@ -327,7 +327,7 @@ export class Guild extends BaseClass { description: "", welcome_channels: [], }, - channelOrdering: [], + channel_ordering: [], afk_timeout: Config.get().defaults.guild.afkTimeout, default_message_notifications: @@ -430,20 +430,20 @@ export class Guild extends BaseClass { if (!guild) guild = await Guild.findOneOrFail({ where: { id: guild_id }, - select: { channelOrdering: true }, + select: { channel_ordering: true }, }); let position; if (typeof insertPoint == "string") - position = guild.channelOrdering.indexOf(insertPoint) + 1; + position = guild.channel_ordering.indexOf(insertPoint) + 1; else position = insertPoint; - guild.channelOrdering.remove(channel_id); + guild.channel_ordering.remove(channel_id); - guild.channelOrdering.splice(position, 0, channel_id); + guild.channel_ordering.splice(position, 0, channel_id); await Guild.update( { id: guild_id }, - { channelOrdering: guild.channelOrdering }, + { channel_ordering: guild.channel_ordering }, ); return position; } @@ -452,7 +452,7 @@ export class Guild extends BaseClass { return { ...this, unavailable: this.unavailable == false ? undefined : true, - channelOrdering: undefined, + channel_ordering: undefined, }; } } diff --git a/src/util/migration/mariadb/1696420827239-guildChannelOrdering.ts b/src/util/migration/mariadb/1696420827239-guildChannelOrdering.ts index bbab72e7..083f3680 100644 --- a/src/util/migration/mariadb/1696420827239-guildChannelOrdering.ts +++ b/src/util/migration/mariadb/1696420827239-guildChannelOrdering.ts @@ -11,7 +11,7 @@ export class guildChannelOrdering1696420827239 implements MigrationInterface { ); await queryRunner.query( - `ALTER TABLE guilds ADD channelOrdering text NOT NULL DEFAULT '[]'`, + `ALTER TABLE guilds ADD channel_ordering text NOT NULL DEFAULT '[]'`, ); for (const guild_id of guilds.records.map((x) => x.id)) { @@ -26,7 +26,7 @@ export class guildChannelOrdering1696420827239 implements MigrationInterface { channels.sort((a, b) => a.position - b.position); await queryRunner.query( - `UPDATE guilds SET channelOrdering = ? WHERE id = ?`, + `UPDATE guilds SET channel_ordering = ? WHERE id = ?`, [JSON.stringify(channels.map((x) => x.id)), guild_id], ); } diff --git a/src/util/migration/mysql/1696420827239-guildChannelOrdering.ts b/src/util/migration/mysql/1696420827239-guildChannelOrdering.ts index bbab72e7..083f3680 100644 --- a/src/util/migration/mysql/1696420827239-guildChannelOrdering.ts +++ b/src/util/migration/mysql/1696420827239-guildChannelOrdering.ts @@ -11,7 +11,7 @@ export class guildChannelOrdering1696420827239 implements MigrationInterface { ); await queryRunner.query( - `ALTER TABLE guilds ADD channelOrdering text NOT NULL DEFAULT '[]'`, + `ALTER TABLE guilds ADD channel_ordering text NOT NULL DEFAULT '[]'`, ); for (const guild_id of guilds.records.map((x) => x.id)) { @@ -26,7 +26,7 @@ export class guildChannelOrdering1696420827239 implements MigrationInterface { channels.sort((a, b) => a.position - b.position); await queryRunner.query( - `UPDATE guilds SET channelOrdering = ? WHERE id = ?`, + `UPDATE guilds SET channel_ordering = ? WHERE id = ?`, [JSON.stringify(channels.map((x) => x.id)), guild_id], ); } diff --git a/src/util/migration/postgres/1696420827239-guildChannelOrdering.ts b/src/util/migration/postgres/1696420827239-guildChannelOrdering.ts index 82085991..6fc80ffd 100644 --- a/src/util/migration/postgres/1696420827239-guildChannelOrdering.ts +++ b/src/util/migration/postgres/1696420827239-guildChannelOrdering.ts @@ -11,7 +11,7 @@ export class guildChannelOrdering1696420827239 implements MigrationInterface { ); await queryRunner.query( - `ALTER TABLE guilds ADD channelOrdering text NOT NULL DEFAULT '[]'`, + `ALTER TABLE guilds ADD channel_ordering text NOT NULL DEFAULT '[]'`, ); for (const guild_id of guilds.records.map((x) => x.id)) { @@ -26,7 +26,7 @@ export class guildChannelOrdering1696420827239 implements MigrationInterface { channels.sort((a, b) => a.position - b.position); await queryRunner.query( - `UPDATE guilds SET channelOrdering = $1 WHERE id = $2`, + `UPDATE guilds SET channel_ordering = $1 WHERE id = $2`, [JSON.stringify(channels.map((x) => x.id)), guild_id], ); } -- cgit 1.4.1