优化
This commit is contained in:
@@ -31,6 +31,19 @@ describe('container fee API', () => {
|
||||
expect(listSuppliers).toHaveBeenCalledWith({ status: 'ACTIVE', category: 'TRUCKING', page: 1, size: 200 })
|
||||
})
|
||||
|
||||
it('loads every ACTIVE supplier without a category filter when the fee item category is empty', async () => {
|
||||
vi.mocked(listSuppliers).mockResolvedValue({ records: [
|
||||
{ id: '41', name: '承运商A', status: 'ACTIVE', category: 'TRUCKING' },
|
||||
{ id: '42', name: '停用承运商', status: 'INACTIVE', category: 'TRUCKING' },
|
||||
{ id: '43', name: '报关行', status: 'ACTIVE', category: 'CUSTOMS' },
|
||||
], page: 1, size: 200, total: 3, pages: 1 } as never)
|
||||
await expect(listContainerFeeSupplierOptions(null)).resolves.toEqual([
|
||||
{ id: '41', supplierName: '承运商A', category: 'TRUCKING' },
|
||||
{ id: '43', supplierName: '报关行', category: 'CUSTOMS' },
|
||||
])
|
||||
expect(listSuppliers).toHaveBeenCalledWith({ status: 'ACTIVE', category: undefined, page: 1, size: 200 })
|
||||
})
|
||||
|
||||
it('reads allocation rows from Finance and never calculates them', async () => {
|
||||
const get = vi.spyOn(http, 'get')
|
||||
.mockResolvedValueOnce({ code: '200', data: [{ id: 81, customerId: 11, containerId: 99 }, { id: 82, customerId: 11, containerId: 100 }] })
|
||||
|
||||
@@ -83,7 +83,11 @@ export interface ContainerCostDetail {
|
||||
const id = (value: unknown) => value == null ? '' : String(value)
|
||||
const numberValue = (value: unknown) => Number.isFinite(Number(value)) ? Number(value) : 0
|
||||
const supplierCategories: SupplierCategory[] = ['BOOKING', 'CUSTOMS', 'TRUCKING', 'CERTIFICATE']
|
||||
const supplierCategory = (value: unknown): SupplierCategory | null => supplierCategories.includes(value as SupplierCategory) ? value as SupplierCategory : null
|
||||
function supplierCategory(value: unknown): SupplierCategory | null {
|
||||
if (value == null || value === '') return null
|
||||
if (supplierCategories.includes(value as SupplierCategory)) return value as SupplierCategory
|
||||
throw new TypeError(`Unsupported supplierCategory: ${String(value)}`)
|
||||
}
|
||||
const base = (planId: string) => `/platform/v1/loading-plans/${encodeURIComponent(planId)}/fee-details`
|
||||
const params = (accountId: string) => ({ accountId })
|
||||
|
||||
@@ -134,9 +138,9 @@ export async function listApplicableFeeItems() {
|
||||
return (unwrapApiResponse(response).records || []).map((raw) => ({ id: id(raw.id), name: String(raw.feeTypeName || ''), feeCode: String(raw.feeCode || ''), supplierCategory: supplierCategory(raw.supplierCategory), warehouseReceivable: Boolean(raw.warehouseReceivable), warehousePayable: Boolean(raw.warehousePayable), pickupReceivable: Boolean(raw.pickupReceivable), pickupPayable: Boolean(raw.pickupPayable) }))
|
||||
}
|
||||
|
||||
export async function listContainerFeeSupplierOptions(category: SupplierCategory): Promise<ContainerFeeSupplierOption[]> {
|
||||
const page = await listSuppliers({ status: 'ACTIVE', category, page: 1, size: 200 })
|
||||
return page.records.filter((supplier) => supplier.status === 'ACTIVE' && supplier.category === category).map((supplier) => ({ id: supplier.id, supplierName: supplier.name, category: supplier.category }))
|
||||
export async function listContainerFeeSupplierOptions(category: SupplierCategory | null): Promise<ContainerFeeSupplierOption[]> {
|
||||
const page = await listSuppliers({ status: 'ACTIVE', category: category ?? undefined, page: 1, size: 200 })
|
||||
return page.records.filter((supplier) => supplier.status === 'ACTIVE' && (!category || supplier.category === category)).map((supplier) => ({ id: supplier.id, supplierName: supplier.name, category: supplier.category }))
|
||||
}
|
||||
|
||||
export async function listContainerCostDetails(customerId: string, containerId: string): Promise<ContainerCostDetail[]> {
|
||||
|
||||
Reference in New Issue
Block a user