Files
edr-platform/apps/edr-freight-api/src/modules/warehouses/entities/warehouse.entity.ts
Hagernesh ba79b36d90 feat(warehouses): record container vs bulk freight type
Nullable freight_type on the warehouse, null meaning it takes both.
No backfill: every existing warehouse is unrestricted today and
writing a value would narrow allocation behind the operator's back.
Reuses FREIGHT_TYPES from the booking entity rather than a third copy
of the same two values.
2026-08-28 15:04:39 +00:00

84 lines
3.0 KiB
TypeScript

import { BaseEntity } from '@edr/api-common';
import { Column, Entity, Index, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
import { FREIGHT_TYPES, FreightType } from '../../bookings/entities/booking.entity';
import { Facility } from '../../facilities/entities/facility.entity';
import { WarehouseYard } from './warehouse-yard.entity';
export const WAREHOUSE_TYPES = ['OPEN_WAREHOUSE', 'CLOSED_WAREHOUSE'] as const;
export type WarehouseType = (typeof WAREHOUSE_TYPES)[number];
export { FREIGHT_TYPES };
export type { FreightType };
export const WAREHOUSE_STATUSES = ['ACTIVE', 'INACTIVE'] as const;
export type WarehouseStatus = (typeof WAREHOUSE_STATUSES)[number];
@Entity({ schema: 'freight', name: 'warehouses' })
@Index(['code'], { unique: true })
@Index(['type'])
@Index(['status'])
@Index(['stationId'])
export class Warehouse extends BaseEntity {
@Column({ name: 'name', type: 'varchar', length: 160 })
name!: string;
@Column({ name: 'code', type: 'varchar', length: 40, unique: true })
code!: string;
@Column({ name: 'type', type: 'varchar', length: 32 })
type!: WarehouseType;
/**
* What the warehouse handles. Null means unrestricted — the pre-existing
* behaviour for every warehouse created before this field existed, so it
* never narrows an already-configured site.
*/
@Column({ name: 'freight_type', type: 'varchar', length: 16, nullable: true })
freightType?: FreightType | null;
@Column({ name: 'station_id', type: 'uuid', nullable: true })
stationId?: string | null;
@Column({ name: 'location_name', type: 'varchar', length: 200, nullable: true })
locationName?: string | null;
@Column({ name: 'capacity_weight', type: 'numeric', precision: 14, scale: 3, nullable: true })
capacityWeight?: number | null;
@Column({ name: 'capacity_containers', type: 'int', nullable: true })
capacityContainers?: number | null;
@Column({ name: 'current_weight', type: 'numeric', precision: 14, scale: 3, default: 0 })
currentWeight!: number;
@Column({ name: 'current_containers', type: 'int', default: 0 })
currentContainers!: number;
// Batch 2 capacity (weight + volume). maxWeight backfilled from capacityWeight.
@Column({ name: 'max_weight', type: 'numeric', precision: 14, scale: 3, nullable: true })
maxWeight?: number | null;
@Column({ name: 'max_volume', type: 'numeric', precision: 14, scale: 3, nullable: true })
maxVolume?: number | null;
@Column({ name: 'current_volume', type: 'numeric', precision: 14, scale: 3, default: 0 })
currentVolume!: number;
@Column({ name: 'status', type: 'varchar', length: 16, default: 'ACTIVE' })
status!: WarehouseStatus;
@Column({ name: 'is_active', type: 'boolean', default: true })
isActive!: boolean;
@Column({ name: 'facility_id', type: 'uuid', nullable: true })
facilityId?: string | null;
@ManyToOne(() => Facility, (facility) => facility.warehouses, { nullable: true })
@JoinColumn({ name: 'facility_id' })
facility?: Facility | null;
@OneToMany(() => WarehouseYard, (yard) => yard.warehouse)
yards?: WarehouseYard[];
}