feat(wagons): audited maintenance/availability toggle

This commit is contained in:
Marshal
2026-08-07 12:10:43 +00:00
parent 756325c814
commit 70215a9f37
12 changed files with 419 additions and 31 deletions

View File

@@ -216,6 +216,7 @@ import {
type Wagon,
type WagonListFilters,
type WagonMovementRecord,
type WagonStatusLog,
type WagonTransferRequest,
type CreateTransferRequestPayload,
type BulkFulfillResult,
@@ -1795,15 +1796,23 @@ export const api = {
),
bulkSetStatus: endpoint<
{ wagonIds: string[]; status: Wagon["status"] },
{ wagonIds: string[]; status: Wagon["status"]; note?: string },
{ updated: number }
>(
"wagons",
"bulkSetStatus",
({ wagonIds, status }) =>
wagonService.bulkSetStatus(wagonIds, status).then((r) => r.data),
({ wagonIds, status, note }) =>
wagonService.bulkSetStatus(wagonIds, status, note).then((r) => r.data),
undefined,
() => [["wagons"]],
// The fleet desk lists wagons under the "fleet" key root, not "wagons".
() => [["wagons"], QUERY_KEYS.FLEET.list("wagons")],
),
statusHistory: endpoint<{ id: string }, WagonStatusLog[]>(
"wagons",
"statusHistory",
({ id }) => wagonService.getStatusHistory(id).then((r) => r.data),
({ id }) => ["wagons", "status-history", id],
),
},

View File

@@ -94,6 +94,17 @@ export interface WagonMovementRecord {
wagon?: { id: string; wagonNumber?: string } | null;
}
/** One row of the wagon status audit trail. Returned newest first by the API. */
export interface WagonStatusLog {
id: string;
wagonId: string;
fromStatus: Freight.WagonStatus;
toStatus: Freight.WagonStatus;
changedByUserId: string | null;
note: string | null;
createdAt: string;
}
export const wagonService = {
/** One page ({items, meta}); 10 rows unless `pageSize` says otherwise. */
getAll: (filters: WagonListFilters = {}) =>
@@ -128,9 +139,12 @@ export const wagonService = {
/** 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 }),
/** Set the same status on many wagons in a single call. */
bulkSetStatus: (wagonIds: string[], status: Freight.WagonStatus) =>
apiClient.post<{ updated: number }>('/wagons/bulk-status', { wagonIds, status }),
/** Set the same status on many wagons in a single call (writes audit rows). */
bulkSetStatus: (wagonIds: string[], status: Freight.WagonStatus, note?: string) =>
apiClient.post<{ updated: number }>('/wagons/bulk-status', { wagonIds, status, note }),
/** Status audit trail for one wagon, newest first. */
getStatusHistory: (id: string) =>
apiClient.get<WagonStatusLog[]>(`/wagons/${id}/status-history`),
};
/**