67 lines
2.2 KiB
TypeScript
67 lines
2.2 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: 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({ default: true, nullable: false })
|
|
isActive: boolean & Opt;
|
|
|
|
//=========================
|
|
|
|
@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;
|
|
}
|