diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/src/dtos/DmChannelDTO.ts | 36 | ||||
-rw-r--r-- | util/src/dtos/UserDTO.ts | 12 | ||||
-rw-r--r-- | util/src/dtos/index.ts | 2 | ||||
-rw-r--r-- | util/src/entities/Invite.ts | 2 | ||||
-rw-r--r-- | util/src/entities/Migration.ts | 2 | ||||
-rw-r--r-- | util/src/util/ApiError.ts | 3 | ||||
-rw-r--r-- | util/src/util/Array.ts | 4 | ||||
-rw-r--r-- | util/src/util/FieldError.ts | 6 | ||||
-rw-r--r-- | util/src/util/Rights.ts | 2 |
9 files changed, 38 insertions, 31 deletions
diff --git a/util/src/dtos/DmChannelDTO.ts b/util/src/dtos/DmChannelDTO.ts index 8b7a18fd..226b2f9d 100644 --- a/util/src/dtos/DmChannelDTO.ts +++ b/util/src/dtos/DmChannelDTO.ts @@ -12,24 +12,30 @@ export class DmChannelDTO { type: number; static async from(channel: Channel, excluded_recipients: string[] = [], origin_channel_id?: string) { - const obj = new DmChannelDTO() - obj.icon = channel.icon || null - obj.id = channel.id - obj.last_message_id = channel.last_message_id || null - obj.name = channel.name || null - obj.origin_channel_id = origin_channel_id || null - obj.owner_id = channel.owner_id - obj.type = channel.type - obj.recipients = (await Promise.all(channel.recipients!.filter(r => !excluded_recipients.includes(r.user_id)).map(async r => { - return await User.findOneOrFail({ where: { id: r.user_id }, select: PublicUserProjection }) - }))).map(u => new MinimalPublicUserDTO(u)) - return obj + const obj = new DmChannelDTO(); + obj.icon = channel.icon || null; + obj.id = channel.id; + obj.last_message_id = channel.last_message_id || null; + obj.name = channel.name || null; + obj.origin_channel_id = origin_channel_id || null; + obj.owner_id = channel.owner_id; + obj.type = channel.type; + obj.recipients = ( + await Promise.all( + channel + .recipients!.filter((r) => !excluded_recipients.includes(r.user_id)) + .map(async (r) => { + return await User.findOneOrFail({ where: { id: r.user_id }, select: PublicUserProjection }); + }) + ) + ).map((u) => new MinimalPublicUserDTO(u)); + return obj; } excludedRecipients(excluded_recipients: string[]): DmChannelDTO { return { ...this, - recipients: this.recipients.filter(r => !excluded_recipients.includes(r.id)) - } + recipients: this.recipients.filter((r) => !excluded_recipients.includes(r.id)), + }; } -} \ No newline at end of file +} diff --git a/util/src/dtos/UserDTO.ts b/util/src/dtos/UserDTO.ts index f09b5f4e..ee2752a4 100644 --- a/util/src/dtos/UserDTO.ts +++ b/util/src/dtos/UserDTO.ts @@ -8,10 +8,10 @@ export class MinimalPublicUserDTO { username: string; constructor(user: User) { - this.avatar = user.avatar - this.discriminator = user.discriminator - this.id = user.id - this.public_flags = user.public_flags - this.username = user.username + this.avatar = user.avatar; + this.discriminator = user.discriminator; + this.id = user.id; + this.public_flags = user.public_flags; + this.username = user.username; } -} \ No newline at end of file +} diff --git a/util/src/dtos/index.ts b/util/src/dtos/index.ts index 13702342..0e8f8459 100644 --- a/util/src/dtos/index.ts +++ b/util/src/dtos/index.ts @@ -1,2 +1,2 @@ export * from "./DmChannelDTO"; -export * from "./UserDTO"; \ No newline at end of file +export * from "./UserDTO"; diff --git a/util/src/entities/Invite.ts b/util/src/entities/Invite.ts index b3e00957..6ac64ddc 100644 --- a/util/src/entities/Invite.ts +++ b/util/src/entities/Invite.ts @@ -71,7 +71,7 @@ export class Invite extends BaseClassWithoutId { @Column({ nullable: true }) target_user_type?: number; - @Column({ nullable: true}) + @Column({ nullable: true }) vanity_url?: boolean; static async joinGuild(user_id: string, code: string) { diff --git a/util/src/entities/Migration.ts b/util/src/entities/Migration.ts index 7393496f..3f39ae72 100644 --- a/util/src/entities/Migration.ts +++ b/util/src/entities/Migration.ts @@ -10,7 +10,7 @@ export class Migration extends BaseClassWithoutId { @PrimaryIdAutoGenerated() id: number; - @Column({ type: 'bigint' }) + @Column({ type: "bigint" }) timestamp: number; @Column() diff --git a/util/src/util/ApiError.ts b/util/src/util/ApiError.ts index c133e6e7..f1a9b4f6 100644 --- a/util/src/util/ApiError.ts +++ b/util/src/util/ApiError.ts @@ -9,7 +9,8 @@ export class ApiError extends Error { } withDefaultParams(): ApiError { - if (this.defaultParams) return new ApiError(applyParamsToString(this.message, this.defaultParams), this.code, this.httpStatus); + if (this.defaultParams) + return new ApiError(applyParamsToString(this.message, this.defaultParams), this.code, this.httpStatus); return this; } diff --git a/util/src/util/Array.ts b/util/src/util/Array.ts index 27f7c961..5a45d1b5 100644 --- a/util/src/util/Array.ts +++ b/util/src/util/Array.ts @@ -1,3 +1,3 @@ export function containsAll(arr: any[], target: any[]) { - return target.every(v => arr.includes(v)); -} \ No newline at end of file + return target.every((v) => arr.includes(v)); +} diff --git a/util/src/util/FieldError.ts b/util/src/util/FieldError.ts index 0b3f93d2..406b33e8 100644 --- a/util/src/util/FieldError.ts +++ b/util/src/util/FieldError.ts @@ -8,9 +8,9 @@ export function FieldErrors(fields: Record<string, { code?: string; message: str _errors: [ { message, - code: code || "BASE_TYPE_INVALID" - } - ] + code: code || "BASE_TYPE_INVALID", + }, + ], })) ); } diff --git a/util/src/util/Rights.ts b/util/src/util/Rights.ts index 5edd9142..f0d00baf 100644 --- a/util/src/util/Rights.ts +++ b/util/src/util/Rights.ts @@ -56,7 +56,7 @@ export class Rights extends BitField { INVITE_USERS: BitFlag(29), // can create user-specific invites in the guilds that they have INVITE_USERS SELF_DELETE_DISABLE: BitFlag(30), // can disable/delete own account DEBTABLE: BitFlag(31), // can use pay-to-use features - CREDITABLE: BitFlag(32) // can receive money from monetisation related features + CREDITABLE: BitFlag(32), // can receive money from monetisation related features }; any(permission: RightResolvable, checkOperator = true) { |