import { Column, Entity, Index, PrimaryGeneratedColumn } from 'typeorm'; import { TimestampedEntity } from './timestamped.entity'; export enum InspectionActStatus { DRAFT = 'DRAFT', READY = 'READY', CLOSED = 'CLOSED', CANCELLED = 'CANCELLED', RECTIFIED = 'RECTIFIED', } @Entity({ name: 'inspection_acts' }) @Index('uq_inspection_acts_one_draft_per_visit', ['visitId'], { unique: true, where: "status = 'DRAFT'" }) @Index('uq_inspection_acts_year_number', ['actYear', 'actNumber'], { unique: true }) @Index('uq_inspection_acts_code', ['code'], { unique: true }) @Index('idx_inspection_acts_visit_status', ['visitId', 'status']) @Index('idx_inspection_acts_occurred_at', ['occurredAt']) @Index('idx_inspection_acts_created_by', ['createdBy']) export class InspectionAct extends TimestampedEntity { @PrimaryGeneratedColumn('uuid') id!: string; @Column({ name: 'visit_id', type: 'uuid' }) visitId!: string; @Column({ name: 'act_year', type: 'integer' }) actYear!: number; @Column({ name: 'act_number', type: 'integer' }) actNumber!: number; @Column({ type: 'varchar', length: 24 }) code!: string; @Column({ type: 'varchar', length: 24, default: InspectionActStatus.DRAFT }) status!: InspectionActStatus; @Column({ name: 'occurred_at', type: 'timestamptz' }) occurredAt!: Date; @Column({ type: 'varchar', length: 200 }) title!: string; @Column({ type: 'text' }) summary!: string; @Column({ type: 'text', nullable: true }) observations!: string | null; @Column({ name: 'current_version', type: 'integer', default: 0 }) currentVersion!: number; @Column({ name: 'cancellation_reason', type: 'text', nullable: true }) cancellationReason!: string | null; @Column({ name: 'closed_at', type: 'timestamptz', nullable: true }) closedAt!: Date | null; @Column({ name: 'closed_by', type: 'uuid', nullable: true }) closedBy!: string | null; @Column({ name: 'closure_sha256', type: 'char', length: 64, nullable: true }) closureSha256!: string | null; @Column({ name: 'created_by', type: 'uuid', nullable: true }) createdBy!: string | null; @Column({ name: 'updated_by', type: 'uuid', nullable: true }) updatedBy!: string | null; }