mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 05:18:11 +00:00
Merge pull request #1337 from Tria-plc/freight_feature/usermanagement
Freight feature/usermanagement
This commit is contained in:
@@ -284,6 +284,32 @@ const TRAIN_BUILDER_INVALIDATIONS: ReadonlyArray<readonly unknown[]> = [
|
||||
QUERY_KEYS.FLEET.ROOT,
|
||||
];
|
||||
|
||||
/**
|
||||
* Coupling/uncoupling wagons moves wagons between the available pool and one
|
||||
* train — it does not touch locomotives, so those roots stay valid. Trimming
|
||||
* the set keeps a drag-reorder from refetching the whole fleet.
|
||||
*/
|
||||
const TRAIN_BUILDER_WAGON_INVALIDATIONS: ReadonlyArray<readonly unknown[]> = [
|
||||
QUERY_KEYS.TRAIN_BUILDER.ROOT,
|
||||
QUERY_KEYS.TRAIN_SCHEDULING.ROOT,
|
||||
["wagons"],
|
||||
];
|
||||
|
||||
/**
|
||||
* Every train-builder mutation responds with the train's full, fresh
|
||||
* composition — write it straight into the detail cache so the workspace
|
||||
* repaints from the response instead of refetching what it was just handed.
|
||||
*/
|
||||
const seedComposition = (
|
||||
input: { id: string } | string,
|
||||
data: TrainComposition,
|
||||
): ReadonlyArray<readonly [readonly unknown[], unknown]> => [
|
||||
[
|
||||
QUERY_KEYS.TRAIN_BUILDER.composition(typeof input === "string" ? input : input.id),
|
||||
data,
|
||||
],
|
||||
];
|
||||
|
||||
export const api = {
|
||||
trainScheduling: {
|
||||
// ── Queries ────────────────────────────────────────────────────────────
|
||||
@@ -2070,6 +2096,7 @@ export const api = {
|
||||
trainBuilderService.setLocomotives(id, locomotiveIds).then((r) => r.data),
|
||||
undefined,
|
||||
() => TRAIN_BUILDER_INVALIDATIONS,
|
||||
seedComposition,
|
||||
),
|
||||
|
||||
setYard: endpoint<{ id: string; currentYardId: string }, TrainComposition>(
|
||||
@@ -2079,6 +2106,7 @@ export const api = {
|
||||
trainBuilderService.setYard(id, currentYardId).then((r) => r.data),
|
||||
undefined,
|
||||
() => TRAIN_BUILDER_INVALIDATIONS,
|
||||
seedComposition,
|
||||
),
|
||||
|
||||
updateDetails: endpoint<
|
||||
@@ -2091,6 +2119,7 @@ export const api = {
|
||||
trainBuilderService.updateDetails(id, payload).then((r) => r.data),
|
||||
undefined,
|
||||
() => TRAIN_BUILDER_INVALIDATIONS,
|
||||
seedComposition,
|
||||
),
|
||||
|
||||
assignWagons: endpoint<{ id: string; wagonIds: string[] }, TrainComposition>(
|
||||
@@ -2099,7 +2128,8 @@ export const api = {
|
||||
({ id, wagonIds }) =>
|
||||
trainBuilderService.assignWagons(id, wagonIds).then((r) => r.data),
|
||||
undefined,
|
||||
() => TRAIN_BUILDER_INVALIDATIONS,
|
||||
() => TRAIN_BUILDER_WAGON_INVALIDATIONS,
|
||||
seedComposition,
|
||||
),
|
||||
|
||||
removeWagon: endpoint<{ id: string; wagonId: string }, TrainComposition>(
|
||||
@@ -2108,7 +2138,8 @@ export const api = {
|
||||
({ id, wagonId }) =>
|
||||
trainBuilderService.removeWagon(id, wagonId).then((r) => r.data),
|
||||
undefined,
|
||||
() => TRAIN_BUILDER_INVALIDATIONS,
|
||||
() => TRAIN_BUILDER_WAGON_INVALIDATIONS,
|
||||
seedComposition,
|
||||
),
|
||||
|
||||
sendWagonToMaintenance: endpoint<
|
||||
@@ -2120,7 +2151,8 @@ export const api = {
|
||||
({ id, wagonId, note }) =>
|
||||
trainBuilderService.sendWagonToMaintenance(id, wagonId, note).then((r) => r.data),
|
||||
undefined,
|
||||
() => TRAIN_BUILDER_INVALIDATIONS,
|
||||
() => TRAIN_BUILDER_WAGON_INVALIDATIONS,
|
||||
seedComposition,
|
||||
),
|
||||
|
||||
reorderWagons: endpoint<{ id: string; wagonIds: string[] }, TrainComposition>(
|
||||
@@ -2129,7 +2161,8 @@ export const api = {
|
||||
({ id, wagonIds }) =>
|
||||
trainBuilderService.reorderWagons(id, wagonIds).then((r) => r.data),
|
||||
undefined,
|
||||
() => TRAIN_BUILDER_INVALIDATIONS,
|
||||
() => TRAIN_BUILDER_WAGON_INVALIDATIONS,
|
||||
seedComposition,
|
||||
),
|
||||
|
||||
deactivate: endpoint<string, TrainComposition>(
|
||||
@@ -2138,6 +2171,7 @@ export const api = {
|
||||
(id) => trainBuilderService.deactivate(id).then((r) => r.data),
|
||||
undefined,
|
||||
() => TRAIN_BUILDER_INVALIDATIONS,
|
||||
seedComposition,
|
||||
),
|
||||
|
||||
activate: endpoint<string, TrainComposition>(
|
||||
@@ -2146,6 +2180,7 @@ export const api = {
|
||||
(id) => trainBuilderService.activate(id).then((r) => r.data),
|
||||
undefined,
|
||||
() => TRAIN_BUILDER_INVALIDATIONS,
|
||||
seedComposition,
|
||||
),
|
||||
|
||||
disband: endpoint<string, void>(
|
||||
|
||||
@@ -6,6 +6,35 @@ import type { Freight } from "@edr/types";
|
||||
|
||||
const B = URL_CONSTANTS.BOOKINGS;
|
||||
|
||||
/**
|
||||
* One shared-wagon approval. Covers BOTH bookings on the wagon — the pair is
|
||||
* decided as a unit, never one side at a time.
|
||||
*/
|
||||
export interface ConsolidationApprovalRow {
|
||||
id: string;
|
||||
bookingId: string;
|
||||
partnerBookingId: string;
|
||||
status: "PENDING" | "APPROVED" | "REJECTED";
|
||||
requestedBy?: string | null;
|
||||
requestedAt: string;
|
||||
decidedBy?: string | null;
|
||||
decidedAt?: string | null;
|
||||
decisionNote?: string | null;
|
||||
scheduledDate?: string | null;
|
||||
bookingReference?: string | null;
|
||||
partnerBookingReference?: string | null;
|
||||
booking?: {
|
||||
id: string;
|
||||
reference?: string;
|
||||
company?: { name?: string } | null;
|
||||
} | null;
|
||||
partnerBooking?: {
|
||||
id: string;
|
||||
reference?: string;
|
||||
company?: { name?: string } | null;
|
||||
} | null;
|
||||
}
|
||||
|
||||
export interface BookingListFilter {
|
||||
status?: string;
|
||||
/** Comma-separated statuses for grouped tabs */
|
||||
@@ -327,6 +356,60 @@ export const bookingsService = {
|
||||
cancel: (id: string, reason: string) =>
|
||||
postBooking<BookingDetail>(B.CANCEL(id), { reason }),
|
||||
|
||||
// ── Shared-wagon approval gate ──────────────────────────────────────────
|
||||
|
||||
/** Pairings awaiting a decision, oldest first. */
|
||||
consolidationApprovalQueue: async (): Promise<ConsolidationApprovalRow[]> => {
|
||||
const response = await client.get(B.CONSOLIDATION_APPROVAL_QUEUE);
|
||||
return (unwrap(response.data) ?? []) as ConsolidationApprovalRow[];
|
||||
},
|
||||
|
||||
/** Decision history for one booking's shared wagon — who, when, and why. */
|
||||
consolidationApprovalHistory: async (
|
||||
bookingId: string,
|
||||
): Promise<ConsolidationApprovalRow[]> => {
|
||||
const response = await client.get(
|
||||
B.CONSOLIDATION_APPROVAL_HISTORY(bookingId),
|
||||
);
|
||||
return (unwrap(response.data) ?? []) as ConsolidationApprovalRow[];
|
||||
},
|
||||
|
||||
/** Approve: both bookings leave the gate and continue to Operations. */
|
||||
approveConsolidation: async (approvalId: string, note?: string) => {
|
||||
const response = await client.post(B.CONSOLIDATION_APPROVE(approvalId), {
|
||||
note,
|
||||
});
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
/** Reject: both bookings go back to GL for changes with the reason. */
|
||||
rejectConsolidation: async (approvalId: string, reason: string) => {
|
||||
const response = await client.post(B.CONSOLIDATION_REJECT(approvalId), {
|
||||
reason,
|
||||
});
|
||||
return unwrap(response.data);
|
||||
},
|
||||
|
||||
/**
|
||||
* Apply one staff decision to BOTH halves of a consolidated pair. The two
|
||||
* bookings share a wagon, so they advance or cancel together — all-or-nothing
|
||||
* on the server. Each half keeps its own invoice and payment.
|
||||
*/
|
||||
pairedDecision: async (
|
||||
id: string,
|
||||
decision: "accept" | "cancel" | "operationAccept" | "requestChanges",
|
||||
options: { reason?: string; note?: string; validityDays?: number } = {},
|
||||
): Promise<{ booking: BookingDetail; partner: BookingDetail }> => {
|
||||
const response = await client.post(B.PAIRED_DECISION(id), {
|
||||
decision,
|
||||
...options,
|
||||
});
|
||||
return unwrap(response.data) as {
|
||||
booking: BookingDetail;
|
||||
partner: BookingDetail;
|
||||
};
|
||||
},
|
||||
|
||||
create: async (payload: Record<string, unknown>): Promise<BookingDetail> => {
|
||||
const response = await client.post<{ booking: BookingDetail } | BookingDetail>(
|
||||
B.BASE,
|
||||
|
||||
@@ -73,6 +73,32 @@ export interface ShipmentValidation {
|
||||
totalAmount?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* A booking GL may pick as the shared-wagon partner of an odd-20ft customs
|
||||
* booking. `hasCargo` is false for a bare instance whose containers GL still
|
||||
* enters on the split completion form.
|
||||
*/
|
||||
export interface ConsolidationCandidate {
|
||||
id: string;
|
||||
reference: string;
|
||||
contractId: string | null;
|
||||
companyName: string | null;
|
||||
status: string;
|
||||
tradeDirection: string | null;
|
||||
originYardId: string | null;
|
||||
destinationYardId: string | null;
|
||||
scheduledDate: string | null;
|
||||
ft20Quantity: number;
|
||||
hasCargo: boolean;
|
||||
}
|
||||
|
||||
/** Both halves of a shared-wagon completion, each with its own full payload. */
|
||||
export interface CompleteConsolidatedPairPayload {
|
||||
partnerBookingId: string;
|
||||
booking: Freight.CreateBookingUnderContractDto;
|
||||
partner: Freight.CreateBookingUnderContractDto;
|
||||
}
|
||||
|
||||
export interface ContractListSummaryMetrics {
|
||||
inQueue: number;
|
||||
needsAction: number;
|
||||
@@ -677,6 +703,46 @@ export const contractsService = {
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Bookings GL may link to an odd-20ft customs booking as its shared-wagon
|
||||
* partner (same route and direction, customs, odd 20ft, not already paired).
|
||||
*/
|
||||
listConsolidationCandidates: async (
|
||||
id: string,
|
||||
bookingId: string,
|
||||
): Promise<ConsolidationCandidate[]> => {
|
||||
const response = await client.get(
|
||||
C.CONSOLIDATION_CANDIDATES(id, bookingId),
|
||||
);
|
||||
return (unwrap(response.data) ?? []) as ConsolidationCandidate[];
|
||||
},
|
||||
|
||||
/**
|
||||
* Complete an odd-20ft booking together with the partner booking sharing its
|
||||
* wagon. All-or-nothing on the server: either both bookings complete and are
|
||||
* linked, or neither does. Each booking keeps its own price and its own
|
||||
* invoice — only the wagon is shared.
|
||||
*/
|
||||
completeConsolidatedPair: async (
|
||||
id: string,
|
||||
bookingId: string,
|
||||
payload: CompleteConsolidatedPairPayload,
|
||||
): Promise<{
|
||||
booking: { id: string; reference: string };
|
||||
partner: { id: string; reference: string };
|
||||
warnings?: string[];
|
||||
}> => {
|
||||
const response = await client.post(
|
||||
C.BOOKINGS_COMPLETE_CONSOLIDATED(id, bookingId),
|
||||
payload,
|
||||
);
|
||||
return unwrap(response.data) as {
|
||||
booking: { id: string; reference: string };
|
||||
partner: { id: string; reference: string };
|
||||
warnings?: string[];
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Pre-create validation + authoritative price preview: the same
|
||||
* BookingPricingService pass that prices the booking on create (rail +
|
||||
|
||||
Reference in New Issue
Block a user