Deprecation: Use object-based relations for typeorm

This commit is contained in:
Rory&
2025-12-19 21:06:12 +01:00
parent 7c247aedb9
commit 6162fbd520
55 changed files with 151 additions and 137 deletions
@@ -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;
@@ -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;
+2 -2
View File
@@ -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) {
+1 -1
View File
@@ -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);
},
+1 -1
View File
@@ -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: {
+1 -1
View File
@@ -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({
+1 -1
View File
@@ -55,7 +55,7 @@ router.post(
totp_last_ticket: ticket,
},
select: { id: true },
relations: ["settings"],
relations: { settings: true },
});
const ret = await verifyWebAuthnToken(ticket);
+1 -1
View File
@@ -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) {
@@ -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);
@@ -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 },
});
}
@@ -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" },
});
@@ -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
+3 -3
View File
@@ -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" },
});
+1 -1
View File
@@ -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);
@@ -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;
@@ -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",
@@ -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(
+2 -2
View File
@@ -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);
+1 -1
View File
@@ -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
@@ -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);
@@ -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());
@@ -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
@@ -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);
+2 -2
View File
@@ -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) || []));
@@ -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));
+1 -1
View File
@@ -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 },
+1 -1
View File
@@ -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;
+2 -2
View File
@@ -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({
+1 -1
View File
@@ -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])),
},
+3 -3
View File
@@ -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
+1 -1
View File
@@ -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 });
+1 -1
View File
@@ -44,7 +44,7 @@ router.get(
where: {
owner_user_id: req.user_id,
},
relations: ["members"],
relations: { members: true },
});
res.send(teams);
+1 -1
View File
@@ -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,
+2 -2
View File
@@ -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;
@@ -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) {
+1 -1
View File
@@ -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]))));
},
+1 -1
View File
@@ -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 },
});
+21 -20
View File
@@ -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) => {
@@ -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)) {
+6 -6
View File
@@ -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,
});
+1 -1
View File
@@ -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);
@@ -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) {
+3 -3
View File
@@ -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) {
+11 -2
View File
@@ -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)
+1 -1
View File
@@ -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) {
+2 -2
View File
@@ -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: {
+1 -1
View File
@@ -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" } });
+6 -6
View File
@@ -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,
+1 -1
View File
@@ -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));
+1 -1
View File
@@ -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 },
});
}
+1 -1
View File
@@ -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");
+1 -1
View File
@@ -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 },
});
}
+4 -4
View File
@@ -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,
+5 -5
View File
@@ -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());
+1 -1
View File
@@ -54,7 +54,7 @@ export async function onIdentify(this: WebRtcWebSocket, data: VoicePayload) {
session_id,
used: false,
},
relations: ["stream"],
relations: { stream: true },
});
if (streamSession) {