Files
edr-platform/apps/edr-freight-api/src/modules/contracts/entities/contract-clearance-cycle.entity.ts
2026-06-26 23:24:48 +00:00

38 lines
1.3 KiB
TypeScript

import { BaseEntity } from '@edr/api-common';
import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm';
import { Contract } from './contract.entity';
/**
* One pre-booking clearance round on a contract (Path B). GENERAL contracts run
* many cycles; ONE_TIME uses cycle_number = 1. The booking GL creates is linked
* back via bookingId. See §5.16.
*/
@Entity({ schema: 'freight', name: 'contract_clearance_cycles' })
@Index(['contractId'])
export class ContractClearanceCycle extends BaseEntity {
@Column({ name: 'contract_id', type: 'uuid' })
contractId!: string;
@ManyToOne(() => Contract, (c) => c.clearanceCycles, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'contract_id' })
contract?: Contract;
@Column({ name: 'cycle_number', type: 'int' })
cycleNumber!: number;
@Column({ name: 'status', type: 'varchar', length: 40, default: 'AWAITING_DOCUMENTS' })
status!: string;
@Column({ name: 'booking_id', type: 'uuid', nullable: true })
bookingId?: string | null;
@Column({ name: 'started_at', type: 'timestamptz', default: () => 'now()' })
startedAt!: Date;
@Column({ name: 'clearance_ready_at', type: 'timestamptz', nullable: true })
clearanceReadyAt?: Date | null;
@Column({ name: 'completed_at', type: 'timestamptz', nullable: true })
completedAt?: Date | null;
}