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:
Marshal
2026-08-04 14:07:16 +00:00
parent 8cf49aa1cc
commit 5d68a3f7b7
22 changed files with 806 additions and 20 deletions

View File

@@ -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);
},
};