Files
dmail-api/src/modules/users/entities/user.entity.ts
T
2025-07-28 12:38:38 +03:30

84 lines
2.7 KiB
TypeScript

import { Collection, Entity, EntityRepositoryType, ManyToOne, OneToMany, Opt, Property, Unique } from "@mikro-orm/core";
import { RefreshToken } from "./refresh-token.entity";
import { Role } from "./role.entity";
import { BaseEntity } from "../../../common/entities/base.entity";
import { Business } from "../../businesses/entities/business.entity";
import { Domain } from "../../domains/entities/domain.entity";
import { Template } from "../../templates/entities/template.entity";
import { UserRepository } from "../repositories/user.repository";
@Entity({ repository: () => UserRepository })
@Unique({ properties: ["userName", "domain"], name: "unique_user_name_domain", options: { where: "deleted_at is null" } })
export class User extends BaseEntity {
@Property({ type: "varchar", length: 150, nullable: false })
title!: string;
@Property({ type: "varchar", length: 50, nullable: true })
userName!: string;
@Property({ type: "varchar", length: 150, nullable: false })
password!: string;
@Property({ type: "varchar", length: 255, nullable: true })
profilePic?: string;
@Property({ type: "varchar", length: 255, nullable: false })
emailAddress!: string;
@Property({ type: "boolean", default: false })
emailEnabled: boolean & Opt;
@Property({ type: "bigint", nullable: false, default: 134_217_728 }) // 128MB default
emailQuota!: number;
@Property({ type: "bigint", nullable: false, default: 0 })
emailQuotaUsed!: number & Opt;
// Email account integration fields
@Property({ type: "varchar", length: 255, nullable: false })
wildduckUserId!: string;
@Property({ type: "varchar", length: 255, nullable: true })
displayName?: string;
@Property({ type: "timestamptz", nullable: true })
lastQuotaSync?: Date;
@Property({ type: "json", nullable: true })
forwarders?: string[];
@Property({ default: true, nullable: false })
isActive: boolean & Opt;
// Two-Factor Authentication fields
@Property({ type: "boolean", default: false })
is2FAEnabled: boolean & Opt;
@Property({ type: "timestamptz", nullable: true })
twoFactorEnabledAt?: Date;
// Push notification tokens from different devices
@Property({ type: "json", nullable: true })
pushTokens?: string[];
//=========================
@OneToMany(() => RefreshToken, (token) => token.user)
refreshTokens = new Collection<RefreshToken>(this);
@ManyToOne(() => Role, { deleteRule: "restrict" })
role!: Role;
@ManyToOne(() => Business, { deleteRule: "cascade" })
business!: Business;
@ManyToOne(() => Domain, { deleteRule: "restrict" })
domain!: Domain;
@ManyToOne(() => Template, { deleteRule: "restrict", nullable: true })
template?: Template;
[EntityRepositoryType]?: UserRepository;
}