mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 19:58:11 +00:00
booking operations and trains scheduling also allocations
This commit is contained in:
@@ -2,14 +2,18 @@ import { api as client } from '../auth/http';
|
||||
import { unwrap } from '@/utils/endpoint';
|
||||
import { URL_CONSTANTS } from '@/constants/URLS';
|
||||
import type {
|
||||
AssignBookingsPayload,
|
||||
CreateTrainSchedulePayload,
|
||||
EligibleContainerBookingsResponse,
|
||||
FreightType,
|
||||
LocomotiveRecord,
|
||||
PinWagonsPayload,
|
||||
TrainScheduleDetail,
|
||||
TrainScheduleFilters,
|
||||
TrainScheduleListItem,
|
||||
TrainSchedulePreviewPayload,
|
||||
TrainSchedulePreviewResponse,
|
||||
TrainSchedulingGlobalRules,
|
||||
YardOption,
|
||||
} from '@/types/trainScheduling';
|
||||
|
||||
@@ -17,22 +21,33 @@ interface BookingReferenceDataResponse {
|
||||
yard?: Array<YardOption & { label?: string }>;
|
||||
}
|
||||
|
||||
const pathsFor = (freightType?: FreightType) =>
|
||||
freightType === "BULK"
|
||||
? URL_CONSTANTS.TRAIN_SCHEDULING.BULK
|
||||
: URL_CONSTANTS.TRAIN_SCHEDULING.CONTAINER;
|
||||
|
||||
export const trainSchedulingService = {
|
||||
getEligibleBookings: async (
|
||||
filters?: TrainScheduleFilters,
|
||||
freightType?: FreightType,
|
||||
): Promise<EligibleContainerBookingsResponse> => {
|
||||
const useUnified = !freightType || freightType === "MIXED";
|
||||
const response = await client.get<EligibleContainerBookingsResponse>(
|
||||
URL_CONSTANTS.TRAIN_SCHEDULING.ELIGIBLE_BOOKINGS,
|
||||
{ params: filters },
|
||||
useUnified
|
||||
? URL_CONSTANTS.TRAIN_SCHEDULING.ELIGIBLE_BOOKINGS
|
||||
: pathsFor(freightType).ELIGIBLE_BOOKINGS,
|
||||
{ params: { ...filters, ...(freightType && freightType !== "MIXED" ? { freightType } : {}) } },
|
||||
);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
preview: async (
|
||||
payload: TrainSchedulePreviewPayload,
|
||||
freightType?: FreightType,
|
||||
): Promise<TrainSchedulePreviewResponse> => {
|
||||
const useUnified = !freightType || freightType === "MIXED";
|
||||
const response = await client.post<TrainSchedulePreviewResponse>(
|
||||
URL_CONSTANTS.TRAIN_SCHEDULING.PREVIEW,
|
||||
useUnified ? URL_CONSTANTS.TRAIN_SCHEDULING.PREVIEW : pathsFor(freightType).PREVIEW,
|
||||
payload,
|
||||
);
|
||||
return unwrap(response.data);
|
||||
@@ -40,31 +55,92 @@ export const trainSchedulingService = {
|
||||
|
||||
createSchedule: async (
|
||||
payload: CreateTrainSchedulePayload,
|
||||
freightType?: FreightType,
|
||||
): Promise<TrainScheduleDetail> => {
|
||||
const response = await client.post<TrainScheduleDetail>(
|
||||
URL_CONSTANTS.TRAIN_SCHEDULING.SCHEDULES,
|
||||
pathsFor(freightType).SCHEDULES,
|
||||
payload,
|
||||
);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
listSchedules: async (): Promise<TrainScheduleListItem[]> => {
|
||||
listSchedules: async (
|
||||
freightType: FreightType = "CONTAINER",
|
||||
): Promise<TrainScheduleListItem[]> => {
|
||||
const response = await client.get<TrainScheduleListItem[]>(
|
||||
URL_CONSTANTS.TRAIN_SCHEDULING.SCHEDULES,
|
||||
pathsFor(freightType === "MIXED" ? undefined : freightType).SCHEDULES,
|
||||
);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
getScheduleById: async (id: string): Promise<TrainScheduleDetail> => {
|
||||
getScheduleById: async (
|
||||
id: string,
|
||||
freightType?: FreightType,
|
||||
): Promise<TrainScheduleDetail> => {
|
||||
const response = await client.get<TrainScheduleDetail>(
|
||||
URL_CONSTANTS.TRAIN_SCHEDULING.SCHEDULE_BY_ID(id),
|
||||
pathsFor(freightType === "MIXED" ? undefined : freightType).SCHEDULE_BY_ID(id),
|
||||
);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
cancelSchedule: async (id: string): Promise<TrainScheduleDetail> => {
|
||||
assignBookings: async (
|
||||
scheduleId: string,
|
||||
payload: AssignBookingsPayload,
|
||||
freightType?: FreightType,
|
||||
): Promise<TrainScheduleDetail> => {
|
||||
const useUnified = !freightType || freightType === "MIXED";
|
||||
const response = await client.post<TrainScheduleDetail>(
|
||||
URL_CONSTANTS.TRAIN_SCHEDULING.CANCEL_SCHEDULE(id),
|
||||
useUnified
|
||||
? URL_CONSTANTS.TRAIN_SCHEDULING.ASSIGN_BOOKINGS(scheduleId)
|
||||
: pathsFor(freightType).ASSIGN_BOOKINGS(scheduleId),
|
||||
payload,
|
||||
);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
unassignBooking: async (
|
||||
scheduleId: string,
|
||||
bookingId: string,
|
||||
): Promise<TrainScheduleDetail> => {
|
||||
const response = await client.delete<TrainScheduleDetail>(
|
||||
URL_CONSTANTS.TRAIN_SCHEDULING.UNASSIGN_BOOKING(scheduleId, bookingId),
|
||||
);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
pinWagons: async (
|
||||
scheduleId: string,
|
||||
payload: PinWagonsPayload,
|
||||
): Promise<TrainScheduleDetail> => {
|
||||
const response = await client.post<TrainScheduleDetail>(
|
||||
URL_CONSTANTS.TRAIN_SCHEDULING.PIN_WAGONS(scheduleId),
|
||||
payload,
|
||||
);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
finalizeSchedule: async (scheduleId: string): Promise<TrainScheduleDetail> => {
|
||||
const response = await client.post<TrainScheduleDetail>(
|
||||
URL_CONSTANTS.TRAIN_SCHEDULING.FINALIZE(scheduleId),
|
||||
{},
|
||||
);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
dispatchSchedule: async (scheduleId: string): Promise<TrainScheduleDetail> => {
|
||||
const response = await client.post<TrainScheduleDetail>(
|
||||
URL_CONSTANTS.TRAIN_SCHEDULING.DISPATCH(scheduleId),
|
||||
{},
|
||||
);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
cancelSchedule: async (
|
||||
id: string,
|
||||
freightType: FreightType = "CONTAINER",
|
||||
): Promise<TrainScheduleDetail> => {
|
||||
const response = await client.post<TrainScheduleDetail>(
|
||||
pathsFor(freightType === "MIXED" ? undefined : freightType).CANCEL_SCHEDULE(id),
|
||||
{},
|
||||
);
|
||||
return unwrap(response.data);
|
||||
@@ -77,6 +153,81 @@ export const trainSchedulingService = {
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
previewReschedule: async (
|
||||
scheduleId: string,
|
||||
payload: {
|
||||
incomingBookingIds: string[];
|
||||
trigger: string;
|
||||
reason?: string;
|
||||
newDepartureDate?: string;
|
||||
},
|
||||
) => {
|
||||
const response = await client.post(
|
||||
URL_CONSTANTS.TRAIN_SCHEDULING.RESCHEDULE_PREVIEW(scheduleId),
|
||||
payload,
|
||||
);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
executeReschedule: async (
|
||||
scheduleId: string,
|
||||
payload: {
|
||||
incomingBookingIds: string[];
|
||||
trigger: string;
|
||||
reason?: string;
|
||||
newDepartureDate?: string;
|
||||
finalBookingIds: string[];
|
||||
displacedBookingIds: string[];
|
||||
},
|
||||
) => {
|
||||
const response = await client.post(
|
||||
URL_CONSTANTS.TRAIN_SCHEDULING.RESCHEDULE_EXECUTE(scheduleId),
|
||||
payload,
|
||||
);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
maintenanceReschedule: async (
|
||||
scheduleId: string,
|
||||
payload: {
|
||||
incomingBookingIds: string[];
|
||||
newDepartureDate: string;
|
||||
reason?: string;
|
||||
},
|
||||
) => {
|
||||
const response = await client.post(
|
||||
URL_CONSTANTS.TRAIN_SCHEDULING.MAINTENANCE(scheduleId),
|
||||
{ ...payload, trigger: "TRAIN_MAINTENANCE" },
|
||||
);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
getGlobalRules: async (): Promise<TrainSchedulingGlobalRules> => {
|
||||
const response = await client.get<TrainSchedulingGlobalRules>(
|
||||
URL_CONSTANTS.TRAIN_SCHEDULING.GLOBAL_RULES,
|
||||
);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
updateGlobalRules: async (
|
||||
payload: Partial<
|
||||
Pick<
|
||||
TrainSchedulingGlobalRules,
|
||||
| "maxTrainLengthMeters"
|
||||
| "maxTrainWeightTons"
|
||||
| "maxWagonsPerTrain"
|
||||
| "max20ftContainerWeightTons"
|
||||
| "max20ftPairWeightDiffTons"
|
||||
>
|
||||
>,
|
||||
): Promise<TrainSchedulingGlobalRules> => {
|
||||
const response = await client.patch<TrainSchedulingGlobalRules>(
|
||||
URL_CONSTANTS.TRAIN_SCHEDULING.GLOBAL_RULES,
|
||||
payload,
|
||||
);
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
getStations: async (): Promise<YardOption[]> => {
|
||||
const response = await client.get<BookingReferenceDataResponse>(
|
||||
URL_CONSTANTS.BOOKINGS.REFERENCE_DATA,
|
||||
|
||||
Reference in New Issue
Block a user