diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ee60e5f..25a9866 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -50,49 +50,50 @@ - + diff --git "a/src/api/routes/applications/\043application_id/index.ts" "b/src/api/routes/applications/\043application_id/index.ts" index bf29f40..22340e9 100644 --- "a/src/api/routes/applications/\043application_id/index.ts" +++ "b/src/api/routes/applications/\043application_id/index.ts" @@ -83,7 +83,7 @@ if (body.guild_id) { const guild = await Guild.findOneOrFail({ where: { id: body.guild_id }, - select: ["owner_id"], + select: { owner_id: true }, }); if (guild.owner_id != req.user_id) throw new HTTPError("You must be the owner of the guild to link it to an application", 400); } diff --git a/src/api/routes/applications/@me.ts b/src/api/routes/applications/@me.ts index c1cf0db..1c4a753 100644 --- a/src/api/routes/applications/@me.ts +++ b/src/api/routes/applications/@me.ts @@ -79,7 +79,7 @@ if (body.guild_id) { const guild = await Guild.findOneOrFail({ where: { id: body.guild_id }, - select: ["owner_id"], + select: { owner_id: true }, }); if (guild.owner_id != req.user_id) throw new HTTPError("You must be the owner of the guild to link it to an application", 400); } diff --git a/src/api/routes/auth/forgot.ts b/src/api/routes/auth/forgot.ts index db16c3b..26e1b35 100644 --- a/src/api/routes/auth/forgot.ts +++ b/src/api/routes/auth/forgot.ts @@ -63,7 +63,7 @@ const user = await User.findOne({ where: [{ phone: login }, { email: login }], - select: ["username", "id", "email"], + select: { username: true, id: true, email: true }, }).catch(() => {}); if (user && user.email) { diff --git a/src/api/routes/auth/login.ts b/src/api/routes/auth/login.ts index 911ad4a..8b2e039 100644 --- a/src/api/routes/auth/login.ts +++ b/src/api/routes/auth/login.ts @@ -67,7 +67,7 @@ const user = await User.findOneOrFail({ where: [{ phone: login }, { email: login }], - select: ["data", "id", "disabled", "deleted", "totp_secret", "mfa_enabled", "webauthn_enabled", "security_keys", "verified"], + 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"], }).catch(() => { throw FieldErrors({ diff --git a/src/api/routes/auth/mfa/totp.ts b/src/api/routes/auth/mfa/totp.ts index b9f2fa8..dd10769 100644 --- a/src/api/routes/auth/mfa/totp.ts +++ b/src/api/routes/auth/mfa/totp.ts @@ -45,7 +45,7 @@ where: { totp_last_ticket: ticket, }, - select: ["id", "totp_secret"], + select: { id: true, totp_secret: true }, relations: ["settings"], }); diff --git a/src/api/routes/auth/mfa/webauthn.ts b/src/api/routes/auth/mfa/webauthn.ts index da476ab..0bc91cf 100644 --- a/src/api/routes/auth/mfa/webauthn.ts +++ b/src/api/routes/auth/mfa/webauthn.ts @@ -54,7 +54,7 @@ where: { totp_last_ticket: ticket, }, - select: ["id"], + select: { id: true }, relations: ["settings"], }); diff --git a/src/api/routes/auth/register.ts b/src/api/routes/auth/register.ts index f148758..3e3f292 100644 --- a/src/api/routes/auth/register.ts +++ b/src/api/routes/auth/register.ts @@ -111,7 +111,7 @@ // TODO: check if fingerprint was eligible generated const exists = await User.findOne({ where: { fingerprints: body.fingerprint }, - select: ["id"], + select: { id: true }, }); if (exists) { diff --git a/src/api/routes/auth/verify/resend.ts b/src/api/routes/auth/verify/resend.ts index ce6672a..4c0339b 100644 --- a/src/api/routes/auth/verify/resend.ts +++ b/src/api/routes/auth/verify/resend.ts @@ -39,7 +39,7 @@ async (req: Request, res: Response) => { const user = await User.findOneOrFail({ where: { id: req.user_id }, - select: ["username", "email", "verified"], + select: { username: true, email: true, verified: true }, }); if (!user.email) { diff --git a/src/api/routes/auth/verify/view-backup-codes-challenge.ts b/src/api/routes/auth/verify/view-backup-codes-challenge.ts index d3d40d3..7bfd669 100644 --- a/src/api/routes/auth/verify/view-backup-codes-challenge.ts +++ b/src/api/routes/auth/verify/view-backup-codes-challenge.ts @@ -37,7 +37,7 @@ const user = await User.findOneOrFail({ where: { id: req.user_id }, - select: ["data"], + select: { data: true }, }); if (!(await bcrypt.compare(password, user.data.hash || ""))) { diff --git "a/src/api/routes/channels/\043channel_id/invites.ts" "b/src/api/routes/channels/\043channel_id/invites.ts" index 45b7d79..be97e44 100644 --- "a/src/api/routes/channels/\043channel_id/invites.ts" +++ "b/src/api/routes/channels/\043channel_id/invites.ts" @@ -46,7 +46,7 @@ const { channel_id } = req.params; const channel = await Channel.findOneOrFail({ where: { id: channel_id }, - select: ["id", "name", "type", "guild_id"], + select: { id: true, name: true, type: true, guild_id: true }, }); isTextChannel(channel.type); diff --git "a/src/api/routes/channels/\043channel_id/messages/search.ts" "b/src/api/routes/channels/\043channel_id/messages/search.ts" index bec9a44..ed1dfc3 100644 --- "a/src/api/routes/channels/\043channel_id/messages/search.ts" +++ "b/src/api/routes/channels/\043channel_id/messages/search.ts" @@ -45,7 +45,7 @@ const { channel_id } = req.params; const channel = await Channel.findOneOrFail({ where: { guild_id: req.params.guild_id }, - select: ["id"], + select: { id: true }, }); const { content, diff --git "a/src/api/routes/guilds/\043guild_id/delete.ts" "b/src/api/routes/guilds/\043guild_id/delete.ts" index 4edd2c3..6e541da 100644 --- "a/src/api/routes/guilds/\043guild_id/delete.ts" +++ "b/src/api/routes/guilds/\043guild_id/delete.ts" @@ -43,7 +43,7 @@ const guild = await Guild.findOneOrFail({ where: { id: guild_id }, - select: ["owner_id"], + select: { owner_id: true }, }); if (guild.owner_id !== req.user_id) throw new HTTPError("You are not the owner of this guild", 401); diff --git "a/src/api/routes/guilds/\043guild_id/messages/search.ts" "b/src/api/routes/guilds/\043guild_id/messages/search.ts" index be00d5d..426d0dc 100644 --- "a/src/api/routes/guilds/\043guild_id/messages/search.ts" +++ "b/src/api/routes/guilds/\043guild_id/messages/search.ts" @@ -89,7 +89,7 @@ // get all channel IDs that this user can access const channels = await Channel.find({ where: { guild_id: req.params.guild_id }, - select: ["id"], + select: { id: true }, }); const ids = []; diff --git "a/src/api/routes/guilds/\043guild_id/roles/\043role_id/member-ids.ts" "b/src/api/routes/guilds/\043guild_id/roles/\043role_id/member-ids.ts" index ab61325..e4dccb3 100644 --- "a/src/api/routes/guilds/\043guild_id/roles/\043role_id/member-ids.ts" +++ "b/src/api/routes/guilds/\043guild_id/roles/\043role_id/member-ids.ts" @@ -27,7 +27,7 @@ // TODO: Is this route really not paginated? const members = await Member.find({ - select: ["id"], + select: { id: true }, where: { roles: { id: role_id, diff --git "a/src/api/routes/guilds/\043guild_id/roles/member-counts.ts" "b/src/api/routes/guilds/\043guild_id/roles/member-counts.ts" index d77149d..0f3a12c 100644 --- "a/src/api/routes/guilds/\043guild_id/roles/member-counts.ts" +++ "b/src/api/routes/guilds/\043guild_id/roles/member-counts.ts" @@ -26,7 +26,7 @@ const { guild_id } = req.params; await Member.IsInGuildOrFail(req.user_id, guild_id); - const role_ids = await Role.find({ where: { guild_id }, select: ["id"] }); + const role_ids = await Role.find({ where: { guild_id }, select: { id: true } }); const counts: { [id: string]: number } = {}; for (const { id } of role_ids) { counts[id] = await Member.count({ where: { roles: { id }, guild_id } }); diff --git a/src/api/routes/oauth2/authorize.ts b/src/api/routes/oauth2/authorize.ts index 4dea75c..849e79b 100644 --- a/src/api/routes/oauth2/authorize.ts +++ b/src/api/routes/oauth2/authorize.ts @@ -75,7 +75,7 @@ id: req.user_id, bot: false, }, - select: ["id", "username", "avatar", "discriminator", "public_flags"], + select: { id: true, username: true, avatar: true, discriminator: true, public_flags: true }, }); const guilds = await Member.find({ @@ -83,10 +83,11 @@ id: req.user_id, }, relations: ["guild", "roles", "user"], - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - //@ts-ignore - // prettier-ignore - select: ["guild.id", "guild.name", "guild.icon", "guild.mfa_level", "guild.owner_id", "roles.id", "user.flags"], + select: { + guild: { id: true, name: true, icon: true, mfa_level: true, owner_id: true }, + roles: { id: true }, + user: { flags: true }, + }, }); const guildsWithPermissions = guilds.map((x) => { diff --git a/src/api/routes/safety-hub/@me/index.ts b/src/api/routes/safety-hub/@me/index.ts index 7d0e7ff..e570129 100644 --- a/src/api/routes/safety-hub/@me/index.ts +++ b/src/api/routes/safety-hub/@me/index.ts @@ -38,7 +38,7 @@ async (req: Request, res: Response) => { const user = await User.findOneOrFail({ where: { id: req.user_id }, - select: ["data"], + select: { data: true }, }); res.send({ diff --git a/src/api/routes/safety-hub/suspended/@me.ts b/src/api/routes/safety-hub/suspended/@me.ts index 7d0e7ff..e570129 100644 --- a/src/api/routes/safety-hub/suspended/@me.ts +++ b/src/api/routes/safety-hub/suspended/@me.ts @@ -38,7 +38,7 @@ async (req: Request, res: Response) => { const user = await User.findOneOrFail({ where: { id: req.user_id }, - select: ["data"], + select: { data: true }, }); res.send({ diff --git a/src/api/routes/teams.ts b/src/api/routes/teams.ts index 090807d..a9380f1 100644 --- a/src/api/routes/teams.ts +++ b/src/api/routes/teams.ts @@ -64,7 +64,7 @@ async (req: Request, res: Response) => { const user = await User.findOneOrFail({ where: { id: req.user_id }, - select: ["mfa_enabled"], + select: { mfa_enabled: true }, }); if (!user.mfa_enabled) throw new HTTPError("You must enable MFA to create a team"); diff --git "a/src/api/routes/users/@me/connections/\043connection_name/\043connection_id/access-token.ts" "b/src/api/routes/users/@me/connections/\043connection_name/\043connection_id/access-token.ts" index 8846efe..a85348a 100644 --- "a/src/api/routes/users/@me/connections/\043connection_name/\043connection_id/access-token.ts" +++ "b/src/api/routes/users/@me/connections/\043connection_name/\043connection_id/access-token.ts" @@ -55,7 +55,18 @@ external_id: connection_id, user_id: req.user_id, }, - select: ["external_id", "type", "name", "verified", "visibility", "show_activity", "revoked", "token_data", "friend_sync", "integrations"], + select: { + external_id: true, + type: true, + name: true, + verified: true, + visibility: true, + show_activity: true, + revoked: true, + token_data: true, + friend_sync: true, + integrations: true, + }, }); if (!connectedAccount) throw DiscordApiErrors.UNKNOWN_CONNECTION; if (connectedAccount.revoked) throw DiscordApiErrors.CONNECTION_REVOKED; diff --git "a/src/api/routes/users/@me/connections/\043connection_name/\043connection_id/index.ts" "b/src/api/routes/users/@me/connections/\043connection_name/\043connection_id/index.ts" index 111312a..718c80c 100644 --- "a/src/api/routes/users/@me/connections/\043connection_name/\043connection_id/index.ts" +++ "b/src/api/routes/users/@me/connections/\043connection_name/\043connection_id/index.ts" @@ -33,7 +33,7 @@ external_id: connection_id, type: connection_name, }, - select: ["external_id", "type", "name", "verified", "visibility", "show_activity", "revoked", "friend_sync", "integrations"], + select: { external_id: true, type: true, name: true, verified: true, visibility: true, show_activity: true, revoked: true, friend_sync: true, integrations: true }, }); if (!connection) return DiscordApiErrors.UNKNOWN_CONNECTION; diff --git a/src/api/routes/users/@me/connections/index.ts b/src/api/routes/users/@me/connections/index.ts index a2d8b82..fe2fbba 100644 --- a/src/api/routes/users/@me/connections/index.ts +++ b/src/api/routes/users/@me/connections/index.ts @@ -27,7 +27,18 @@ where: { user_id: req.user_id, }, - select: ["external_id", "type", "name", "verified", "visibility", "show_activity", "revoked", "token_data", "friend_sync", "integrations"], + select: { + external_id: true, + type: true, + name: true, + verified: true, + visibility: true, + show_activity: true, + revoked: true, + token_data: true, + friend_sync: true, + integrations: true, + }, }); res.json(connections.map((x) => new ConnectedAccountDTO(x, true))); diff --git a/src/api/routes/users/@me/delete.ts b/src/api/routes/users/@me/delete.ts index 668f7c1..749baf7 100644 --- a/src/api/routes/users/@me/delete.ts +++ b/src/api/routes/users/@me/delete.ts @@ -40,7 +40,7 @@ async (req: Request, res: Response) => { const user = await User.findOneOrFail({ where: { id: req.user_id }, - select: ["data"], + select: { data: true }, }); //User object let correctpass = true; diff --git a/src/api/routes/users/@me/disable.ts b/src/api/routes/users/@me/disable.ts index 95995e4..e95ec45 100644 --- a/src/api/routes/users/@me/disable.ts +++ b/src/api/routes/users/@me/disable.ts @@ -39,7 +39,7 @@ async (req: Request, res: Response) => { const user = await User.findOneOrFail({ where: { id: req.user_id }, - select: ["data"], + select: { data: true }, }); //User object let correctpass = true; diff --git a/src/api/routes/users/@me/guilds.ts b/src/api/routes/users/@me/guilds.ts index c06c39c..8908656 100644 --- a/src/api/routes/users/@me/guilds.ts +++ b/src/api/routes/users/@me/guilds.ts @@ -67,7 +67,7 @@ const { guild_id } = req.params; const guild = await Guild.findOneOrFail({ where: { id: guild_id }, - select: ["owner_id"], + select: { owner_id: true }, }); if (!guild) throw new HTTPError("Guild doesn't exist", 404); diff --git "a/src/api/routes/users/@me/guilds/\043guild_id/settings.ts" "b/src/api/routes/users/@me/guilds/\043guild_id/settings.ts" index 16b64ec..3aaf723 100644 --- "a/src/api/routes/users/@me/guilds/\043guild_id/settings.ts" +++ "b/src/api/routes/users/@me/guilds/\043guild_id/settings.ts" @@ -35,7 +35,7 @@ async (req: Request, res: Response) => { const user = await Member.findOneOrFail({ where: { id: req.user_id, guild_id: req.params.guild_id }, - select: ["settings"], + select: { settings: true }, }); return res.json(user.settings); }, @@ -66,7 +66,7 @@ const user = await Member.findOneOrFail({ where: { id: req.user_id, guild_id: req.params.guild_id }, - select: ["settings"], + select: { settings: true }, }); OrmUtils.mergeDeep(user.settings || {}, body); Member.update({ id: req.user_id, guild_id: req.params.guild_id }, user); diff --git a/src/api/routes/users/@me/mfa/codes.ts b/src/api/routes/users/@me/mfa/codes.ts index 2eb1a3e..0b1b94d 100644 --- a/src/api/routes/users/@me/mfa/codes.ts +++ b/src/api/routes/users/@me/mfa/codes.ts @@ -49,7 +49,7 @@ const user = await User.findOneOrFail({ where: { id: req.user_id }, - select: ["data"], + select: { data: true }, }); if (!(await bcrypt.compare(password, user.data.hash || ""))) { diff --git a/src/api/routes/users/@me/mfa/totp/disable.ts b/src/api/routes/users/@me/mfa/totp/disable.ts index 11c927e..0b19560 100644 --- a/src/api/routes/users/@me/mfa/totp/disable.ts +++ b/src/api/routes/users/@me/mfa/totp/disable.ts @@ -43,7 +43,7 @@ const user = await User.findOneOrFail({ where: { id: req.user_id }, - select: ["totp_secret"], + select: { totp_secret: true }, }); const backup = await BackupCode.findOne({ where: { code: body.code } }); diff --git a/src/api/routes/users/@me/mfa/totp/enable.ts b/src/api/routes/users/@me/mfa/totp/enable.ts index a400c62..869f157 100644 --- a/src/api/routes/users/@me/mfa/totp/enable.ts +++ b/src/api/routes/users/@me/mfa/totp/enable.ts @@ -47,7 +47,7 @@ const user = await User.findOneOrFail({ where: { id: req.user_id }, - select: ["data", "email"], + select: { data: true, email: true }, }); // TODO: Are guests allowed to enable 2fa? 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 7bd29a5..50bf341 100644 --- a/src/api/routes/users/@me/mfa/webauthn/credentials/index.ts +++ b/src/api/routes/users/@me/mfa/webauthn/credentials/index.ts @@ -80,7 +80,7 @@ where: { id: req.user_id, }, - select: ["data", "id", "disabled", "deleted", "totp_secret", "mfa_enabled", "username"], + select: { data: true, id: true, disabled: true, deleted: true, totp_secret: true, mfa_enabled: true, username: true }, relations: ["settings"], }); diff --git a/src/api/routes/users/@me/relationships.ts b/src/api/routes/users/@me/relationships.ts index 3f95daa..b796b29 100644 --- a/src/api/routes/users/@me/relationships.ts +++ b/src/api/routes/users/@me/relationships.ts @@ -42,7 +42,7 @@ const user = await User.findOneOrFail({ where: { id: req.user_id }, relations: ["relationships", "relationships.to"], - select: ["id", "relationships"], + select: { id: true, relationships: true }, }); const related_users = user.relationships.map((r) => r.toPublicRelationship()); diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts index 6a2a75d..6fb9f79 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts @@ -192,13 +192,13 @@ timePromise(() => Application.findOne({ where: { id: this.user_id }, - select: ["id", "flags"], + select: { id: true, flags: true }, }), ), timePromise(() => ReadState.find({ where: { user_id: this.user_id }, - select: ["id", "channel_id", "last_message_id", "last_pin_timestamp", "mention_count"], + select: { id: true, channel_id: true, last_message_id: true, last_pin_timestamp: true, mention_count: true }, }), ), timePromise(() => diff --git a/src/gateway/opcodes/PresenceUpdate.ts b/src/gateway/opcodes/PresenceUpdate.ts index 2dfa861..54ce3a8 100644 --- a/src/gateway/opcodes/PresenceUpdate.ts +++ b/src/gateway/opcodes/PresenceUpdate.ts @@ -29,7 +29,7 @@ await Session.update({ session_id: this.session_id }, { status: presence.status, activities: presence.activities }); const session = await Session.findOneOrFail({ - select: ["client_status"], + select: { client_status: true }, where: { session_id: this.session_id }, }); diff --git a/src/util/entities/Member.ts b/src/util/entities/Member.ts index 016424e..b2a0fc8 100644 --- a/src/util/entities/Member.ts +++ b/src/util/entities/Member.ts @@ -169,7 +169,7 @@ static async removeFromGuild(user_id: string, guild_id: string) { const guild = await Guild.findOneOrFail({ - select: ["owner_id"], + select: { owner_id: true }, where: { id: guild_id }, }); if (guild.owner_id === user_id) throw new Error("The owner cannot be removed of the guild"); @@ -215,7 +215,7 @@ }), Role.findOneOrFail({ where: { id: role_id, guild_id }, - select: ["id"], + select: { id: true }, }), ]); member.roles.push(Role.create({ id: role_id })); diff --git a/src/util/entities/User.ts b/src/util/entities/User.ts index bc970c6..84471e0 100644 --- a/src/util/entities/User.ts +++ b/src/util/entities/User.ts @@ -217,7 +217,7 @@ // First we need to figure out the currently highest discrimnator for the given username and then increment it const users = await User.find({ where: { username }, - select: ["discriminator"], + select: { discriminator: true }, }); const highestDiscriminator = Math.max(0, ...users.map((u) => Number(u.discriminator))); @@ -236,7 +236,7 @@ const discriminator = Random.nextInt(1, 9999).toString().padStart(4, "0"); const exists = await User.findOne({ where: { discriminator, username: username }, - select: ["id"], + select: { id: true }, }); if (!exists) return discriminator; } diff --git a/src/util/util/Permissions.ts b/src/util/util/Permissions.ts index 49bfb5f..eb656f6 100644 --- a/src/util/util/Permissions.ts +++ b/src/util/util/Permissions.ts @@ -256,7 +256,7 @@ let guild: Guild | undefined; const user = await User.findOneOrFail({ where: { id: user_id }, - select: ["id", "flags"], + select: { id: true, flags: true }, }); if (typeof channel_id === "string") {