mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 08:48:11 +00:00
- Introduced new yard distances resource with CRUD operations. - Created migration for yard distances table with necessary constraints. - Implemented service and repository for yard distances handling. - Added controller for API endpoints to manage yard distances. - Updated rule engine configuration to include yard distances. - Enhanced rule engine resource page to support yard distance selection. - Updated contracts and train builder pages to handle new yard distance logic. - Added error handling utility for better error message extraction.
69 lines
2.4 KiB
TypeScript
69 lines
2.4 KiB
TypeScript
import { api as apiClient } from '../auth/http';
|
|
|
|
import { URL_CONSTANTS } from '@/constants/URLS';
|
|
|
|
export type LocomotiveType = 'DIESEL' | 'ELECTRIC';
|
|
export type LocomotiveStatus =
|
|
| 'AVAILABLE'
|
|
| 'UNAVAILABLE'
|
|
| 'IMPORT_READY'
|
|
| 'EXPORT_READY'
|
|
| 'MAINTENANCE'
|
|
| 'ASSIGNED'
|
|
| 'OUT_OF_SERVICE';
|
|
|
|
export interface LocomotiveListFilters {
|
|
status?: LocomotiveStatus;
|
|
currentYardId?: string;
|
|
/** Drop locos already coupled to a built train (train-builder picker). */
|
|
excludeCoupled?: boolean;
|
|
/** With excludeCoupled: keep THIS train's own coupled locos in the list. */
|
|
excludeTrainId?: string;
|
|
}
|
|
|
|
export interface Locomotive {
|
|
id: string;
|
|
code: string;
|
|
name?: string | null;
|
|
locomotiveType: LocomotiveType;
|
|
status: LocomotiveStatus;
|
|
currentYardId: string | null;
|
|
currentYard?: { id: string; label?: string; code?: string } | null;
|
|
maxPullWeightTons: number;
|
|
maxTrainLengthMeters: number;
|
|
/** Tons a train may exceed maxPullWeightTons by before scheduling blocks it. */
|
|
overageToleranceTons?: number | null;
|
|
/** Metres a train may exceed maxTrainLengthMeters by before scheduling blocks it. */
|
|
overageToleranceMeters?: number | null;
|
|
powerKw?: number | null;
|
|
tractionForceKn?: number | null;
|
|
maxSpeedKmh?: number | null;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
export type SaveLocomotivePayload = Omit<
|
|
Locomotive,
|
|
'id' | 'createdAt' | 'updatedAt'
|
|
>;
|
|
|
|
export const locomotivesService = {
|
|
getAll: (filters: LocomotiveListFilters = {}) => {
|
|
const params = new URLSearchParams();
|
|
if (filters.status) params.set('status', filters.status);
|
|
if (filters.currentYardId) params.set('currentYardId', filters.currentYardId);
|
|
if (filters.excludeCoupled) params.set('excludeCoupled', 'true');
|
|
if (filters.excludeTrainId) params.set('excludeTrainId', filters.excludeTrainId);
|
|
const qs = params.toString();
|
|
return apiClient.get<Locomotive[]>(
|
|
`${URL_CONSTANTS.LOCOMOTIVES.BASE}${qs ? `?${qs}` : ''}`,
|
|
);
|
|
},
|
|
getById: (id: string) => apiClient.get<Locomotive>(URL_CONSTANTS.LOCOMOTIVES.BY_ID(id)),
|
|
create: (data: Partial<SaveLocomotivePayload>) =>
|
|
apiClient.post(URL_CONSTANTS.LOCOMOTIVES.BASE, data),
|
|
update: (id: string, data: Partial<SaveLocomotivePayload>) =>
|
|
apiClient.patch(URL_CONSTANTS.LOCOMOTIVES.BY_ID(id), data),
|
|
decommission: (id: string) => apiClient.post(URL_CONSTANTS.LOCOMOTIVES.DECOMMISSION(id), {}),
|
|
};
|