43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { Column, Entity, JoinColumn, JoinTable, ManyToMany, ManyToOne, OneToMany } from "typeorm";
|
|
import { BaseEntity } from "../../../common/entities/base.entity";
|
|
import { TMWorkspaceType } from "./workspace-type.entity";
|
|
import { TMProject } from "./project.entity";
|
|
import { User } from "../../users/entities/user.entity";
|
|
|
|
@Entity("tm_workspaces")
|
|
export class TMWorkspace extends BaseEntity {
|
|
@Column({ type: "varchar", length: 100 })
|
|
name: string;
|
|
|
|
@Column({ type: "text", nullable: true })
|
|
description: string;
|
|
|
|
@Column({ type: "varchar", length: 20 })
|
|
color: string;
|
|
|
|
@Column({ type: "boolean", default: true })
|
|
isActive: boolean;
|
|
|
|
// --- Relations ---
|
|
|
|
@ManyToOne(() => TMWorkspaceType, { nullable: false, eager: true })
|
|
@JoinColumn({ name: "workspaceTypeId" })
|
|
workspaceType: TMWorkspaceType;
|
|
|
|
@Column({ type: "uuid" })
|
|
workspaceTypeId: string;
|
|
|
|
@OneToMany(() => TMProject, (project) => project.workspace, {
|
|
cascade: ["insert", "update"],
|
|
})
|
|
projects: TMProject[];
|
|
|
|
@ManyToMany(() => User, (user) => user.workspaces)
|
|
@JoinTable({
|
|
name: "tm_workspace_users",
|
|
joinColumn: { name: "workspaceId", referencedColumnName: "id" },
|
|
inverseJoinColumn: { name: "userId", referencedColumnName: "id" },
|
|
})
|
|
users: User[];
|
|
}
|