mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 21:08:12 +00:00
fix train builder and consolidation
This commit is contained in:
@@ -184,10 +184,12 @@ import {
|
||||
import { trainService, type Train } from "./trains.service";
|
||||
import {
|
||||
trainBuilderService,
|
||||
type AdjustConsistPayload,
|
||||
type AvailableTrain,
|
||||
type BuildTrainPayload,
|
||||
type BuiltTrainListFilters,
|
||||
type BuiltTrainListResponse,
|
||||
type ScheduleConsist,
|
||||
type TrainComposition,
|
||||
} from "./trainBuilder.service";
|
||||
import { trainSchedulingService } from "./trainScheduling.service";
|
||||
@@ -320,6 +322,30 @@ export const api = {
|
||||
({ routeId }) => QUERY_KEYS.TRAIN_SCHEDULING.availableTrains(routeId),
|
||||
),
|
||||
|
||||
scheduleConsist: endpoint<{ scheduleId: string }, ScheduleConsist>(
|
||||
"train-scheduling",
|
||||
"schedule-consist",
|
||||
({ scheduleId }) =>
|
||||
trainBuilderService.scheduleConsist(scheduleId).then((r) => r.data),
|
||||
({ scheduleId }) => [
|
||||
...QUERY_KEYS.TRAIN_SCHEDULING.ROOT,
|
||||
"consist",
|
||||
scheduleId,
|
||||
],
|
||||
),
|
||||
|
||||
adjustConsist: endpoint<
|
||||
{ scheduleId: string; payload: AdjustConsistPayload },
|
||||
ScheduleConsist
|
||||
>(
|
||||
"train-scheduling",
|
||||
"adjust-consist",
|
||||
({ scheduleId, payload }) =>
|
||||
trainBuilderService.adjustConsist(scheduleId, payload).then((r) => r.data),
|
||||
undefined,
|
||||
() => TRAIN_BUILDER_INVALIDATIONS,
|
||||
),
|
||||
|
||||
bookableSchedules: endpoint<
|
||||
{ originYardId?: string | null; destinationYardId?: string | null },
|
||||
BookableSchedule[]
|
||||
|
||||
@@ -153,6 +153,64 @@ const toQuery = (filters: BuiltTrainListFilters = {}) => {
|
||||
return qs ? `?${qs}` : "";
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Schedule consist adjustment (train-bound schedules)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export interface ConsistWagonRef {
|
||||
id: string;
|
||||
wagonNumber: string;
|
||||
sequenceNumber: number | null;
|
||||
wagonType: {
|
||||
id: string;
|
||||
code: string;
|
||||
tareWeightTons: number;
|
||||
capacityTons: number;
|
||||
lengthMeters: number;
|
||||
} | null;
|
||||
}
|
||||
|
||||
export interface ScheduleConsist {
|
||||
schedule: { id: string; reference: string | null; status: string };
|
||||
train: {
|
||||
id: string;
|
||||
code: string;
|
||||
trainName: string | null;
|
||||
currentYardId: string | null;
|
||||
};
|
||||
limits: {
|
||||
maxPullWeightTons: number;
|
||||
overageToleranceTons: number;
|
||||
pullCapTons: number;
|
||||
maxTrainLengthMeters: number;
|
||||
overageToleranceMeters: number;
|
||||
lengthCapMeters: number;
|
||||
};
|
||||
totals: {
|
||||
wagonCount: number;
|
||||
cargoTons: number;
|
||||
consistTareTons: number;
|
||||
grossTons: number;
|
||||
consistLengthMeters: number;
|
||||
};
|
||||
wagons: Array<ConsistWagonRef & { loaded: boolean; removable: boolean }>;
|
||||
addableWagons: ConsistWagonRef[];
|
||||
adjustments: Array<{
|
||||
id: string;
|
||||
action: "ADD" | "REMOVE";
|
||||
wagonId: string;
|
||||
wagonNumber: string;
|
||||
adjustedByUserId: string | null;
|
||||
occurredAt: string;
|
||||
}>;
|
||||
editable: boolean;
|
||||
}
|
||||
|
||||
export interface AdjustConsistPayload {
|
||||
addWagonIds?: string[];
|
||||
removeWagonIds?: string[];
|
||||
}
|
||||
|
||||
export const trainBuilderService = {
|
||||
list: (filters: BuiltTrainListFilters = {}) =>
|
||||
apiClient.get<BuiltTrainListResponse>(`${BASE}${toQuery(filters)}`),
|
||||
@@ -175,4 +233,13 @@ export const trainBuilderService = {
|
||||
apiClient.get<AvailableTrain[]>(`/train-scheduling/available-trains`, {
|
||||
params: { routeId },
|
||||
}),
|
||||
/** Consist snapshot for a train-bound schedule (adjust-consist UI). */
|
||||
scheduleConsist: (scheduleId: string) =>
|
||||
apiClient.get<ScheduleConsist>(`/train-scheduling/schedules/${scheduleId}/consist`),
|
||||
/** Permanently trim/add wagons on the schedule's built train. */
|
||||
adjustConsist: (scheduleId: string, payload: AdjustConsistPayload) =>
|
||||
apiClient.post<ScheduleConsist>(
|
||||
`/train-scheduling/schedules/${scheduleId}/adjust-consist`,
|
||||
payload,
|
||||
),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user