diff --git "a/src/api/routes/applications/\043application_id/bot/index.ts" "b/src/api/routes/applications/\043application_id/bot/index.ts" index 835225e..901f386 100644 --- "a/src/api/routes/applications/\043application_id/bot/index.ts" +++ "b/src/api/routes/applications/\043application_id/bot/index.ts" @@ -40,7 +40,7 @@ async (req: Request, res: Response) => { const app = await Application.findOneOrFail({ where: { id: req.params.application_id }, - relations: ["owner"], + relations: { owner: true }, }); if (app.owner.id != req.user_id) throw DiscordApiErrors.ACTION_NOT_AUTHORIZED_ON_APPLICATION; @@ -102,7 +102,7 @@ const app = await Application.findOneOrFail({ where: { id: req.params.application_id }, - relations: ["bot", "owner"], + relations: { bot: true, owner: true }, }); if (!app.bot) throw DiscordApiErrors.BOT_ONLY_ENDPOINT; diff --git "a/src/api/routes/applications/\043application_id/index.ts" "b/src/api/routes/applications/\043application_id/index.ts" index 22340e9..1576df8 100644 --- "a/src/api/routes/applications/\043application_id/index.ts" +++ "b/src/api/routes/applications/\043application_id/index.ts" @@ -40,7 +40,7 @@ async (req: Request, res: Response) => { const app = await Application.findOneOrFail({ where: { id: req.params.application_id }, - relations: ["owner", "bot"], + relations: { owner: true, bot: true }, }); if (app.owner.id != req.user_id) throw DiscordApiErrors.ACTION_NOT_AUTHORIZED_ON_APPLICATION; @@ -66,7 +66,7 @@ const app = await Application.findOneOrFail({ where: { id: req.params.application_id }, - relations: ["owner", "bot"], + relations: { owner: true, bot: true }, }); if (app.owner.id != req.user_id) throw DiscordApiErrors.ACTION_NOT_AUTHORIZED_ON_APPLICATION; @@ -114,7 +114,7 @@ async (req: Request, res: Response) => { const app = await Application.findOneOrFail({ where: { id: req.params.application_id }, - relations: ["bot", "owner"], + relations: { bot: true, owner: true }, }); if (app.owner.id != req.user_id) throw DiscordApiErrors.ACTION_NOT_AUTHORIZED_ON_APPLICATION; diff --git a/src/api/routes/applications/@me.ts b/src/api/routes/applications/@me.ts index 1c4a753..7e315a5 100644 --- a/src/api/routes/applications/@me.ts +++ b/src/api/routes/applications/@me.ts @@ -41,7 +41,7 @@ async (req: Request, res: Response) => { const app = await Application.findOneOrFail({ where: { id: req.user_id }, - relations: ["owner", "bot"], + relations: { owner: true, bot: true }, }); return res.json(app); @@ -66,7 +66,7 @@ const app = await Application.findOneOrFail({ where: { id: req.user_id }, - relations: ["owner", "bot"], + relations: { owner: true, bot: true }, }); if (body.icon) { diff --git a/src/api/routes/applications/index.ts b/src/api/routes/applications/index.ts index e719e44..0740c2f 100644 --- a/src/api/routes/applications/index.ts +++ b/src/api/routes/applications/index.ts @@ -35,7 +35,7 @@ async (req: Request, res: Response) => { const results = await Application.find({ where: { owner: { id: req.user_id } }, - relations: ["owner", "bot"], + relations: { owner: true, bot: true }, }); res.json(results).status(200); }, diff --git a/src/api/routes/auth/login.ts b/src/api/routes/auth/login.ts index 8b2e039..466d264 100644 --- a/src/api/routes/auth/login.ts +++ b/src/api/routes/auth/login.ts @@ -68,7 +68,7 @@ const user = await User.findOneOrFail({ where: [{ phone: login }, { email: login }], select: { data: true, id: true, disabled: true, deleted: true, totp_secret: true, mfa_enabled: true, webauthn_enabled: true, security_keys: true, verified: true }, - relations: ["security_keys", "settings"], + relations: { security_keys: true, settings: true }, }).catch(() => { throw FieldErrors({ login: { diff --git a/src/api/routes/auth/mfa/totp.ts b/src/api/routes/auth/mfa/totp.ts index dd10769..366fb10 100644 --- a/src/api/routes/auth/mfa/totp.ts +++ b/src/api/routes/auth/mfa/totp.ts @@ -46,7 +46,7 @@ totp_last_ticket: ticket, }, select: { id: true, totp_secret: true }, - relations: ["settings"], + relations: { settings: true }, }); const backup = await BackupCode.findOne({ diff --git a/src/api/routes/auth/mfa/webauthn.ts b/src/api/routes/auth/mfa/webauthn.ts index 0bc91cf..3359767 100644 --- a/src/api/routes/auth/mfa/webauthn.ts +++ b/src/api/routes/auth/mfa/webauthn.ts @@ -55,7 +55,7 @@ totp_last_ticket: ticket, }, select: { id: true }, - relations: ["settings"], + relations: { settings: true }, }); const ret = await verifyWebAuthnToken(ticket); diff --git "a/src/api/routes/channels/\043channel_id/index.ts" "b/src/api/routes/channels/\043channel_id/index.ts" index 37909a9..4c16798 100644 --- "a/src/api/routes/channels/\043channel_id/index.ts" +++ "b/src/api/routes/channels/\043channel_id/index.ts" @@ -65,7 +65,7 @@ const channel = await Channel.findOneOrFail({ where: { id: channel_id }, - relations: ["recipients"], + relations: { recipients: true }, }); if (channel.type === ChannelType.DM) { diff --git "a/src/api/routes/channels/\043channel_id/messages/\043message_id/index.ts" "b/src/api/routes/channels/\043channel_id/messages/\043message_id/index.ts" index 6457c7e..934efc3 100644 --- "a/src/api/routes/channels/\043channel_id/messages/\043message_id/index.ts" +++ "b/src/api/routes/channels/\043channel_id/messages/\043message_id/index.ts" @@ -72,7 +72,7 @@ const message = await Message.findOneOrFail({ where: { id: message_id, channel_id }, - relations: ["attachments"], + relations: { attachments: true }, }); const permissions = await getPermission(req.user_id, undefined, channel_id); @@ -200,7 +200,7 @@ } const channel = await Channel.findOneOrFail({ where: { id: channel_id }, - relations: ["recipients", "recipients.user"], + relations: { recipients: { user: true } }, }); const embeds = body.embeds || []; @@ -265,7 +265,7 @@ const message = await Message.findOneOrFail({ where: { id: message_id, channel_id }, - relations: ["attachments"], + relations: { attachments: true }, }); const permissions = await getPermission(req.user_id, undefined, channel_id); diff --git "a/src/api/routes/channels/\043channel_id/messages/index.ts" "b/src/api/routes/channels/\043channel_id/messages/index.ts" index 272fa8a..6b18e2c 100644 --- "a/src/api/routes/channels/\043channel_id/messages/index.ts" +++ "b/src/api/routes/channels/\043channel_id/messages/index.ts" @@ -118,25 +118,26 @@ order: { timestamp: "DESC" }, take: limit, where: { channel_id }, - relations: [ - "author", - "webhook", - "application", - "mentions", - "mention_roles", - "mention_channels", - "sticker_items", - "attachments", - "referenced_message", - "referenced_message.author", - "referenced_message.webhook", - "referenced_message.application", - "referenced_message.mentions", - "referenced_message.mention_roles", - "referenced_message.mention_channels", - "referenced_message.sticker_items", - "referenced_message.attachments", - ], + relations: { + author: true, + webhook: true, + application: true, + mentions: true, + mention_roles: true, + mention_channels: true, + sticker_items: true, + attachments: true, + referenced_message: { + author: true, + webhook: true, + application: true, + mentions: true, + mention_roles: true, + mention_channels: true, + sticker_items: true, + attachments: true, + }, + }, }; let messages: Message[]; @@ -265,7 +266,10 @@ if (msg.message_reference!.guild_id) whereOptions.guild_id = msg.message_reference!.guild_id; if (msg.message_reference!.channel_id) whereOptions.channel_id = msg.message_reference!.channel_id; - msg.referenced_message = await Message.findOne({ where: whereOptions, relations: ["author", "mentions", "mention_roles", "mention_channels"] }); + msg.referenced_message = await Message.findOne({ + where: whereOptions, + relations: { author: true, mentions: true, mention_roles: true, mention_channels: true }, + }); }), ); @@ -323,7 +327,7 @@ const channel = await Channel.findOneOrFail({ where: { id: channel_id }, - relations: ["recipients", "recipients.user"], + relations: { recipients: { user: true } }, }); if (!channel.isWritable()) { throw new HTTPError(`Cannot send messages to channel of type ${channel.type}`, 400); @@ -434,7 +438,7 @@ if (!message.member) { message.member = await Member.findOneOrFail({ where: { id: req.user_id, guild_id: message.guild_id }, - relations: ["roles"], + relations: { roles: true }, }); } diff --git "a/src/api/routes/channels/\043channel_id/messages/pins/index.ts" "b/src/api/routes/channels/\043channel_id/messages/pins/index.ts" index 2355c8b..3316d15 100644 --- "a/src/api/routes/channels/\043channel_id/messages/pins/index.ts" +++ "b/src/api/routes/channels/\043channel_id/messages/pins/index.ts" @@ -41,7 +41,7 @@ const message = await Message.findOneOrFail({ where: { id: message_id }, - relations: ["author"], + relations: { author: true }, }); // * in dm channels anyone can pin messages -> only check for guilds @@ -126,7 +126,7 @@ const message = await Message.findOneOrFail({ where: { id: message_id }, - relations: ["author"], + relations: { author: true }, }); if (message.guild_id) req.permission?.hasThrow("MANAGE_MESSAGES"); @@ -173,7 +173,7 @@ const pins = await Message.find({ where: { channel_id: channel_id, pinned_at: Not(IsNull()) }, - relations: ["author"], + relations: { author: true }, order: { pinned_at: "DESC" }, }); diff --git "a/src/api/routes/channels/\043channel_id/messages/search.ts" "b/src/api/routes/channels/\043channel_id/messages/search.ts" index ed1dfc3..1a371cc 100644 --- "a/src/api/routes/channels/\043channel_id/messages/search.ts" +++ "b/src/api/routes/channels/\043channel_id/messages/search.ts" @@ -87,7 +87,7 @@ id: channel_id, }, }, - relations: ["author", "webhook", "application", "mentions", "mention_roles", "mention_channels", "sticker_items", "attachments"], + relations: { author: true, webhook: true, application: true, mentions: true, mention_roles: true, mention_channels: true, sticker_items: true, attachments: true }, skip: offset ? Number(offset) : 0, }; //@ts-ignore diff --git "a/src/api/routes/channels/\043channel_id/pins.ts" "b/src/api/routes/channels/\043channel_id/pins.ts" index 8e56a54..d94d4f3 100644 --- "a/src/api/routes/channels/\043channel_id/pins.ts" +++ "b/src/api/routes/channels/\043channel_id/pins.ts" @@ -42,7 +42,7 @@ const message = await Message.findOneOrFail({ where: { id: message_id }, - relations: ["author"], + relations: { author: true }, }); // * in dm channels anyone can pin messages -> only check for guilds @@ -127,7 +127,7 @@ const message = await Message.findOneOrFail({ where: { id: message_id }, - relations: ["author"], + relations: { author: true }, }); if (message.guild_id) req.permission?.hasThrow("MANAGE_MESSAGES"); @@ -174,7 +174,7 @@ const pins = await Message.find({ where: { channel_id: channel_id, pinned_at: Not(IsNull()) }, - relations: ["author"], + relations: { author: true }, order: { pinned_at: "DESC" }, }); diff --git "a/src/api/routes/channels/\043channel_id/purge.ts" "b/src/api/routes/channels/\043channel_id/purge.ts" index 3a46beb..90f8c6d 100644 --- "a/src/api/routes/channels/\043channel_id/purge.ts" +++ "b/src/api/routes/channels/\043channel_id/purge.ts" @@ -74,7 +74,7 @@ author_id: rights.has("SELF_DELETE_MESSAGES") ? undefined : Not(req.user_id), // if you lack the right of self-deletion, you can't delete your own messages, even in purges }, - relations: ["author", "webhook", "application", "mentions", "mention_roles", "mention_channels", "sticker_items", "attachments"], + relations: { author: true, webhook: true, application: true, mentions: true, mention_roles: true, mention_channels: true, sticker_items: true, attachments: true }, }; const messages = await Message.find(query); diff --git "a/src/api/routes/channels/\043channel_id/recipients.ts" "b/src/api/routes/channels/\043channel_id/recipients.ts" index d0af3b4..c001f84 100644 --- "a/src/api/routes/channels/\043channel_id/recipients.ts" +++ "b/src/api/routes/channels/\043channel_id/recipients.ts" @@ -35,7 +35,7 @@ const { channel_id, user_id } = req.params; const channel = await Channel.findOneOrFail({ where: { id: channel_id }, - relations: ["recipients"], + relations: { recipients: true }, }); if (channel.type !== ChannelType.GROUP_DM) { @@ -85,7 +85,7 @@ const { channel_id, user_id } = req.params; const channel = await Channel.findOneOrFail({ where: { id: channel_id }, - relations: ["recipients"], + relations: { recipients: true }, }); if (!(channel.type === ChannelType.GROUP_DM && (channel.owner_id === req.user_id || user_id === req.user_id))) throw DiscordApiErrors.MISSING_PERMISSIONS; diff --git "a/src/api/routes/channels/\043channel_id/typing.ts" "b/src/api/routes/channels/\043channel_id/typing.ts" index a41ab7f..b5b2cd1 100644 --- "a/src/api/routes/channels/\043channel_id/typing.ts" +++ "b/src/api/routes/channels/\043channel_id/typing.ts" @@ -41,7 +41,7 @@ }); const member = await Member.findOne({ where: { id: user_id, guild_id: channel.guild_id }, - relations: ["roles", "user"], + relations: { roles: true, user: true }, }); await emitEvent({ event: "TYPING_START", diff --git "a/src/api/routes/channels/\043channel_id/webhooks.ts" "b/src/api/routes/channels/\043channel_id/webhooks.ts" index 1c3c980..994bab2 100644 --- "a/src/api/routes/channels/\043channel_id/webhooks.ts" +++ "b/src/api/routes/channels/\043channel_id/webhooks.ts" @@ -40,7 +40,7 @@ const { channel_id } = req.params; const webhooks = await Webhook.find({ where: { channel_id }, - relations: ["user", "channel", "source_channel", "guild", "source_guild", "application"], + relations: { user: true, channel: true, source_channel: true, guild: true, source_guild: true, application: true }, }); return res.json( diff --git "a/src/api/routes/guilds/\043guild_id/emojis.ts" "b/src/api/routes/guilds/\043guild_id/emojis.ts" index f256ce3..5bc0343 100644 --- "a/src/api/routes/guilds/\043guild_id/emojis.ts" +++ "b/src/api/routes/guilds/\043guild_id/emojis.ts" @@ -42,7 +42,7 @@ const emojis = await Emoji.find({ where: { guild_id: guild_id }, - relations: ["user"], + relations: { user: true }, }); return res.json(emojis); @@ -71,7 +71,7 @@ const emoji = await Emoji.findOneOrFail({ where: { guild_id: guild_id, id: emoji_id }, - relations: ["user"], + relations: { user: true }, }); return res.json(emoji); diff --git "a/src/api/routes/guilds/\043guild_id/index.ts" "b/src/api/routes/guilds/\043guild_id/index.ts" index 38cc913..8bb9e7d 100644 --- "a/src/api/routes/guilds/\043guild_id/index.ts" +++ "b/src/api/routes/guilds/\043guild_id/index.ts" @@ -83,7 +83,7 @@ const guild = await Guild.findOneOrFail({ where: { id: guild_id }, - relations: ["emojis", "roles", "stickers"], + relations: { emojis: true, roles: true, stickers: true }, }); // trying to `select` this fails diff --git "a/src/api/routes/guilds/\043guild_id/members/\043member_id/index.ts" "b/src/api/routes/guilds/\043guild_id/members/\043member_id/index.ts" index 81cda18..6a9cfc5 100644 --- "a/src/api/routes/guilds/\043guild_id/members/\043member_id/index.ts" +++ "b/src/api/routes/guilds/\043guild_id/members/\043member_id/index.ts" @@ -44,7 +44,7 @@ const member = await Member.findOneOrFail({ where: { id: member_id, guild_id }, - relations: ["roles", "user"], + relations: { roles: true, user: true }, select: { index: true, // only grab public member props @@ -91,7 +91,7 @@ const member = await Member.findOneOrFail({ where: { id: member_id, guild_id }, - relations: ["roles", "user"], + relations: { roles: true, user: true }, }); const permission = await getPermission(req.user_id, guild_id); diff --git "a/src/api/routes/guilds/\043guild_id/members/\043member_id/nick.ts" "b/src/api/routes/guilds/\043guild_id/members/\043member_id/nick.ts" index 33f8915..87c95aa 100644 --- "a/src/api/routes/guilds/\043guild_id/members/\043member_id/nick.ts" +++ "b/src/api/routes/guilds/\043guild_id/members/\043member_id/nick.ts" @@ -50,7 +50,7 @@ const member = await Member.findOne({ where: { id: member_id, guild_id }, - relations: ["roles"], + relations: { roles: true }, }); res.send(member?.toPublicMember()); diff --git "a/src/api/routes/guilds/\043guild_id/messages/search.ts" "b/src/api/routes/guilds/\043guild_id/messages/search.ts" index 426d0dc..51c9b5a 100644 --- "a/src/api/routes/guilds/\043guild_id/messages/search.ts" +++ "b/src/api/routes/guilds/\043guild_id/messages/search.ts" @@ -80,7 +80,7 @@ id: req.params.guild_id, }, }, - relations: ["author", "webhook", "application", "mentions", "mention_roles", "mention_channels", "sticker_items", "attachments"], + relations: { author: true, webhook: true, application: true, mentions: true, mention_roles: true, mention_channels: true, sticker_items: true, attachments: true }, skip: offset ? Number(offset) : 0, }; //@ts-ignore diff --git "a/src/api/routes/guilds/\043guild_id/profile/index.ts" "b/src/api/routes/guilds/\043guild_id/profile/index.ts" index 7a944b1..b7a071b 100644 --- "a/src/api/routes/guilds/\043guild_id/profile/index.ts" +++ "b/src/api/routes/guilds/\043guild_id/profile/index.ts" @@ -47,7 +47,7 @@ let member = await Member.findOneOrFail({ where: { id: req.user_id, guild_id }, - relations: ["roles", "user"], + relations: { roles: true, user: true }, }); if (body.banner) body.banner = await handleFile(`/guilds/${guild_id}/users/${req.user_id}/avatars`, body.banner as string); diff --git "a/src/api/routes/guilds/\043guild_id/prune.ts" "b/src/api/routes/guilds/\043guild_id/prune.ts" index c8a42b8..7179147 100644 --- "a/src/api/routes/guilds/\043guild_id/prune.ts" +++ "b/src/api/routes/guilds/\043guild_id/prune.ts" @@ -44,7 +44,7 @@ last_message_id: IsNull(), }, ], - relations: ["roles"], + relations: { roles: true }, }); if (!members.length) return []; @@ -53,7 +53,7 @@ const me = await Member.findOneOrFail({ where: { id: user_id, guild_id }, - relations: ["roles"], + relations: { roles: true }, }); const myHighestRole = Math.max(...(me.roles?.map((x) => x.position) || [])); diff --git "a/src/api/routes/guilds/\043guild_id/roles/\043role_id/members.ts" "b/src/api/routes/guilds/\043guild_id/roles/\043role_id/members.ts" index f89d593..6eb6804 100644 --- "a/src/api/routes/guilds/\043guild_id/roles/\043role_id/members.ts" +++ "b/src/api/routes/guilds/\043guild_id/roles/\043role_id/members.ts" @@ -32,7 +32,7 @@ const members = await Member.find({ where: { guild_id }, - relations: ["roles"], + relations: { roles: true }, }); const [add, remove] = arrayPartition(members, (member) => member_ids.includes(member.id) && !member.roles.map((role) => role.id).includes(role_id)); diff --git "a/src/api/routes/guilds/\043guild_id/templates.ts" "b/src/api/routes/guilds/\043guild_id/templates.ts" index 2cc9604..e577cea 100644 --- "a/src/api/routes/guilds/\043guild_id/templates.ts" +++ "b/src/api/routes/guilds/\043guild_id/templates.ts" @@ -86,7 +86,7 @@ const guild = await Guild.findOneOrFail({ where: { id: guild_id }, select: TemplateGuildProjection, - relations: ["roles", "channels"], + relations: { roles: true, channels: true }, }); const exists = await Template.findOne({ where: { id: guild_id }, diff --git "a/src/api/routes/guilds/\043guild_id/webhooks.ts" "b/src/api/routes/guilds/\043guild_id/webhooks.ts" index 81837d3..65fa0ab 100644 --- "a/src/api/routes/guilds/\043guild_id/webhooks.ts" +++ "b/src/api/routes/guilds/\043guild_id/webhooks.ts" @@ -36,7 +36,7 @@ const { guild_id } = req.params; const webhooks = await Webhook.find({ where: { guild_id }, - relations: ["user", "channel", "source_channel", "guild", "source_guild", "application"], + relations: { user: true, channel: true, source_channel: true, guild: true, source_guild: true, application: true }, }); const instanceUrl = Config.get().api.endpointPublic; diff --git a/src/api/routes/interactions/index.ts b/src/api/routes/interactions/index.ts index e997964..5e77217 100644 --- a/src/api/routes/interactions/index.ts +++ b/src/api/routes/interactions/index.ts @@ -69,7 +69,7 @@ interactionData.app_permissions = (await getPermission(body.application_id, body.guild_id, body.channel_id)).bitfield.toString(); const guild = await Guild.findOneOrFail({ where: { id: body.guild_id } }); - const member = await Member.findOneOrFail({ where: { guild_id: body.guild_id, id: req.user_id }, relations: ["user"] }); + const member = await Member.findOneOrFail({ where: { guild_id: body.guild_id, id: req.user_id }, relations: { user: true } }); interactionData.guild = { id: guild.id, @@ -91,7 +91,7 @@ } if (body.type === InteractionType.MessageComponent || body.data.type === InteractionType.ModalSubmit) { - interactionData.message = await Message.findOneOrFail({ where: { id: body.message_id, flags: undefined }, relations: ["author"] }); + interactionData.message = await Message.findOneOrFail({ where: { id: body.message_id, flags: undefined }, relations: { author: true } }); } emitEvent({ diff --git a/src/api/routes/oauth2/applications/@me.ts b/src/api/routes/oauth2/applications/@me.ts index 9cdd47c..e750a62 100644 --- a/src/api/routes/oauth2/applications/@me.ts +++ b/src/api/routes/oauth2/applications/@me.ts @@ -35,7 +35,7 @@ async (req: Request, res: Response) => { const app = await Application.findOneOrFail({ where: { id: req.params.id }, // ...huh? there's no ID in the path... - relations: ["bot", "owner"], + relations: { bot: true, owner: true }, select: { owner: Object.fromEntries(PublicUserProjection.map((x) => [x, true])), }, diff --git a/src/api/routes/oauth2/authorize.ts b/src/api/routes/oauth2/authorize.ts index 849e79b..b989899 100644 --- a/src/api/routes/oauth2/authorize.ts +++ b/src/api/routes/oauth2/authorize.ts @@ -59,7 +59,7 @@ where: { id: client_id as string, }, - relations: ["bot"], + relations: { bot: true }, }); // TODO: use DiscordApiErrors @@ -82,7 +82,7 @@ where: { id: req.user_id, }, - relations: ["guild", "roles", "user"], + relations: { guild: true, roles: true, user: true }, select: { guild: { id: true, name: true, icon: true, mfa_level: true, owner_id: true }, roles: { id: true }, @@ -204,7 +204,7 @@ where: { id: client_id as string, }, - relations: ["bot"], + relations: { bot: true }, }); // TODO: use DiscordApiErrors diff --git a/src/api/routes/sticker-packs/index.ts b/src/api/routes/sticker-packs/index.ts index 749ce02..b5b08cf 100644 --- a/src/api/routes/sticker-packs/index.ts +++ b/src/api/routes/sticker-packs/index.ts @@ -33,7 +33,7 @@ }), async (req: Request, res: Response) => { const sticker_packs = await StickerPack.find({ - relations: ["stickers"], + relations: { stickers: true }, }); res.json({ sticker_packs }); diff --git a/src/api/routes/teams.ts b/src/api/routes/teams.ts index a9380f1..9e900df 100644 --- a/src/api/routes/teams.ts +++ b/src/api/routes/teams.ts @@ -44,7 +44,7 @@ where: { owner_user_id: req.user_id, }, - relations: ["members"], + relations: { members: true }, }); res.send(teams); diff --git "a/src/api/routes/users/\043user_id/delete.ts" "b/src/api/routes/users/\043user_id/delete.ts" index c2286ce..598be97 100644 --- "a/src/api/routes/users/\043user_id/delete.ts" +++ "b/src/api/routes/users/\043user_id/delete.ts" @@ -81,7 +81,7 @@ //leave all group channels const groupChannels = await Channel.find({ where: { type: ChannelType.GROUP_DM }, - relations: ["recipients"], + relations: { recipients: true }, select: { id: true, owner_id: true, diff --git "a/src/api/routes/users/\043user_id/profile.ts" "b/src/api/routes/users/\043user_id/profile.ts" index b100ac3..e4d4d74 100644 --- "a/src/api/routes/users/\043user_id/profile.ts" +++ "b/src/api/routes/users/\043user_id/profile.ts" @@ -33,7 +33,7 @@ where: { id: req.params.id, }, - relations: ["connected_accounts"], + relations: { connected_accounts: true }, }); const mutual_guilds: object[] = []; @@ -72,7 +72,7 @@ guild_id && typeof guild_id == "string" ? await Member.findOneOrFail({ where: { id: req.params.user_id, guild_id: guild_id }, - relations: ["roles"], + relations: { roles: true }, }) : undefined; diff --git "a/src/api/routes/users/\043user_id/relationships.ts" "b/src/api/routes/users/\043user_id/relationships.ts" index 3272ef7..93f1129 100644 --- "a/src/api/routes/users/\043user_id/relationships.ts" +++ "b/src/api/routes/users/\043user_id/relationships.ts" @@ -38,11 +38,11 @@ const requested_relations = await User.findOneOrFail({ where: { id: req.params.user_id }, - relations: ["relationships"], + relations: { relationships: true }, }); const self_relations = await User.findOneOrFail({ where: { id: req.user_id }, - relations: ["relationships"], + relations: { relationships: true }, }); for (const rmem of requested_relations.relationships) { diff --git a/src/api/routes/users/@me/channels.ts b/src/api/routes/users/@me/channels.ts index e13b874..897630c 100644 --- a/src/api/routes/users/@me/channels.ts +++ b/src/api/routes/users/@me/channels.ts @@ -35,7 +35,7 @@ async (req: Request, res: Response) => { const recipients = await Recipient.find({ where: { user_id: req.user_id, closed: false }, - relations: ["channel", "channel.recipients"], + relations: { channel: { recipients: true } }, }); res.json(await Promise.all(recipients.map((r) => DmChannelDTO.from(r.channel, [req.user_id])))); }, diff --git a/src/api/routes/users/@me/guilds.ts b/src/api/routes/users/@me/guilds.ts index 8908656..8fcec95 100644 --- a/src/api/routes/users/@me/guilds.ts +++ b/src/api/routes/users/@me/guilds.ts @@ -34,7 +34,7 @@ }), async (req: Request, res: Response) => { const members = await Member.find({ - relations: ["guild"], + relations: { guild: true }, where: { id: req.user_id }, }); diff --git a/src/api/routes/users/@me/mentions.ts b/src/api/routes/users/@me/mentions.ts index c2985ca..b63078f 100644 --- a/src/api/routes/users/@me/mentions.ts +++ b/src/api/routes/users/@me/mentions.ts @@ -63,7 +63,7 @@ owner_id: true, }, }, - relations: ["guild", "roles"], + relations: { guild: true, roles: true }, }); const channels = await Channel.find({ @@ -115,25 +115,26 @@ await Message.find({ where: whereQuery, order: { timestamp: "DESC" }, - relations: [ - "author", - "webhook", - "application", - "mentions", - "mention_roles", - "mention_channels", - "sticker_items", - "attachments", - "referenced_message", - "referenced_message.author", - "referenced_message.webhook", - "referenced_message.application", - "referenced_message.mentions", - "referenced_message.mention_roles", - "referenced_message.mention_channels", - "referenced_message.sticker_items", - "referenced_message.attachments", - ], + relations: { + author: true, + webhook: true, + application: true, + mentions: true, + mention_roles: true, + mention_channels: true, + sticker_items: true, + attachments: true, + referenced_message: { + author: true, + webhook: true, + application: true, + mentions: true, + mention_roles: true, + mention_channels: true, + sticker_items: true, + attachments: true, + }, + }, take: limit, }) ).map((m) => { diff --git a/src/api/routes/users/@me/mfa/webauthn/credentials/index.ts b/src/api/routes/users/@me/mfa/webauthn/credentials/index.ts index 50bf341..f99f7b3 100644 --- a/src/api/routes/users/@me/mfa/webauthn/credentials/index.ts +++ b/src/api/routes/users/@me/mfa/webauthn/credentials/index.ts @@ -81,7 +81,7 @@ id: req.user_id, }, select: { data: true, id: true, disabled: true, deleted: true, totp_secret: true, mfa_enabled: true, username: true }, - relations: ["settings"], + relations: { settings: true }, }); if (isGenerateSchema(req.body)) { diff --git a/src/api/routes/users/@me/relationships.ts b/src/api/routes/users/@me/relationships.ts index b796b29..37d5e22 100644 --- a/src/api/routes/users/@me/relationships.ts +++ b/src/api/routes/users/@me/relationships.ts @@ -41,7 +41,7 @@ async (req: Request, res: Response) => { const user = await User.findOneOrFail({ where: { id: req.user_id }, - relations: ["relationships", "relationships.to"], + relations: { relationships: { to: true } }, select: { id: true, relationships: true }, }); @@ -70,7 +70,7 @@ res, await User.findOneOrFail({ where: { id: req.params.user_id }, - relations: ["relationships", "relationships.to"], + relations: { relationships: { to: true } }, select: userProjection, }), req.body.type ?? RelationshipType.friends, @@ -135,7 +135,7 @@ req, res, await User.findOneOrFail({ - relations: ["relationships", "relationships.to"], + relations: { relationships: { to: true } }, select: userProjection, where: { discriminator: String(req.body.discriminator).padStart(4, "0"), //Discord send the discriminator as integer, we need to add leading zeroes @@ -167,12 +167,12 @@ const user = await User.findOneOrFail({ where: { id: req.user_id }, select: userProjection, - relations: ["relationships"], + relations: { relationships: true }, }); const friend = await User.findOneOrFail({ where: { id: user_id }, select: userProjection, - relations: ["relationships"], + relations: { relationships: true }, }); const relationship = user.relationships.find((x) => x.to_id === user_id); @@ -224,7 +224,7 @@ const user = await User.findOneOrFail({ where: { id: req.user_id }, - relations: ["relationships", "relationships.to"], + relations: { relationships: { to: true } }, select: userProjection, }); diff --git a/src/api/routes/users/@me/settings.ts b/src/api/routes/users/@me/settings.ts index 57ffba1..47c206c 100644 --- a/src/api/routes/users/@me/settings.ts +++ b/src/api/routes/users/@me/settings.ts @@ -64,7 +64,7 @@ const user = await User.findOneOrFail({ where: { id: req.user_id, bot: false }, - relations: ["settings"], + relations: { settings: true }, }); if (!user.settings) user.settings = UserSettings.create(body); diff --git "a/src/api/routes/webhooks/\043webhook_id/\043token/index.ts" "b/src/api/routes/webhooks/\043webhook_id/\043token/index.ts" index eecbfca..7bb1cd9 100644 --- "a/src/api/routes/webhooks/\043webhook_id/\043token/index.ts" +++ "b/src/api/routes/webhooks/\043webhook_id/\043token/index.ts" @@ -24,7 +24,7 @@ where: { id: webhook_id, }, - relations: ["user", "channel", "source_channel", "guild", "source_guild", "application"], + relations: { user: true, channel: true, source_channel: true, guild: true, source_guild: true, application: true }, }); if (!webhook) { @@ -107,7 +107,7 @@ where: { id: webhook_id, }, - relations: ["channel", "guild", "application"], + relations: { channel: true, guild: true, application: true }, }); if (!webhook) { @@ -154,7 +154,7 @@ const webhook = await Webhook.findOneOrFail({ where: { id: webhook_id }, - relations: ["user", "channel", "source_channel", "guild", "source_guild", "application"], + relations: { user: true, channel: true, source_channel: true, guild: true, source_guild: true, application: true }, }); const channel_id = webhook.channel_id; if (!body.name && !body.avatar) { diff --git "a/src/api/routes/webhooks/\043webhook_id/index.ts" "b/src/api/routes/webhooks/\043webhook_id/index.ts" index 8844b8e..bf275fb 100644 --- "a/src/api/routes/webhooks/\043webhook_id/index.ts" +++ "b/src/api/routes/webhooks/\043webhook_id/index.ts" @@ -20,7 +20,7 @@ const { webhook_id } = req.params; const webhook = await Webhook.findOneOrFail({ where: { id: webhook_id }, - relations: ["user", "channel", "source_channel", "guild", "source_guild", "application"], + relations: { user: true, channel: true, source_channel: true, guild: true, source_guild: true, application: true }, }); if (webhook.guild_id) { @@ -52,7 +52,7 @@ const webhook = await Webhook.findOneOrFail({ where: { id: webhook_id }, - relations: ["user", "channel", "source_channel", "guild", "source_guild", "application"], + relations: { user: true, channel: true, source_channel: true, guild: true, source_guild: true, application: true }, }); if (webhook.guild_id) { @@ -98,7 +98,7 @@ const webhook = await Webhook.findOneOrFail({ where: { id: webhook_id }, - relations: ["user", "channel", "source_channel", "guild", "source_guild", "application"], + relations: { user: true, channel: true, source_channel: true, guild: true, source_guild: true, application: true }, }); if (webhook.guild_id) { diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts index 618f02f..766abd1 100644 --- a/src/api/util/handlers/Message.ts +++ b/src/api/util/handlers/Message.ts @@ -61,7 +61,7 @@ export async function handleMessage(opts: MessageOptions): Promise { const channel = await Channel.findOneOrFail({ where: { id: opts.channel_id }, - relations: ["recipients"], + relations: { recipients: true }, }); if (!channel || !opts.channel_id) throw new HTTPError("Channel not found", 404); @@ -242,7 +242,16 @@ where: { id: opts.message_reference.message_id, }, - relations: ["author", "webhook", "application", "mentions", "mention_roles", "mention_channels", "sticker_items", "attachments"], + relations: { + author: true, + webhook: true, + application: true, + mentions: true, + mention_roles: true, + mention_channels: true, + sticker_items: true, + attachments: true, + }, }); if (message.referenced_message.channel_id && message.referenced_message.channel_id !== opts.message_reference.channel_id) diff --git a/src/api/util/handlers/Webhook.ts b/src/api/util/handlers/Webhook.ts index cd0f2f6..d4aceb8 100644 --- a/src/api/util/handlers/Webhook.ts +++ b/src/api/util/handlers/Webhook.ts @@ -14,7 +14,7 @@ where: { id: webhook_id, }, - relations: ["channel", "guild", "application"], + relations: { channel: true, guild: true, application: true }, }); if (!webhook) { diff --git a/src/gateway/listener/listener.ts b/src/gateway/listener/listener.ts index 28dff2c..1f0d386 100644 --- a/src/gateway/listener/listener.ts +++ b/src/gateway/listener/listener.ts @@ -64,11 +64,11 @@ const [members, recipients, relationships] = await Promise.all([ Member.find({ where: { id: this.user_id }, - relations: ["guild", "guild.channels"], + relations: { guild: { channels: true } }, }), Recipient.find({ where: { user_id: this.user_id, closed: false }, - relations: ["channel"], + relations: { channel: true }, }), Relationship.find({ where: { diff --git a/src/gateway/opcodes/GuildSync.ts b/src/gateway/opcodes/GuildSync.ts index 6eea199..ab27963 100644 --- a/src/gateway/opcodes/GuildSync.ts +++ b/src/gateway/opcodes/GuildSync.ts @@ -91,7 +91,7 @@ async function handleGuildSync(ws: WebSocket, guild_id: string) { const res: GuildSyncResult = { id: guild_id, presences: [], members: [] }; - const members = await Member.find({ where: { guild_id }, relations: ["user", "roles", "guild"] }); + const members = await Member.find({ where: { guild_id }, relations: { user: true, roles: true, guild: true } }); res.members = members.map((m) => m.toPublicMember()); const sessions = await Session.find({ where: { user_id: In(members.map((m) => m.id)) }, order: { user_id: "ASC" } }); diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts index 6fb9f79..d6f1462 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts @@ -90,7 +90,7 @@ const { result: tokenData, elapsed: checkTokenTime } = await timePromise(() => checkToken(identify.token, { - // relations: ["relationships", "relationships.to", "settings"], + // relations: {"relationships", "relationships.to", "settings"], // select: [...PrivateUserProjection, "relationships", "rights"], select: [...PrivateUserProjection, "rights"], }), @@ -180,7 +180,7 @@ timePromise(() => Relationship.find({ where: { from_id: this.user_id }, - relations: ["to"], + relations: { to: true }, }), ), timePromise(() => UserSettings.getOrDefault(this.user_id)), @@ -221,24 +221,24 @@ // .columns.map((x) => [x.propertyName, true]), // ), }, - relations: [ + relations: { // "guild", // "guild.channels", // "guild.emojis", // "guild.roles", // "guild.stickers", // "guild.voice_states", - "roles", + roles: true, // For these entities, `user` is always just the logged in user we fetched above // "user", - ], + }, }), ), timePromise(() => Recipient.find({ where: { user_id: this.user_id, closed: false }, - relations: ["channel", "channel.recipients", "channel.recipients.user"], + relations: { channel: { recipients: { user: true } } }, select: { channel: { id: true, diff --git a/src/gateway/opcodes/RequestGuildMembers.ts b/src/gateway/opcodes/RequestGuildMembers.ts index 1c70809..8fa9017 100644 --- a/src/gateway/opcodes/RequestGuildMembers.ts +++ b/src/gateway/opcodes/RequestGuildMembers.ts @@ -67,7 +67,7 @@ where: { guild_id, }, - relations: ["user", "roles"], + relations: { user: true, roles: true }, }; if (limit) memberFind.take = Math.abs(Number(limit || 100)); diff --git a/src/gateway/opcodes/StreamCreate.ts b/src/gateway/opcodes/StreamCreate.ts index 176a084..0c6c8c2 100644 --- a/src/gateway/opcodes/StreamCreate.ts +++ b/src/gateway/opcodes/StreamCreate.ts @@ -32,7 +32,7 @@ if (body.guild_id) { voiceState.member = await Member.findOneOrFail({ where: { id: voiceState.user_id, guild_id: voiceState.guild_id }, - relations: ["user", "roles"], + relations: { user: true, roles: true }, }); } diff --git a/src/gateway/opcodes/StreamWatch.ts b/src/gateway/opcodes/StreamWatch.ts index 4e51865..3a3c553 100644 --- a/src/gateway/opcodes/StreamWatch.ts +++ b/src/gateway/opcodes/StreamWatch.ts @@ -28,7 +28,7 @@ const stream = await Stream.findOne({ where: { channel_id: channelId, owner_id: userId }, - relations: ["channel"], + relations: { channel: true }, }); if (!stream) return this.close(4000, "Invalid stream key"); diff --git a/src/gateway/opcodes/VoiceStateUpdate.ts b/src/gateway/opcodes/VoiceStateUpdate.ts index 08a8181..5d36382 100644 --- a/src/gateway/opcodes/VoiceStateUpdate.ts +++ b/src/gateway/opcodes/VoiceStateUpdate.ts @@ -92,7 +92,7 @@ if (body.guild_id) { voiceState.member = await Member.findOneOrFail({ where: { id: voiceState.user_id, guild_id: voiceState.guild_id }, - relations: ["user", "roles"], + relations: { user: true, roles: true }, }); } diff --git a/src/util/entities/Channel.ts b/src/util/entities/Channel.ts index 8ec801c..a250758 100644 --- a/src/util/entities/Channel.ts +++ b/src/util/entities/Channel.ts @@ -273,7 +273,7 @@ const userRecipients = await Recipient.find({ where: { user_id: creator_user_id }, - relations: ["channel", "channel.recipients"], + relations: { channel: { recipients: true } }, }); for (const ur of userRecipients) { @@ -451,8 +451,8 @@ let member = opts.member; if (!member) { - if (opts.user) member = await Member.findOneOrFail({ where: { guild_id: guild.id, id: opts.user.id }, relations: ["roles"] }); - else if (opts.user_id) member = await Member.findOneOrFail({ where: { guild_id: guild.id, id: opts.user_id }, relations: ["roles"] }); + if (opts.user) member = await Member.findOneOrFail({ where: { guild_id: guild.id, id: opts.user.id }, relations: { roles: true } }); + else if (opts.user_id) member = await Member.findOneOrFail({ where: { guild_id: guild.id, id: opts.user_id }, relations: { roles: true } }); else { console.error("Channel.getUserPermissions: called without user or member for non-DM channel."); return Permissions.NONE; @@ -464,7 +464,7 @@ ( await Member.findOneOrFail({ where: { guild_id: guild.id, index: member.index }, - relations: ["roles"], + relations: { roles: true }, select: { roles: { id: true, diff --git a/src/util/entities/Member.ts b/src/util/entities/Member.ts index b2a0fc8..080e8ba 100644 --- a/src/util/entities/Member.ts +++ b/src/util/entities/Member.ts @@ -175,7 +175,7 @@ if (guild.owner_id === user_id) throw new Error("The owner cannot be removed of the guild"); const member = await Member.findOneOrFail({ where: { id: user_id, guild_id }, - relations: ["user"], + relations: { user: true }, }); // use promise all to execute all promises at the same time -> save time @@ -205,7 +205,7 @@ const [member] = await Promise.all([ Member.findOneOrFail({ where: { id: user_id, guild_id }, - relations: ["user", "roles"], // we don't want to load the role objects just the ids + relations: { user: true, roles: true }, // we don't want to load the role objects just the ids select: { index: true, roles: { @@ -238,7 +238,7 @@ const [member] = await Promise.all([ Member.findOneOrFail({ where: { id: user_id, guild_id }, - relations: ["user", "roles"], // we don't want to load the role objects just the ids + relations: { user: true, roles: true }, // we don't want to load the role objects just the ids select: { index: true, roles: { @@ -270,7 +270,7 @@ id: user_id, guild_id, }, - relations: ["user"], + relations: { user: true }, }); // @ts-expect-error Member nickname is nullable @@ -327,7 +327,7 @@ }, }, }, - relations: ["user", "roles"], + relations: { user: true, roles: true }, take: 10, }) ).map((member) => member.toPublicMember()); diff --git a/src/webrtc/opcodes/Identify.ts b/src/webrtc/opcodes/Identify.ts index ac93011..5097679 100644 --- a/src/webrtc/opcodes/Identify.ts +++ b/src/webrtc/opcodes/Identify.ts @@ -54,7 +54,7 @@ session_id, used: false, }, - relations: ["stream"], + relations: { stream: true }, }); if (streamSession) {