prettier formatted /util

This commit is contained in:
developomp 2021-10-20 09:16:59 +09:00
parent 5f14f82f5c
commit 14e42d025a
9 changed files with 38 additions and 31 deletions

View File

@ -12,24 +12,30 @@ export class DmChannelDTO {
type: number; type: number;
static async from(channel: Channel, excluded_recipients: string[] = [], origin_channel_id?: string) { static async from(channel: Channel, excluded_recipients: string[] = [], origin_channel_id?: string) {
const obj = new DmChannelDTO() const obj = new DmChannelDTO();
obj.icon = channel.icon || null obj.icon = channel.icon || null;
obj.id = channel.id obj.id = channel.id;
obj.last_message_id = channel.last_message_id || null obj.last_message_id = channel.last_message_id || null;
obj.name = channel.name || null obj.name = channel.name || null;
obj.origin_channel_id = origin_channel_id || null obj.origin_channel_id = origin_channel_id || null;
obj.owner_id = channel.owner_id obj.owner_id = channel.owner_id;
obj.type = channel.type obj.type = channel.type;
obj.recipients = (await Promise.all(channel.recipients!.filter(r => !excluded_recipients.includes(r.user_id)).map(async r => { obj.recipients = (
return await User.findOneOrFail({ where: { id: r.user_id }, select: PublicUserProjection }) await Promise.all(
}))).map(u => new MinimalPublicUserDTO(u)) channel
return obj .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 { excludedRecipients(excluded_recipients: string[]): DmChannelDTO {
return { return {
...this, ...this,
recipients: this.recipients.filter(r => !excluded_recipients.includes(r.id)) recipients: this.recipients.filter((r) => !excluded_recipients.includes(r.id)),
} };
} }
} }

View File

@ -8,10 +8,10 @@ export class MinimalPublicUserDTO {
username: string; username: string;
constructor(user: User) { constructor(user: User) {
this.avatar = user.avatar this.avatar = user.avatar;
this.discriminator = user.discriminator this.discriminator = user.discriminator;
this.id = user.id this.id = user.id;
this.public_flags = user.public_flags this.public_flags = user.public_flags;
this.username = user.username this.username = user.username;
} }
} }

View File

@ -10,7 +10,7 @@ export class Migration extends BaseClassWithoutId {
@PrimaryIdAutoGenerated() @PrimaryIdAutoGenerated()
id: number; id: number;
@Column({ type: 'bigint' }) @Column({ type: "bigint" })
timestamp: number; timestamp: number;
@Column() @Column()

View File

@ -9,7 +9,8 @@ export class ApiError extends Error {
} }
withDefaultParams(): ApiError { 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; return this;
} }

View File

@ -1,3 +1,3 @@
export function containsAll(arr: any[], target: any[]) { export function containsAll(arr: any[], target: any[]) {
return target.every(v => arr.includes(v)); return target.every((v) => arr.includes(v));
} }

View File

@ -8,9 +8,9 @@ export function FieldErrors(fields: Record<string, { code?: string; message: str
_errors: [ _errors: [
{ {
message, message,
code: code || "BASE_TYPE_INVALID" code: code || "BASE_TYPE_INVALID",
} },
] ],
})) }))
); );
} }

View File

@ -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 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 SELF_DELETE_DISABLE: BitFlag(30), // can disable/delete own account
DEBTABLE: BitFlag(31), // can use pay-to-use features 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) { any(permission: RightResolvable, checkOperator = true) {