feat(admin): confirm container departure from detail
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
|
||||
import type { OutboundDispatchDetail, OutboundDispatchQuery, OutboundDispatchResource, OutboundGateResult } from '../types'
|
||||
import type {
|
||||
ContainerOutboundActionRequest,
|
||||
ContainerOutboundAggregate,
|
||||
ContainerOutboundDispatchDetail,
|
||||
ContainerOutboundGateResult,
|
||||
ContainerOutboundInboundBinding,
|
||||
ContainerOutboundInboundGate,
|
||||
OutboundDispatchDetail,
|
||||
OutboundDispatchQuery,
|
||||
OutboundDispatchResource,
|
||||
OutboundGateResult,
|
||||
} from '../types'
|
||||
const basePath = '/platform/v1/first-leg/outbound-dispatches'; const keys = ['orderId', 'inboundId', 'containerBookingId', 'customerId'] as const
|
||||
function item(raw: OutboundDispatchResource): OutboundDispatchResource { const value = { ...raw } as OutboundDispatchResource & Record<string, unknown>; for (const key of keys) if (value[key] != null) value[key] = String(value[key]); value.version = Number(value.version ?? 0); return value }
|
||||
function idem() { return `outbound-dispatch-${Date.now()}-${Math.random().toString(36).slice(2)}` }
|
||||
@@ -7,3 +18,70 @@ export async function listOutboundDispatches(query: OutboundDispatchQuery) { con
|
||||
export async function getOutboundDispatchDetail(query: OutboundDispatchQuery) { const response = await http.get<ApiEnvelope<OutboundDispatchDetail>, ApiEnvelope<OutboundDispatchDetail>>(`${basePath}/detail`, { params: query }); const data = unwrapApiResponse(response); return { ...data, aggregate: item(data.aggregate) } }
|
||||
export async function checkOutboundGate(query: OutboundDispatchQuery) { const response = await http.get<ApiEnvelope<OutboundGateResult>, ApiEnvelope<OutboundGateResult>>(`${basePath}/check-gate`, { params: query }); return unwrapApiResponse(response) }
|
||||
export async function changeOutboundDispatch(action: 'confirm-dispatch' | 'reverse-dispatch', request: { inboundId: string; containerBookingId?: string | null; expectedVersion: number; remark?: string }) { const response = await http.post<ApiEnvelope<OutboundDispatchDetail>, ApiEnvelope<OutboundDispatchDetail>>(`${basePath}/${action}`, request, { headers: { 'Idempotency-Key': idem() } }); const data = unwrapApiResponse(response); return { ...data, aggregate: item(data.aggregate) } }
|
||||
|
||||
function optionalId(value: unknown): string | null {
|
||||
return value == null ? null : String(value)
|
||||
}
|
||||
|
||||
function inboundBinding(raw: ContainerOutboundInboundBinding): ContainerOutboundInboundBinding {
|
||||
return {
|
||||
...raw,
|
||||
orderId: String(raw.orderId),
|
||||
inboundId: String(raw.inboundId),
|
||||
tenantId: String(raw.tenantId),
|
||||
customerId: optionalId(raw.customerId),
|
||||
pickTaskId: optionalId(raw.pickTaskId),
|
||||
}
|
||||
}
|
||||
|
||||
function inboundGate(raw: ContainerOutboundInboundGate): ContainerOutboundInboundGate {
|
||||
return { ...raw, inboundId: String(raw.inboundId), gate: { ...raw.gate, items: raw.gate?.items || [] } }
|
||||
}
|
||||
|
||||
function containerGate(raw: ContainerOutboundGateResult): ContainerOutboundGateResult {
|
||||
return { ...raw, inbounds: (raw.inbounds || []).map(inboundGate) }
|
||||
}
|
||||
|
||||
function containerAggregate(raw: ContainerOutboundAggregate): ContainerOutboundAggregate {
|
||||
return {
|
||||
...raw,
|
||||
containerBookingId: String(raw.containerBookingId),
|
||||
loadingPlanId: String(raw.loadingPlanId),
|
||||
oceanBookingId: optionalId(raw.oceanBookingId),
|
||||
truckAppointmentId: optionalId(raw.truckAppointmentId),
|
||||
version: Number(raw.version ?? 0),
|
||||
inbounds: (raw.inbounds || []).map(inboundBinding),
|
||||
gate: containerGate(raw.gate),
|
||||
}
|
||||
}
|
||||
|
||||
function containerDetail(raw: ContainerOutboundDispatchDetail): ContainerOutboundDispatchDetail {
|
||||
return {
|
||||
...raw,
|
||||
aggregate: containerAggregate(raw.aggregate),
|
||||
timeline: (raw.timeline || []).map((entry) => ({ ...entry, operatorId: optionalId(entry.operatorId) })),
|
||||
}
|
||||
}
|
||||
|
||||
export async function getContainerOutboundDispatch(containerBookingId: string) {
|
||||
const response = await http.get<ApiEnvelope<ContainerOutboundDispatchDetail>, ApiEnvelope<ContainerOutboundDispatchDetail>>(
|
||||
`${basePath}/${encodeURIComponent(containerBookingId)}`,
|
||||
)
|
||||
return containerDetail(unwrapApiResponse(response))
|
||||
}
|
||||
|
||||
export async function checkContainerOutboundGate(containerBookingId: string) {
|
||||
const response = await http.get<ApiEnvelope<ContainerOutboundGateResult>, ApiEnvelope<ContainerOutboundGateResult>>(
|
||||
`${basePath}/${encodeURIComponent(containerBookingId)}/gate`,
|
||||
)
|
||||
return containerGate(unwrapApiResponse(response))
|
||||
}
|
||||
|
||||
export async function confirmContainerOutboundDispatch(containerBookingId: string, request: ContainerOutboundActionRequest) {
|
||||
const response = await http.post<ApiEnvelope<ContainerOutboundDispatchDetail>, ApiEnvelope<ContainerOutboundDispatchDetail>>(
|
||||
`${basePath}/${encodeURIComponent(containerBookingId)}/confirm`,
|
||||
request,
|
||||
{ headers: { 'Idempotency-Key': idem() } },
|
||||
)
|
||||
return containerDetail(unwrapApiResponse(response))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user