diff --git a/src/api/routes/applications/#application_id/bot/index.ts b/src/api/routes/applications/#application_id/bot/index.ts
index 835225e0..901f386f 100644
--- a/src/api/routes/applications/#application_id/bot/index.ts
+++ b/src/api/routes/applications/#application_id/bot/index.ts
@@ -40,7 +40,7 @@ router.post(
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 @@ router.patch(
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/#application_id/index.ts b/src/api/routes/applications/#application_id/index.ts
index 22340e9e..1576df88 100644
--- a/src/api/routes/applications/#application_id/index.ts
+++ b/src/api/routes/applications/#application_id/index.ts
@@ -40,7 +40,7 @@ router.get(
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 @@ router.patch(
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 @@ router.post(
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 1c4a7530..7e315a56 100644
--- a/src/api/routes/applications/@me.ts
+++ b/src/api/routes/applications/@me.ts
@@ -41,7 +41,7 @@ router.get(
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 @@ router.patch(
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 e719e443..0740c2fb 100644
--- a/src/api/routes/applications/index.ts
+++ b/src/api/routes/applications/index.ts
@@ -35,7 +35,7 @@ router.get(
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 8b2e039a..466d264a 100644
--- a/src/api/routes/auth/login.ts
+++ b/src/api/routes/auth/login.ts
@@ -68,7 +68,7 @@ router.post(
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 dd107698..366fb102 100644
--- a/src/api/routes/auth/mfa/totp.ts
+++ b/src/api/routes/auth/mfa/totp.ts
@@ -46,7 +46,7 @@ router.post(
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 0bc91cfe..3359767c 100644
--- a/src/api/routes/auth/mfa/webauthn.ts
+++ b/src/api/routes/auth/mfa/webauthn.ts
@@ -55,7 +55,7 @@ router.post(
totp_last_ticket: ticket,
},
select: { id: true },
- relations: ["settings"],
+ relations: { settings: true },
});
const ret = await verifyWebAuthnToken(ticket);
diff --git a/src/api/routes/channels/#channel_id/index.ts b/src/api/routes/channels/#channel_id/index.ts
index 37909a94..4c167983 100644
--- a/src/api/routes/channels/#channel_id/index.ts
+++ b/src/api/routes/channels/#channel_id/index.ts
@@ -65,7 +65,7 @@ router.delete(
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/#channel_id/messages/#message_id/index.ts b/src/api/routes/channels/#channel_id/messages/#message_id/index.ts
index 6457c7eb..934efc31 100644
--- a/src/api/routes/channels/#channel_id/messages/#message_id/index.ts
+++ b/src/api/routes/channels/#channel_id/messages/#message_id/index.ts
@@ -72,7 +72,7 @@ router.patch(
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 @@ router.put(
}
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 @@ router.get(
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/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts
index 272fa8ac..6b18e2c9 100644
--- a/src/api/routes/channels/#channel_id/messages/index.ts
+++ b/src/api/routes/channels/#channel_id/messages/index.ts
@@ -118,25 +118,26 @@ router.get(
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 @@ router.get(
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 @@ router.post(
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 @@ router.post(
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/#channel_id/messages/pins/index.ts b/src/api/routes/channels/#channel_id/messages/pins/index.ts
index 2355c8b9..3316d156 100644
--- a/src/api/routes/channels/#channel_id/messages/pins/index.ts
+++ b/src/api/routes/channels/#channel_id/messages/pins/index.ts
@@ -41,7 +41,7 @@ router.put(
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 @@ router.delete(
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 @@ router.get(
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/#channel_id/messages/search.ts b/src/api/routes/channels/#channel_id/messages/search.ts
index ed1dfc33..1a371cc7 100644
--- a/src/api/routes/channels/#channel_id/messages/search.ts
+++ b/src/api/routes/channels/#channel_id/messages/search.ts
@@ -87,7 +87,7 @@ router.get(
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/#channel_id/pins.ts b/src/api/routes/channels/#channel_id/pins.ts
index 8e56a54d..d94d4f37 100644
--- a/src/api/routes/channels/#channel_id/pins.ts
+++ b/src/api/routes/channels/#channel_id/pins.ts
@@ -42,7 +42,7 @@ router.put(
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 @@ router.delete(
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 @@ router.get(
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/#channel_id/purge.ts b/src/api/routes/channels/#channel_id/purge.ts
index 3a46beb7..90f8c6d4 100644
--- a/src/api/routes/channels/#channel_id/purge.ts
+++ b/src/api/routes/channels/#channel_id/purge.ts
@@ -74,7 +74,7 @@ router.post(
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/#channel_id/recipients.ts b/src/api/routes/channels/#channel_id/recipients.ts
index d0af3b4a..c001f843 100644
--- a/src/api/routes/channels/#channel_id/recipients.ts
+++ b/src/api/routes/channels/#channel_id/recipients.ts
@@ -35,7 +35,7 @@ router.put(
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 @@ router.delete(
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/#channel_id/typing.ts b/src/api/routes/channels/#channel_id/typing.ts
index a41ab7ff..b5b2cd1e 100644
--- a/src/api/routes/channels/#channel_id/typing.ts
+++ b/src/api/routes/channels/#channel_id/typing.ts
@@ -41,7 +41,7 @@ router.post(
});
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/#channel_id/webhooks.ts b/src/api/routes/channels/#channel_id/webhooks.ts
index 1c3c980a..994bab2f 100644
--- a/src/api/routes/channels/#channel_id/webhooks.ts
+++ b/src/api/routes/channels/#channel_id/webhooks.ts
@@ -40,7 +40,7 @@ router.get(
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/#guild_id/emojis.ts b/src/api/routes/guilds/#guild_id/emojis.ts
index f256ce33..5bc03433 100644
--- a/src/api/routes/guilds/#guild_id/emojis.ts
+++ b/src/api/routes/guilds/#guild_id/emojis.ts
@@ -42,7 +42,7 @@ router.get(
const emojis = await Emoji.find({
where: { guild_id: guild_id },
- relations: ["user"],
+ relations: { user: true },
});
return res.json(emojis);
@@ -71,7 +71,7 @@ router.get(
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/#guild_id/index.ts b/src/api/routes/guilds/#guild_id/index.ts
index 38cc9139..8bb9e7df 100644
--- a/src/api/routes/guilds/#guild_id/index.ts
+++ b/src/api/routes/guilds/#guild_id/index.ts
@@ -83,7 +83,7 @@ router.patch(
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/#guild_id/members/#member_id/index.ts b/src/api/routes/guilds/#guild_id/members/#member_id/index.ts
index 81cda182..6a9cfc55 100644
--- a/src/api/routes/guilds/#guild_id/members/#member_id/index.ts
+++ b/src/api/routes/guilds/#guild_id/members/#member_id/index.ts
@@ -44,7 +44,7 @@ router.get(
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 @@ router.patch(
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/#guild_id/members/#member_id/nick.ts b/src/api/routes/guilds/#guild_id/members/#member_id/nick.ts
index 33f89152..87c95aa3 100644
--- a/src/api/routes/guilds/#guild_id/members/#member_id/nick.ts
+++ b/src/api/routes/guilds/#guild_id/members/#member_id/nick.ts
@@ -50,7 +50,7 @@ router.patch(
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/#guild_id/messages/search.ts b/src/api/routes/guilds/#guild_id/messages/search.ts
index 426d0dcf..51c9b5a2 100644
--- a/src/api/routes/guilds/#guild_id/messages/search.ts
+++ b/src/api/routes/guilds/#guild_id/messages/search.ts
@@ -80,7 +80,7 @@ router.get(
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/#guild_id/profile/index.ts b/src/api/routes/guilds/#guild_id/profile/index.ts
index 7a944b1f..b7a071b7 100644
--- a/src/api/routes/guilds/#guild_id/profile/index.ts
+++ b/src/api/routes/guilds/#guild_id/profile/index.ts
@@ -47,7 +47,7 @@ router.patch(
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/#guild_id/prune.ts b/src/api/routes/guilds/#guild_id/prune.ts
index c8a42b84..71791479 100644
--- a/src/api/routes/guilds/#guild_id/prune.ts
+++ b/src/api/routes/guilds/#guild_id/prune.ts
@@ -44,7 +44,7 @@ const inactiveMembers = async (guild_id: string, user_id: string, days: number,
last_message_id: IsNull(),
},
],
- relations: ["roles"],
+ relations: { roles: true },
});
if (!members.length) return [];
@@ -53,7 +53,7 @@ const inactiveMembers = async (guild_id: string, user_id: string, days: number,
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/#guild_id/roles/#role_id/members.ts b/src/api/routes/guilds/#guild_id/roles/#role_id/members.ts
index f89d5935..6eb6804c 100644
--- a/src/api/routes/guilds/#guild_id/roles/#role_id/members.ts
+++ b/src/api/routes/guilds/#guild_id/roles/#role_id/members.ts
@@ -32,7 +32,7 @@ router.patch("/", route({ permission: "MANAGE_ROLES" }), async (req: Request, re
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/#guild_id/templates.ts b/src/api/routes/guilds/#guild_id/templates.ts
index 2cc9604c..e577cead 100644
--- a/src/api/routes/guilds/#guild_id/templates.ts
+++ b/src/api/routes/guilds/#guild_id/templates.ts
@@ -86,7 +86,7 @@ router.post(
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/#guild_id/webhooks.ts b/src/api/routes/guilds/#guild_id/webhooks.ts
index 81837d34..65fa0ab2 100644
--- a/src/api/routes/guilds/#guild_id/webhooks.ts
+++ b/src/api/routes/guilds/#guild_id/webhooks.ts
@@ -36,7 +36,7 @@ router.get(
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 e997964e..5e772175 100644
--- a/src/api/routes/interactions/index.ts
+++ b/src/api/routes/interactions/index.ts
@@ -69,7 +69,7 @@ router.post("/", route({}), async (req: Request, res: Response) => {
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 @@ router.post("/", route({}), async (req: Request, res: Response) => {
}
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 9cdd47c0..e750a62a 100644
--- a/src/api/routes/oauth2/applications/@me.ts
+++ b/src/api/routes/oauth2/applications/@me.ts
@@ -35,7 +35,7 @@ router.get(
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 849e79b1..b989899a 100644
--- a/src/api/routes/oauth2/authorize.ts
+++ b/src/api/routes/oauth2/authorize.ts
@@ -59,7 +59,7 @@ router.get(
where: {
id: client_id as string,
},
- relations: ["bot"],
+ relations: { bot: true },
});
// TODO: use DiscordApiErrors
@@ -82,7 +82,7 @@ router.get(
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 @@ router.post(
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 749ce026..b5b08cfa 100644
--- a/src/api/routes/sticker-packs/index.ts
+++ b/src/api/routes/sticker-packs/index.ts
@@ -33,7 +33,7 @@ router.get(
}),
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 a9380f12..9e900df1 100644
--- a/src/api/routes/teams.ts
+++ b/src/api/routes/teams.ts
@@ -44,7 +44,7 @@ router.get(
where: {
owner_user_id: req.user_id,
},
- relations: ["members"],
+ relations: { members: true },
});
res.send(teams);
diff --git a/src/api/routes/users/#user_id/delete.ts b/src/api/routes/users/#user_id/delete.ts
index c2286cea..598be974 100644
--- a/src/api/routes/users/#user_id/delete.ts
+++ b/src/api/routes/users/#user_id/delete.ts
@@ -81,7 +81,7 @@ router.post(
//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/#user_id/profile.ts b/src/api/routes/users/#user_id/profile.ts
index b100ac35..e4d4d749 100644
--- a/src/api/routes/users/#user_id/profile.ts
+++ b/src/api/routes/users/#user_id/profile.ts
@@ -33,7 +33,7 @@ router.get("/", route({ responses: { 200: { body: "UserProfileResponse" } } }),
where: {
id: req.params.id,
},
- relations: ["connected_accounts"],
+ relations: { connected_accounts: true },
});
const mutual_guilds: object[] = [];
@@ -72,7 +72,7 @@ router.get("/", route({ responses: { 200: { body: "UserProfileResponse" } } }),
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/#user_id/relationships.ts b/src/api/routes/users/#user_id/relationships.ts
index 3272ef7b..93f11296 100644
--- a/src/api/routes/users/#user_id/relationships.ts
+++ b/src/api/routes/users/#user_id/relationships.ts
@@ -38,11 +38,11 @@ router.get(
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 e13b874a..897630ce 100644
--- a/src/api/routes/users/@me/channels.ts
+++ b/src/api/routes/users/@me/channels.ts
@@ -35,7 +35,7 @@ router.get(
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 89086562..8fcec95a 100644
--- a/src/api/routes/users/@me/guilds.ts
+++ b/src/api/routes/users/@me/guilds.ts
@@ -34,7 +34,7 @@ router.get(
}),
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 c2985ca4..b63078f0 100644
--- a/src/api/routes/users/@me/mentions.ts
+++ b/src/api/routes/users/@me/mentions.ts
@@ -63,7 +63,7 @@ router.get(
owner_id: true,
},
},
- relations: ["guild", "roles"],
+ relations: { guild: true, roles: true },
});
const channels = await Channel.find({
@@ -115,25 +115,26 @@ router.get(
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 50bf341c..f99f7b3d 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 @@ router.post(
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 b796b29e..37d5e222 100644
--- a/src/api/routes/users/@me/relationships.ts
+++ b/src/api/routes/users/@me/relationships.ts
@@ -41,7 +41,7 @@ router.get(
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 @@ router.put(
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 @@ router.post(
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 @@ router.delete(
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 @@ async function updateRelationship(req: Request, res: Response, friend: User, typ
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 57ffba14..47c206c9 100644
--- a/src/api/routes/users/@me/settings.ts
+++ b/src/api/routes/users/@me/settings.ts
@@ -64,7 +64,7 @@ router.patch(
const user = await User.findOneOrFail({
where: { id: req.user_id, bot: false },
- relations: ["settings"],
+ relations: { settings: true },
});
if (!user.settings) user.settings = UserSettings.create<UserSettings>(body);
diff --git a/src/api/routes/webhooks/#webhook_id/#token/index.ts b/src/api/routes/webhooks/#webhook_id/#token/index.ts
index eecbfcae..7bb1cd9f 100644
--- a/src/api/routes/webhooks/#webhook_id/#token/index.ts
+++ b/src/api/routes/webhooks/#webhook_id/#token/index.ts
@@ -24,7 +24,7 @@ router.get(
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 @@ router.delete(
where: {
id: webhook_id,
},
- relations: ["channel", "guild", "application"],
+ relations: { channel: true, guild: true, application: true },
});
if (!webhook) {
@@ -154,7 +154,7 @@ router.patch(
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/#webhook_id/index.ts b/src/api/routes/webhooks/#webhook_id/index.ts
index 8844b8ef..bf275fb5 100644
--- a/src/api/routes/webhooks/#webhook_id/index.ts
+++ b/src/api/routes/webhooks/#webhook_id/index.ts
@@ -20,7 +20,7 @@ router.get(
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 @@ router.delete(
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 @@ router.patch(
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 618f02f0..766abd13 100644
--- a/src/api/util/handlers/Message.ts
+++ b/src/api/util/handlers/Message.ts
@@ -61,7 +61,7 @@ const LINK_REGEX = /<?https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-
export async function handleMessage(opts: MessageOptions): Promise<Message> {
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 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
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 cd0f2f6e..d4aceb89 100644
--- a/src/api/util/handlers/Webhook.ts
+++ b/src/api/util/handlers/Webhook.ts
@@ -14,7 +14,7 @@ export const executeWebhook = async (req: Request, res: Response) => {
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 28dff2c0..1f0d386d 100644
--- a/src/gateway/listener/listener.ts
+++ b/src/gateway/listener/listener.ts
@@ -64,11 +64,11 @@ export async function setupListener(this: WebSocket) {
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 6eea199b..ab279639 100644
--- a/src/gateway/opcodes/GuildSync.ts
+++ b/src/gateway/opcodes/GuildSync.ts
@@ -91,7 +91,7 @@ interface GuildSyncResult {
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 6fb9f795..d6f14627 100644
--- a/src/gateway/opcodes/Identify.ts
+++ b/src/gateway/opcodes/Identify.ts
@@ -90,7 +90,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
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 @@ export async function onIdentify(this: WebSocket, data: Payload) {
timePromise(() =>
Relationship.find({
where: { from_id: this.user_id },
- relations: ["to"],
+ relations: { to: true },
}),
),
timePromise(() => UserSettings.getOrDefault(this.user_id)),
@@ -221,24 +221,24 @@ export async function onIdentify(this: WebSocket, data: Payload) {
// .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 1c708095..8fa90179 100644
--- a/src/gateway/opcodes/RequestGuildMembers.ts
+++ b/src/gateway/opcodes/RequestGuildMembers.ts
@@ -67,7 +67,7 @@ export async function onRequestGuildMembers(this: WebSocket, { d }: Payload) {
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 176a084b..0c6c8c2d 100644
--- a/src/gateway/opcodes/StreamCreate.ts
+++ b/src/gateway/opcodes/StreamCreate.ts
@@ -32,7 +32,7 @@ export async function onStreamCreate(this: WebSocket, data: Payload) {
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 4e518651..3a3c553e 100644
--- a/src/gateway/opcodes/StreamWatch.ts
+++ b/src/gateway/opcodes/StreamWatch.ts
@@ -28,7 +28,7 @@ export async function onStreamWatch(this: WebSocket, data: Payload) {
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 08a81817..5d363825 100644
--- a/src/gateway/opcodes/VoiceStateUpdate.ts
+++ b/src/gateway/opcodes/VoiceStateUpdate.ts
@@ -92,7 +92,7 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) {
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 8ec801c0..a250758f 100644
--- a/src/util/entities/Channel.ts
+++ b/src/util/entities/Channel.ts
@@ -273,7 +273,7 @@ export class Channel extends BaseClass {
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 @@ export class Channel extends BaseClass {
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 @@ export class Channel extends BaseClass {
(
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 b2a0fc89..080e8bad 100644
--- a/src/util/entities/Member.ts
+++ b/src/util/entities/Member.ts
@@ -175,7 +175,7 @@ export class Member extends BaseClassWithoutId {
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 @@ export class Member extends BaseClassWithoutId {
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 @@ export class Member extends BaseClassWithoutId {
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 @@ export class Member extends BaseClassWithoutId {
id: user_id,
guild_id,
},
- relations: ["user"],
+ relations: { user: true },
});
// @ts-expect-error Member nickname is nullable
@@ -327,7 +327,7 @@ export class Member extends BaseClassWithoutId {
},
},
},
- 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 ac93011a..50976794 100644
--- a/src/webrtc/opcodes/Identify.ts
+++ b/src/webrtc/opcodes/Identify.ts
@@ -54,7 +54,7 @@ export async function onIdentify(this: WebRtcWebSocket, data: VoicePayload) {
session_id,
used: false,
},
- relations: ["stream"],
+ relations: { stream: true },
});
if (streamSession) {
|