Files
admin-web/src/modules/customers/overseasStorageFee.ts
T
2026-08-27 21:48:15 +08:00

68 lines
2.7 KiB
TypeScript

import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
export type OverseasFeeType = 'STORAGE' | 'RETURN_STORAGE'
export type OverseasBillingUnit = 'CBM' | 'PALLET'
export interface OverseasStorageFeeTier {
id: string
startDay: number
endDay: number | null
unitPrice: number
sortNo: number
feeType: OverseasFeeType
billingUnit: OverseasBillingUnit
}
export interface OverseasStorageFeeConfig {
id: string
customerId: string
customerName: string
currency: string
tiers: OverseasStorageFeeTier[]
version: number
createdAt: string | null
updatedAt: string | null
}
export interface OverseasStorageFeeUpdateRequest {
customerId: string
customerName: string
currency: string
tiers: Array<Pick<OverseasStorageFeeTier, 'feeType' | 'billingUnit' | 'startDay' | 'endDay' | 'unitPrice'>>
version: number
}
const path = (tenantId: string) => `/platform/v1/iam/tenants/${encodeURIComponent(tenantId)}/overseas-storage-fees`
type RawConfig = Omit<OverseasStorageFeeConfig, 'id' | 'customerId' | 'version' | 'tiers'> & {
id: string | number
customerId: string | number
version: string | number
tiers: Array<Omit<OverseasStorageFeeTier, 'id'> & { id: string | number; unitPrice: number | string }>
}
function normalize(data: RawConfig): OverseasStorageFeeConfig {
return {
...data,
id: String(data.id), customerId: String(data.customerId), version: Number(data.version),
tiers: data.tiers.map((tier) => ({ ...tier, id: String(tier.id), endDay: tier.endDay == null ? null : Number(tier.endDay), unitPrice: Number(tier.unitPrice), feeType: tier.feeType as OverseasFeeType, billingUnit: tier.billingUnit as OverseasBillingUnit })),
}
}
export async function getCustomerOverseasStorageFees(tenantId: string) {
const response = await http.get<never, ApiEnvelope<RawConfig>>(path(tenantId))
return normalize(unwrapApiResponse(response))
}
export async function updateCustomerOverseasStorageFees(tenantId: string, request: OverseasStorageFeeUpdateRequest) {
const response = await http.put<never, ApiEnvelope<null>>(path(tenantId), request)
unwrapApiResponse(response)
return getCustomerOverseasStorageFees(tenantId)
}
export async function listOverseasStorageFees(page = 1, size = 20, customerName?: string) {
const response = await http.get<never, ApiEnvelope<{ records: RawConfig[]; total: number; page: number; size: number }>>('/platform/v1/overseas-storage-fees', { params: { page, size, customerName } })
const result = unwrapApiResponse(response)
return { ...result, records: (result.records || []).map(normalize), total: Number(result.total || 0), page: Number(result.page || page), size: Number(result.size || size) }
}