import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm'; import BaseModel from 'Common/Models/BaseModel'; import User from './User'; import Project from './Project'; import CrudApiEndpoint from 'Common/Types/Database/CrudApiEndpoint'; import Route from 'Common/Types/API/Route'; import TableColumnType from 'Common/Types/Database/TableColumnType'; import TableColumn from 'Common/Types/Database/TableColumn'; import ColumnType from 'Common/Types/Database/ColumnType'; import ObjectID from 'Common/Types/ObjectID'; import TableAccessControl from 'Common/Types/Database/AccessControl/TableAccessControl'; import Permission from 'Common/Types/Permission'; import ColumnAccessControl from 'Common/Types/Database/AccessControl/ColumnAccessControl'; import TenantColumn from 'Common/Types/Database/TenantColumn'; import TableMetadata from 'Common/Types/Database/TableMetadata'; import EnableWorkflow from 'Common/Types/Model/EnableWorkflow'; import IconProp from 'Common/Types/Icon/IconProp'; import ScheduledMaintenance from './ScheduledMaintenance'; import CanAccessIfCanReadOn from 'Common/Types/Database/CanAccessIfCanReadOn'; @CanAccessIfCanReadOn('scheduledMaintenance') @TenantColumn('projectId') @TableAccessControl({ create: [ Permission.ProjectOwner, Permission.ProjectAdmin, Permission.ProjectMember, Permission.CanCreateScheduledMaintenanceInternalNote, ], read: [ Permission.ProjectOwner, Permission.ProjectAdmin, Permission.ProjectMember, Permission.CanReadScheduledMaintenanceInternalNote, ], delete: [ Permission.ProjectOwner, Permission.ProjectAdmin, Permission.ProjectMember, Permission.CanDeleteScheduledMaintenanceInternalNote, ], update: [ Permission.ProjectOwner, Permission.ProjectAdmin, Permission.ProjectMember, Permission.CanEditScheduledMaintenanceInternalNote, ], }) @EnableWorkflow({ create: true, delete: true, update: true, read: true, }) @CrudApiEndpoint(new Route('/scheduled-maintenance-internal-note')) @Entity({ name: 'ScheduledMaintenanceInternalNote', }) @TableMetadata({ tableName: 'ScheduledMaintenanceInternalNote', singularName: 'Scheduled Event Internal Note', pluralName: 'Scheduled Event Internal Notes', icon: IconProp.Lock, tableDescription: "Manage internal or postmortem note for your scheduled event" }) export default class ScheduledMaintenanceInternalNote extends BaseModel { @ColumnAccessControl({ create: [ Permission.ProjectOwner, Permission.ProjectAdmin, Permission.ProjectMember, Permission.CanCreateScheduledMaintenanceInternalNote, ], read: [ Permission.ProjectOwner, Permission.ProjectAdmin, Permission.ProjectMember, Permission.CanReadScheduledMaintenanceInternalNote, ], update: [], }) @TableColumn({ manyToOneRelationColumn: 'projectId', type: TableColumnType.Entity, modelType: Project, }) @ManyToOne( (_type: string) => { return Project; }, { eager: false, nullable: true, onDelete: 'CASCADE', orphanedRowAction: 'nullify', } ) @JoinColumn({ name: 'projectId' }) public project?: Project = undefined; @ColumnAccessControl({ create: [ Permission.ProjectOwner, Permission.ProjectAdmin, Permission.ProjectMember, Permission.CanCreateScheduledMaintenanceInternalNote, ], read: [ Permission.ProjectOwner, Permission.ProjectAdmin, Permission.ProjectMember, Permission.CanReadScheduledMaintenanceInternalNote, ], update: [], }) @Index() @TableColumn({ type: TableColumnType.ObjectID, required: true, canReadOnPopulate: true, }) @Column({ type: ColumnType.ObjectID, nullable: false, transformer: ObjectID.getDatabaseTransformer(), }) public projectId?: ObjectID = undefined; @ColumnAccessControl({ create: [ Permission.ProjectOwner, Permission.ProjectAdmin, Permission.ProjectMember, Permission.CanCreateScheduledMaintenanceInternalNote, ], read: [ Permission.ProjectOwner, Permission.ProjectAdmin, Permission.ProjectMember, Permission.CanReadScheduledMaintenanceInternalNote, ], update: [], }) @TableColumn({ manyToOneRelationColumn: 'scheduledMaintenanceId', type: TableColumnType.Entity, modelType: ScheduledMaintenance, }) @ManyToOne( (_type: string) => { return ScheduledMaintenance; }, { eager: false, nullable: true, onDelete: 'CASCADE', orphanedRowAction: 'nullify', } ) @JoinColumn({ name: 'scheduledMaintenanceId' }) public scheduledMaintenance?: ScheduledMaintenance = undefined; @ColumnAccessControl({ create: [ Permission.ProjectOwner, Permission.ProjectAdmin, Permission.ProjectMember, Permission.CanCreateScheduledMaintenanceInternalNote, ], read: [ Permission.ProjectOwner, Permission.ProjectAdmin, Permission.ProjectMember, Permission.CanReadScheduledMaintenanceInternalNote, ], update: [], }) @Index() @TableColumn({ type: TableColumnType.ObjectID, required: true }) @Column({ type: ColumnType.ObjectID, nullable: false, transformer: ObjectID.getDatabaseTransformer(), }) public scheduledMaintenanceId?: ObjectID = undefined; @ColumnAccessControl({ create: [ Permission.ProjectOwner, Permission.ProjectAdmin, Permission.ProjectMember, Permission.CanCreateScheduledMaintenanceInternalNote, ], read: [ Permission.ProjectOwner, Permission.ProjectAdmin, Permission.ProjectMember, Permission.CanReadScheduledMaintenanceInternalNote, ], update: [], }) @TableColumn({ manyToOneRelationColumn: 'createdByUserId', type: TableColumnType.Entity, modelType: User, }) @ManyToOne( (_type: string) => { return User; }, { eager: false, nullable: true, onDelete: 'CASCADE', orphanedRowAction: 'nullify', } ) @JoinColumn({ name: 'createdByUserId' }) public createdByUser?: User = undefined; @ColumnAccessControl({ create: [ Permission.ProjectOwner, Permission.ProjectAdmin, Permission.ProjectMember, Permission.CanCreateScheduledMaintenanceInternalNote, ], read: [ Permission.ProjectOwner, Permission.ProjectAdmin, Permission.ProjectMember, Permission.CanReadScheduledMaintenanceInternalNote, ], update: [], }) @TableColumn({ type: TableColumnType.ObjectID }) @Column({ type: ColumnType.ObjectID, nullable: true, transformer: ObjectID.getDatabaseTransformer(), }) public createdByUserId?: ObjectID = undefined; @ColumnAccessControl({ create: [], read: [], update: [], }) @TableColumn({ manyToOneRelationColumn: 'deletedByUserId', type: TableColumnType.ObjectID, }) @ManyToOne( (_type: string) => { return User; }, { cascade: false, eager: false, nullable: true, onDelete: 'CASCADE', orphanedRowAction: 'nullify', } ) @JoinColumn({ name: 'deletedByUserId' }) public deletedByUser?: User = undefined; @ColumnAccessControl({ create: [], read: [], update: [], }) @TableColumn({ type: TableColumnType.ObjectID }) @Column({ type: ColumnType.ObjectID, nullable: true, transformer: ObjectID.getDatabaseTransformer(), }) public deletedByUserId?: ObjectID = undefined; @ColumnAccessControl({ create: [ Permission.ProjectOwner, Permission.ProjectAdmin, Permission.ProjectMember, Permission.CanCreateScheduledMaintenanceInternalNote, ], read: [ Permission.ProjectOwner, Permission.ProjectAdmin, Permission.ProjectMember, Permission.CanReadScheduledMaintenanceInternalNote, ], update: [ Permission.ProjectOwner, Permission.ProjectAdmin, Permission.ProjectMember, Permission.CanEditScheduledMaintenanceInternalNote, ], }) @TableColumn({ type: TableColumnType.Markdown }) @Column({ type: ColumnType.Markdown, nullable: false, unique: false, }) public note?: string = undefined; }