fix(overseas): normalize transfer inventory quantities at API boundary

This commit is contained in:
2026-10-04 22:26:36 +08:00
parent 939cc11d7b
commit ea24496b11
7 changed files with 90 additions and 14 deletions
@@ -1,6 +1,7 @@
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
import { normalizeOverseasPage, type OverseasPagePayload } from './lastMileOrders'
import { normalizeWarehouseTransferQuantity } from './warehouseTransferQuantities'
export interface WarehouseTransferQuery {
page: number
@@ -93,14 +94,19 @@ export interface AllocateWarehouseTransferPayload {
allocations: Array<{ inventoryPositionId: string; palletId: string; packageCount: number }>
}
type WarehouseTransferDetailWire = Omit<WarehouseTransferDetailDto, 'packageCount'> & { packageCount: number | string }
function normalizeTransferDetail(value: WarehouseTransferDetailWire): WarehouseTransferDetailDto {
return { ...value, packageCount: normalizeWarehouseTransferQuantity(value.packageCount, '本票转运箱数') }
}
/** The caller must use confirmed source positions, never aggregate inventory rows. */
export async function allocateWarehouseTransfer(customerId: string, transferNo: string, payload: AllocateWarehouseTransferPayload) {
const response = await http.post<ApiEnvelope<WarehouseTransferDetailDto>, ApiEnvelope<WarehouseTransferDetailDto>>(
const response = await http.post<ApiEnvelope<WarehouseTransferDetailWire>, ApiEnvelope<WarehouseTransferDetailWire>>(
`/platform/v1/last-leg/warehouse-transfers/${encodeURIComponent(transferNo)}/allocations`,
payload,
{ params: { customerId } },
)
return unwrapApiResponse(response)
return normalizeTransferDetail(unwrapApiResponse(response))
}
export async function listWarehouseTransfers(customerId: string, query: WarehouseTransferQuery) {
@@ -112,11 +118,11 @@ export async function listWarehouseTransfers(customerId: string, query: Warehous
}
export async function getWarehouseTransfer(customerId: string, transferNo: string) {
const response = await http.get<ApiEnvelope<WarehouseTransferDetailDto>, ApiEnvelope<WarehouseTransferDetailDto>>(
const response = await http.get<ApiEnvelope<WarehouseTransferDetailWire>, ApiEnvelope<WarehouseTransferDetailWire>>(
`/platform/v1/last-leg/warehouse-transfers/${encodeURIComponent(transferNo)}`,
{ params: { customerId } },
)
return unwrapApiResponse(response)
return normalizeTransferDetail(unwrapApiResponse(response))
}
export async function reviewWarehouseTransfer(
@@ -125,10 +131,10 @@ export async function reviewWarehouseTransfer(
decision: 'APPROVE' | 'REJECT',
remark?: string,
) {
const response = await http.post<ApiEnvelope<WarehouseTransferDetailDto>, ApiEnvelope<WarehouseTransferDetailDto>>(
const response = await http.post<ApiEnvelope<WarehouseTransferDetailWire>, ApiEnvelope<WarehouseTransferDetailWire>>(
`/platform/v1/last-leg/warehouse-transfers/${encodeURIComponent(transferNo)}/review`,
{ decision, remark },
{ params: { customerId } },
)
return unwrapApiResponse(response)
return normalizeTransferDetail(unwrapApiResponse(response))
}