优化
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
createPlatformWarehouse,
|
||||
getPlatformWarehouse,
|
||||
importWarehouses,
|
||||
listAllPlatformWarehouses,
|
||||
listPlatformWarehouses,
|
||||
updatePlatformWarehouse,
|
||||
type SavePlatformWarehouseRequest,
|
||||
@@ -109,6 +110,31 @@ describe('platform warehouse API', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('loads every warehouse page for complete resource selectors', async () => {
|
||||
const firstRecord = { id: '1', warehouseCode: 'ABE2', warehouseType: 'FBA' }
|
||||
const domesticRecord = { id: '201', warehouseCode: 'CN-YIWU-01', warehouseType: 'DOMESTIC' }
|
||||
vi.mocked(http.get)
|
||||
.mockResolvedValueOnce({
|
||||
code: '200',
|
||||
data: { records: [firstRecord], page: 1, size: 200, total: 201, pages: 2 },
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
code: '200',
|
||||
data: { records: [domesticRecord], page: 2, size: 200, total: 201, pages: 2 },
|
||||
})
|
||||
|
||||
await expect(listAllPlatformWarehouses()).resolves.toEqual([
|
||||
{ ...firstRecord, primaryAddress: null, addressSummary: null },
|
||||
{ ...domesticRecord, primaryAddress: null, addressSummary: null },
|
||||
])
|
||||
expect(http.get).toHaveBeenNthCalledWith(1, '/platform/v1/warehouse-admin', {
|
||||
params: { page: 1, size: 200 },
|
||||
})
|
||||
expect(http.get).toHaveBeenNthCalledWith(2, '/platform/v1/warehouse-admin', {
|
||||
params: { page: 2, size: 200 },
|
||||
})
|
||||
})
|
||||
|
||||
it('uses the implemented create, update, and status routes', async () => {
|
||||
vi.mocked(http.post).mockResolvedValue({ code: '200', message: 'success', data: '19001' })
|
||||
vi.mocked(http.put).mockResolvedValue({ code: '200', message: 'success', data: null })
|
||||
|
||||
@@ -221,6 +221,21 @@ export async function listPlatformWarehouses(pageOrQuery: number | PlatformWareh
|
||||
}
|
||||
}
|
||||
|
||||
export async function listAllPlatformWarehouses(
|
||||
filters: Omit<PlatformWarehouseQuery, 'page' | 'size'> = {},
|
||||
): Promise<PlatformWarehouseSummaryResource[]> {
|
||||
const size = 200
|
||||
const firstPage = await listPlatformWarehouses({ ...filters, page: 1, size })
|
||||
if (firstPage.pages <= 1) return firstPage.records
|
||||
|
||||
const remainingPages = await Promise.all(
|
||||
Array.from({ length: firstPage.pages - 1 }, (_, index) => (
|
||||
listPlatformWarehouses({ ...filters, page: index + 2, size })
|
||||
)),
|
||||
)
|
||||
return [firstPage, ...remainingPages].flatMap((page) => page.records)
|
||||
}
|
||||
|
||||
export async function getPlatformWarehouse(warehouseId: number | string) {
|
||||
const response = await http.get<ApiEnvelope<PlatformWarehouseDetailResource>, ApiEnvelope<PlatformWarehouseDetailResource>>(
|
||||
`${basePath}/${warehouseId}`,
|
||||
|
||||
Reference in New Issue
Block a user