Files
admin-web/src/modules/overseas-master-data/api/dispatchCapacityDemands.ts
T

24 lines
1.8 KiB
TypeScript

import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
export interface DispatchCapacityDemand {
dispatchNo: string; warehouseName: string; route: string | null; plannedDepartureAt: string | null
vehiclePalletSpaces: number | null; scheduledPalletCount: number | null; remainingPalletSpaces: number | null
remainingWeightKg: number | null; remainingVolumeCbm: number | null; capacityKnown: boolean; capacityReason: string | null
}
interface Page { records: DispatchCapacityDemand[]; page: number; size: number; total: number; pages: number }
interface Query { page: number; size: number; origin?: string; destination?: string }
const quantity = (value: unknown): number => {
if (value == null || typeof value === 'string' && value.trim() === '') throw new Error('散板需求数量缺失')
if (typeof value !== 'number' && typeof value !== 'string') throw new Error('散板需求数量无效')
const parsed = Number(value)
if (!Number.isFinite(parsed) || parsed < 0) throw new Error('散板需求数量无效')
return parsed
}
export async function listDispatchCapacityDemands(query: Query): Promise<Page> {
const value = unwrapApiResponse(await http.get<ApiEnvelope<Page>, ApiEnvelope<Page>>('/platform/v1/last-leg/dispatches/capacity-demands', { params: query }))
const nullable = (number: unknown) => number == null ? null : quantity(number)
return { ...value, page: quantity(value.page), size: quantity(value.size), total: quantity(value.total), pages: quantity(value.pages), records: value.records.map(row => ({ ...row,
vehiclePalletSpaces: nullable(row.vehiclePalletSpaces), scheduledPalletCount: nullable(row.scheduledPalletCount), remainingPalletSpaces: nullable(row.remainingPalletSpaces),
remainingWeightKg: nullable(row.remainingWeightKg), remainingVolumeCbm: nullable(row.remainingVolumeCbm),
})) }
}