mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 16:00:56 +00:00
add permanent purge functionality for wagons and routes
- Implemented a method in to permanently delete wagons without history. - Added corresponding permissions for hard delete actions in . - Updated the UI components to include purge actions, ensuring they are only available to users with the appropriate permissions. - Created modals for confirming permanent deletions in and . - Enhanced API services to handle purge requests for locomotives, wagons, and routes. - Added tests for the purge functionality in both and services to ensure proper behavior and error handling.
This commit is contained in:
@@ -1605,6 +1605,15 @@ export const api = {
|
||||
undefined,
|
||||
() => [["routes"]],
|
||||
),
|
||||
|
||||
/** Irreversible purge — refused while any train schedule uses the route. */
|
||||
purge: endpoint<string, void>(
|
||||
"routes",
|
||||
"purge",
|
||||
(id) => routesService.purge(id).then(() => undefined),
|
||||
undefined,
|
||||
() => [["routes"]],
|
||||
),
|
||||
},
|
||||
|
||||
stations: {
|
||||
@@ -2194,6 +2203,15 @@ export const api = {
|
||||
undefined,
|
||||
({ slug }) => [QUERY_KEYS.FLEET.list(slug)],
|
||||
),
|
||||
|
||||
/** Irreversible purge — locomotives and wagons only. */
|
||||
purge: endpoint<{ slug: FleetResourceSlug; id: string }, unknown>(
|
||||
"fleet",
|
||||
"purge",
|
||||
({ slug, id }) => fleetService.purge(slug, id),
|
||||
undefined,
|
||||
({ slug }) => [QUERY_KEYS.FLEET.list(slug)],
|
||||
),
|
||||
},
|
||||
|
||||
truckTypes: {
|
||||
|
||||
@@ -77,6 +77,21 @@ const removeHandlers: Record<FleetResourceSlug, (id: string) => Promise<unknown>
|
||||
drivers: (id) => driversService.delete(id),
|
||||
};
|
||||
|
||||
/**
|
||||
* Permanent purge, only for the two slugs that expose it. Everything else stays
|
||||
* soft-delete/decommission only, so there is deliberately no entry here.
|
||||
*/
|
||||
const purgeHandlers: Partial<
|
||||
Record<FleetResourceSlug, (id: string) => Promise<unknown>>
|
||||
> = {
|
||||
locomotives: (id) => locomotivesService.purge(id),
|
||||
wagons: (id) => wagonService.purge(id),
|
||||
};
|
||||
|
||||
/** True when the slug supports an irreversible purge. */
|
||||
export const isFleetPurgeable = (slug: FleetResourceSlug) =>
|
||||
slug in purgeHandlers;
|
||||
|
||||
export const fleetService = {
|
||||
list: (slug: FleetResourceSlug, filters?: FleetListFilters) => listHandlers[slug](filters),
|
||||
/** Only for slugs in `pagedHandlers` — guard with `isFleetServerPaginated`. */
|
||||
@@ -89,4 +104,11 @@ export const fleetService = {
|
||||
update: (slug: FleetResourceSlug, id: string, data: Record<string, unknown>) =>
|
||||
updateHandlers[slug](id, data),
|
||||
remove: (slug: FleetResourceSlug, id: string) => removeHandlers[slug](id),
|
||||
purge: (slug: FleetResourceSlug, id: string) => {
|
||||
const handler = purgeHandlers[slug];
|
||||
if (!handler) {
|
||||
throw new Error(`Fleet resource "${slug}" cannot be permanently deleted`);
|
||||
}
|
||||
return handler(id);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -85,4 +85,7 @@ export const locomotivesService = {
|
||||
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), {}),
|
||||
/** Irreversible purge — the API refuses it while any train references the loco. */
|
||||
purge: (id: string) =>
|
||||
apiClient.delete(`${URL_CONSTANTS.LOCOMOTIVES.BY_ID(id)}/permanent`),
|
||||
};
|
||||
|
||||
@@ -101,6 +101,9 @@ export const routesService = {
|
||||
update: (id: string, data: Partial<SaveRoutePayload>) =>
|
||||
apiClient.patch(URL_CONSTANTS.ROUTES.BY_ID(id), data),
|
||||
deactivate: (id: string) => apiClient.delete(URL_CONSTANTS.ROUTES.BY_ID(id)),
|
||||
/** Irreversible purge — the API refuses it while any train schedule uses the route. */
|
||||
purge: (id: string) =>
|
||||
apiClient.delete(`${URL_CONSTANTS.ROUTES.BY_ID(id)}/permanent`),
|
||||
/** All active yards (page-walked — the yards list API caps pageSize at 100). */
|
||||
getYards: async (): Promise<YardRef[]> => {
|
||||
const rows = await ruleEngineService.listAll("yards", { isActive: true });
|
||||
|
||||
@@ -123,6 +123,8 @@ export const wagonService = {
|
||||
create: (data: Partial<Wagon>) => apiClient.post('/wagons', data),
|
||||
update: (id: string, data: Partial<Wagon>) => apiClient.patch(`/wagons/${id}`, data),
|
||||
delete: (id: string) => apiClient.delete(`/wagons/${id}`),
|
||||
/** Irreversible purge — the API refuses it when the wagon has any history. */
|
||||
purge: (id: string) => apiClient.delete(`/wagons/${id}/permanent`),
|
||||
/** Relocate many wagons to one yard in a single call (writes movement ledger). */
|
||||
bulkTransfer: (wagonIds: string[], toYardId: string) =>
|
||||
apiClient.post<{ moved: number }>('/wagons/bulk-transfer', { wagonIds, toYardId }),
|
||||
|
||||
Reference in New Issue
Block a user