diff --git a/src/entities/category.entity.ts b/src/entities/category.entity.ts index b7a8e987..e7a1323b 100644 --- a/src/entities/category.entity.ts +++ b/src/entities/category.entity.ts @@ -1,17 +1,22 @@ -import { Collection, Entity, ManyToMany, Property } from "@mikro-orm/postgresql"; +import { + Collection, + Entity, + ManyToMany, + Property, +} from "@mikro-orm/postgresql"; import { BaseEntity } from "@common/database"; import { Post } from "./index"; @Entity() export class Category extends BaseEntity { @Property({ index: true }) - name!: string; + name!: string; @Property() - description!: string; + description!: string; @ManyToMany(() => Post, post => post.categories) - posts = new Collection(this); + posts = new Collection(this); constructor(partial?: Partial) { super(); diff --git a/src/entities/comment.entity.ts b/src/entities/comment.entity.ts index 911e058e..819dd81e 100644 --- a/src/entities/comment.entity.ts +++ b/src/entities/comment.entity.ts @@ -6,18 +6,17 @@ import type { Post, User } from "./index"; @Entity() export class Comment extends BaseEntity { @Property() - body!: string; + body!: string; @ManyToOne({ - eager: false, + index: true, }) - post!: Rel>; + post!: Rel>; @ManyToOne({ - eager: false, index: true, }) - author!: Rel>; + author!: Rel>; constructor(partial?: Partial) { super(); diff --git a/src/entities/conversation.entity.ts b/src/entities/conversation.entity.ts index 7ec1c8c1..3eb947be 100644 --- a/src/entities/conversation.entity.ts +++ b/src/entities/conversation.entity.ts @@ -1,19 +1,25 @@ import { BaseEntity } from "@common/database"; -import { Collection, Entity, ManyToMany, OneToMany, Property } from "@mikro-orm/postgresql"; +import { + Collection, + Entity, + ManyToMany, + OneToMany, + Property, +} from "@mikro-orm/postgresql"; import { Message, User } from "./index"; @Entity() export class Conversation extends BaseEntity { @Property({ index: true }) - chatName!: string; + chatName!: string; @ManyToMany(() => User, user => user.conversations, { index: true }) - users = new Collection(this); + users = new Collection(this); @OneToMany(() => Message, message => message.conversation, { orphanRemoval: true, }) - messages = new Collection(this); + messages = new Collection(this); constructor(partial?: Partial) { super(); diff --git a/src/entities/message.entity.ts b/src/entities/message.entity.ts index 773edd99..96150cf5 100644 --- a/src/entities/message.entity.ts +++ b/src/entities/message.entity.ts @@ -1,30 +1,28 @@ import { BaseEntity } from "@common/database"; -import type { Opt , Ref } from "@mikro-orm/postgresql"; +import type { Opt, Ref } from "@mikro-orm/postgresql"; import { Entity, ManyToOne, Property, Rel } from "@mikro-orm/postgresql"; import type { Conversation, User } from "./index"; @Entity() export class Message extends BaseEntity { @Property() - body!: string; + body!: string; @ManyToOne({ - eager: false, index: true, }) - sender!: Rel>; + sender!: Rel>; @ManyToOne({ - eager: false, index: true, }) - conversation!: Rel>; + conversation!: Rel>; @Property() - isRead: boolean & Opt = false; + isRead: boolean & Opt = false; @Property() - readAt?: Date; + readAt?: Date; constructor(partial?: Partial) { super(); diff --git a/src/entities/news-letter.entity.ts b/src/entities/news-letter.entity.ts index 1cb5ae88..bb0d8ed3 100644 --- a/src/entities/news-letter.entity.ts +++ b/src/entities/news-letter.entity.ts @@ -1,16 +1,16 @@ -import { Entity ,Property} from "@mikro-orm/postgresql"; +import { Entity, Property } from "@mikro-orm/postgresql"; import { BaseEntity } from "@common/database"; @Entity() export class NewsLetter extends BaseEntity { @Property({ index: true, unique: true }) - name!: string; + name!: string; @Property({ columnType: "text" }) - content!: string; + content!: string; @Property() - sentAt?: Date; + sentAt?: Date; constructor(partial?: Partial) { super(); diff --git a/src/entities/otp-log.entity.ts b/src/entities/otp-log.entity.ts index df6e579b..15d4e9a8 100644 --- a/src/entities/otp-log.entity.ts +++ b/src/entities/otp-log.entity.ts @@ -1,4 +1,4 @@ -import type { Opt ,Ref } from "@mikro-orm/postgresql"; +import type { Opt, Ref } from "@mikro-orm/postgresql"; import { Entity, ManyToOne, Property, Rel } from "@mikro-orm/postgresql"; import { BaseEntity } from "@common/database"; import type { User } from "./user.entity"; @@ -6,22 +6,21 @@ import type { User } from "./user.entity"; @Entity() export class OtpLog extends BaseEntity { @Property() - expiresIn!: Date; + expiresIn!: Date; @Property({ length: 20, index: true, }) - otpCode?: string; + otpCode?: string; @ManyToOne({ - eager: false, index: true, }) - user!: Rel>; + user!: Rel>; @Property() - isUsed: boolean & Opt = false; + isUsed: boolean & Opt = false; constructor(partial?: Partial) { super(); diff --git a/src/entities/points-redemption-log.entity.ts b/src/entities/points-redemption-log.entity.ts index 6d81865f..6dc5a283 100644 --- a/src/entities/points-redemption-log.entity.ts +++ b/src/entities/points-redemption-log.entity.ts @@ -6,13 +6,13 @@ import type { User } from "./user.entity"; @Entity() export class PointRedemptionLog extends BaseEntity { @Property() - points!: number; + points!: number; @Property({ columnType: "numeric(9,2)" }) - amount!: string; + amount!: string; @ManyToOne() - user!: Rel>; + user!: Rel>; constructor(partial?: Partial) { super(); diff --git a/src/entities/post.entity.ts b/src/entities/post.entity.ts index 036a2948..32c18454 100644 --- a/src/entities/post.entity.ts +++ b/src/entities/post.entity.ts @@ -39,20 +39,18 @@ export class Post extends BaseEntity { @Property() readCount: number & Opt = 0; - @Property() + @Property({ index: true }) published: boolean & Opt = false; @Property() favoritesCount: number & Opt = 0; @ManyToOne({ - eager: false, index: true, }) author!: Rel>; @OneToMany(() => Comment, comment => comment.post, { - eager: false, orphanRemoval: true, }) comments = new Collection(this); @@ -76,9 +74,9 @@ export class Post extends BaseEntity { @BeforeUpdate() async generateSlug(arguments_: EventArgs) { if (arguments_.changeSet?.payload?.title) { - this.slug - = `${slugify(this.title) - }-${Math.trunc(Math.random() * 36 ** 6).toString(36)}`; + this.slug = `${slugify( + this.title, + )}-${Math.trunc(Math.random() * 36 ** 6).toString(36)}`; } this.readingTime = this.getReadingTime(this.content); } diff --git a/src/entities/protocol.entity.ts b/src/entities/protocol.entity.ts index 1b2100b3..9e526606 100644 --- a/src/entities/protocol.entity.ts +++ b/src/entities/protocol.entity.ts @@ -6,16 +6,16 @@ import { BaseEntity } from "@common/database"; @Entity() export class Protocol extends BaseEntity { @Property() - loginAttemptnumbererval!: number; + loginAttemptnumbererval!: number; @Property() - loginnumberervalUnit!: string; + loginnumberervalUnit!: string; @Property() - loginMaxRetry!: number; + loginMaxRetry!: number; @Property() - otpExpiryInMinutes!: number; + otpExpiryInMinutes!: number; constructor(partial?: Partial) { super(); diff --git a/src/entities/referral.entity.ts b/src/entities/referral.entity.ts index c381e801..e1a8be5e 100644 --- a/src/entities/referral.entity.ts +++ b/src/entities/referral.entity.ts @@ -1,5 +1,12 @@ import type { Opt, Ref } from "@mikro-orm/postgresql"; -import { Entity, Enum, Index, ManyToOne, Property, Rel } from "@mikro-orm/postgresql"; +import { + Entity, + Enum, + Index, + ManyToOne, + Property, + Rel, +} from "@mikro-orm/postgresql"; import { ReferralStatus } from "@common/@types"; import { BaseEntity } from "@common/database"; import type { User } from "./user.entity"; @@ -9,12 +16,12 @@ export class Referral extends BaseEntity { @ManyToOne({ index: true, }) - referrer!: Rel>; + referrer!: Rel>; @Property({ index: true, }) - mobileNumber!: string; + mobileNumber!: string; @Index() @Enum(() => ReferralStatus) diff --git a/src/entities/refresh-token.entity.ts b/src/entities/refresh-token.entity.ts index b6f150ed..d368ae8c 100644 --- a/src/entities/refresh-token.entity.ts +++ b/src/entities/refresh-token.entity.ts @@ -6,15 +6,15 @@ import type { User } from "./user.entity"; @Entity() export class RefreshToken extends BaseEntity { @Property() - expiresIn!: Date; + expiresIn!: Date; @ManyToOne({ - eager: false, + index: true, }) - user!: Rel>; + user!: Rel>; @Property() - isRevoked: boolean & Opt = false; + isRevoked: boolean & Opt = false; constructor(partial?: Partial) { super(); diff --git a/src/entities/subscribers.entity.ts b/src/entities/subscribers.entity.ts index 2aa2e911..466d425e 100644 --- a/src/entities/subscribers.entity.ts +++ b/src/entities/subscribers.entity.ts @@ -4,7 +4,7 @@ import { BaseEntity } from "@common/database"; @Entity() export class Subscriber extends BaseEntity { @Property({ index: true, unique: true }) - email!: string; + email!: string; constructor(partial?: Partial) { super(); diff --git a/src/entities/tag.entity.ts b/src/entities/tag.entity.ts index 8142e897..4f0f1d0d 100644 --- a/src/entities/tag.entity.ts +++ b/src/entities/tag.entity.ts @@ -1,8 +1,6 @@ import { BeforeCreate, - BeforeUpdate, - BeforeUpsert, Collection, Entity, @@ -21,16 +19,16 @@ export class Tag extends BaseEntity { index: true, unique: true, }) - title!: string; + title!: string; @Property({ columnType: "text" }) - description!: string; + description!: string; @Property({ index: true }) - slug?: string; + slug?: string; @ManyToMany(() => Post, post => post.tags) - posts = new Collection(this); + posts = new Collection(this); constructor(partial?: Partial) { super(); diff --git a/src/entities/user.entity.ts b/src/entities/user.entity.ts index 34bdc729..2466bdd4 100644 --- a/src/entities/user.entity.ts +++ b/src/entities/user.entity.ts @@ -1,11 +1,7 @@ -import type { - FilterQuery, -} from "@mikro-orm/postgresql"; +import type { FilterQuery } from "@mikro-orm/postgresql"; import { BeforeCreate, - BeforeUpdate, - BeforeUpsert, Collection, Embeddable, @@ -13,6 +9,7 @@ import { Entity, Enum, EventArgs, + Index, ManyToMany, OneToMany, Property, @@ -67,6 +64,7 @@ export class User extends BaseEntity { @Property() isTwoFactorEnabled? = false; + @Index() @Enum({ items: () => Roles, array: true }) roles?: Roles[] = [Roles.AUTHOR]; @@ -78,7 +76,6 @@ export class User extends BaseEntity { @OneToMany(() => Post, post => post.author, { orphanRemoval: true, - eager: false }) posts = new Collection(this);