import { Column, Entity, Index, ManyToMany, ManyToOne } from "typeorm"; import { BaseEntity } from "../../../common/entities/base.entity"; import { DanakService } from "../../danak-services/entities/danak-service.entity"; import { UserGroup } from "../../users/entities/user-group.entity"; @Entity() @Index(["isPublic", "createdAt"]) export class Announcement extends BaseEntity { @Column({ type: "varchar", length: 100 }) title: string; @Column({ type: "text" }) content: string; @Column({ type: "timestamp", default: null, nullable: true }) publishAt: Date; //TODO: Add service here //TODO: Add customer here @ManyToOne(() => DanakService, (service) => service.announcements, { eager: true, onDelete: "CASCADE" }) service: DanakService; @Column({ type: "boolean", default: false }) isImportant: boolean; @ManyToMany(() => UserGroup, (group) => group.announcements) targetGroups: UserGroup[]; @Column({ default: false }) isPublic: boolean; isPublicAnnouncement(): boolean { return this.isPublic; } }