import { Column, Entity, JoinColumn, JoinTable, ManyToMany, ManyToOne, OneToMany } from "typeorm"; import { BaseEntity } from "../../../common/entities/base.entity"; import { TMWorkspace } from "./workspace.entity"; import { TMTaskPhase } from "./task-phase.entity"; import { User } from "../../users/entities/user.entity"; @Entity("tm_projects") export class TMProject extends BaseEntity { @Column({ type: "varchar", length: 150 }) name: string; @Column({ type: "varchar", length: 150, nullable: true }) ownerName: string; @Column({ type: "text", nullable: true }) description: string; @Column({ type: "timestamptz", nullable: true }) startDate: Date; @Column({ type: "text", nullable: true }) backgroundPicture: string; @Column({ type: "varchar", length: 20, nullable: true }) backgroundColor: string; @Column({ type: "boolean", default: true }) isActive: boolean; // --- Relations --- @ManyToOne(() => TMWorkspace, (workspace) => workspace.projects, { nullable: false, onDelete: "RESTRICT", }) @JoinColumn({ name: "workspaceId" }) workspace: TMWorkspace; @Column({ type: "uuid" }) workspaceId: string; @OneToMany(() => TMTaskPhase, (taskPhase) => taskPhase.project, { cascade: ["insert", "update"], }) taskPhases: TMTaskPhase[]; @ManyToMany(() => User, (user) => user.projects) @JoinTable({ name: "tm_project_users", joinColumn: { name: "projectId", referencedColumnName: "id" }, inverseJoinColumn: { name: "userId", referencedColumnName: "id" }, }) users: User[]; }