mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
import { BaseEntity } from '@edr/api-common';
|
|
import { Column, Entity, Index, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
|
|
|
|
import { Booking } from '../../bookings/entities/booking.entity';
|
|
import { Vehicle } from '../../vehicles/entities/vehicle.entity';
|
|
import { FirstMileContainerAllocation } from './first-mile-container-allocation.entity';
|
|
|
|
export const FIRST_MILE_STATUSES = [
|
|
'PAYMENT_PENDING',
|
|
'READY_TO_TRANSIT',
|
|
'IN_TRANSIT',
|
|
'RECEIVED_TO_PORT',
|
|
] as const;
|
|
|
|
export type FirstMileStatus = (typeof FIRST_MILE_STATUSES)[number];
|
|
|
|
@Entity({ name: 'first_mile', schema: 'freight' })
|
|
@Index(['bookingId'])
|
|
@Index(['status'])
|
|
@Index(['vehicleId'])
|
|
export class FirstMile extends BaseEntity {
|
|
@Column({ name: 'booking_id', type: 'uuid' })
|
|
bookingId!: string;
|
|
|
|
@ManyToOne(() => Booking, { nullable: false, eager: false })
|
|
@JoinColumn({ name: 'booking_id' })
|
|
booking?: Booking;
|
|
|
|
@Column({ name: 'status', type: 'varchar', length: 30, default: 'PAYMENT_PENDING' })
|
|
status!: FirstMileStatus;
|
|
|
|
@Column({ name: 'advanced_payment', type: 'numeric', precision: 14, scale: 2, default: 0 })
|
|
advancedPayment!: number;
|
|
|
|
@Column({ name: 'remaining_payment', type: 'numeric', precision: 14, scale: 2, default: 0 })
|
|
remainingPayment!: number;
|
|
|
|
@Column({ name: 'paid', type: 'boolean', default: false })
|
|
paid!: boolean;
|
|
|
|
// TODO: uncomment after migration creates column
|
|
// @Column({ type: 'boolean', default: false })
|
|
// isPostPaymentCompleted!: boolean;
|
|
|
|
@Column({ name: 'estimated_km', type: 'numeric', precision: 10, scale: 2, nullable: true })
|
|
estimatedKm?: number | null;
|
|
|
|
@Column({ name: 'exact_km', type: 'numeric', precision: 10, scale: 2, nullable: true })
|
|
exactKm?: number | null;
|
|
|
|
@Column({ name: 'vehicle_id', type: 'uuid', nullable: true })
|
|
vehicleId?: string | null;
|
|
|
|
@ManyToOne(() => Vehicle, { nullable: true, eager: false })
|
|
@JoinColumn({ name: 'vehicle_id' })
|
|
vehicle?: Vehicle | null;
|
|
|
|
@OneToMany(
|
|
() => FirstMileContainerAllocation,
|
|
(containerAllocation) => containerAllocation.firstMile,
|
|
{ eager: false },
|
|
)
|
|
containerAllocations!: FirstMileContainerAllocation[];
|
|
}
|