mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 05:18:11 +00:00
feat: implement consolidation approval process for shared-wagon bookings
- Add migration for consolidation approvals table and status enum - Create ConsolidationApprovalService to handle approval logic - Implement repository for managing consolidation approvals - Add entity for consolidation approval with necessary fields - Develop frontend components for displaying and managing consolidation approvals - Create tests for consolidation approval service to ensure correct behavior
This commit is contained in:
@@ -33,6 +33,27 @@ export type InvalidatesMeta = (
|
||||
data: unknown,
|
||||
) => ReadonlyArray<readonly unknown[]>;
|
||||
|
||||
/**
|
||||
* Cache entries a mutation can write DIRECTLY from its own response, skipping
|
||||
* a refetch. Many endpoints already return the fresh entity they just changed
|
||||
* (e.g. every train-builder mutation returns the whole `TrainComposition`), so
|
||||
* re-fetching that same key is a wasted round-trip and a visible flicker.
|
||||
*
|
||||
* Returned pairs are written with `setQueryData` by the app-wide MutationCache
|
||||
* BEFORE the `invalidates` keys are invalidated, and any key seeded here is
|
||||
* skipped by that invalidation pass — the value just written IS the fresh one.
|
||||
*/
|
||||
export type UpdatesFn<TInput, TResponse> = (
|
||||
input: TInput,
|
||||
data: TResponse,
|
||||
) => ReadonlyArray<readonly [readonly unknown[], unknown]>;
|
||||
|
||||
/** Shape stored in `mutation.meta.updates` and consumed by the MutationCache. */
|
||||
export type UpdatesMeta = (
|
||||
variables: unknown,
|
||||
data: unknown,
|
||||
) => ReadonlyArray<readonly [readonly unknown[], unknown]>;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Endpoint interfaces
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -67,6 +88,7 @@ export function endpoint<TInput, TResponse>(
|
||||
execute: (input: TInput) => Promise<TResponse>,
|
||||
queryKeyBuilder?: (input: TInput) => readonly unknown[],
|
||||
invalidates?: InvalidatesFn<TInput, TResponse>,
|
||||
updates?: UpdatesFn<TInput, TResponse>,
|
||||
) {
|
||||
const buildKey = (input?: TInput): readonly unknown[] => {
|
||||
if (queryKeyBuilder && input !== undefined) {
|
||||
@@ -101,16 +123,30 @@ export function endpoint<TInput, TResponse>(
|
||||
const mutationOptions = (
|
||||
config?: Omit<UseMutationOptions<TResponse, Error, TInput>, "mutationFn">,
|
||||
): UseMutationOptions<TResponse, Error, TInput> => {
|
||||
const meta = invalidates
|
||||
? {
|
||||
...config?.meta,
|
||||
invalidates: ((variables, data) =>
|
||||
invalidates(
|
||||
variables as TInput,
|
||||
data as TResponse,
|
||||
)) satisfies InvalidatesMeta,
|
||||
}
|
||||
: config?.meta;
|
||||
const meta =
|
||||
invalidates || updates
|
||||
? {
|
||||
...config?.meta,
|
||||
...(invalidates
|
||||
? {
|
||||
invalidates: ((variables, data) =>
|
||||
invalidates(
|
||||
variables as TInput,
|
||||
data as TResponse,
|
||||
)) satisfies InvalidatesMeta,
|
||||
}
|
||||
: {}),
|
||||
...(updates
|
||||
? {
|
||||
updates: ((variables, data) =>
|
||||
updates(
|
||||
variables as TInput,
|
||||
data as TResponse,
|
||||
)) satisfies UpdatesMeta,
|
||||
}
|
||||
: {}),
|
||||
}
|
||||
: config?.meta;
|
||||
|
||||
return {
|
||||
...config,
|
||||
|
||||
Reference in New Issue
Block a user