This commit is contained in:
2026-08-06 15:32:07 +08:00
parent e33d620d87
commit 9aa79bef6d
8 changed files with 101 additions and 22 deletions
@@ -0,0 +1,28 @@
export type WarehouseType = 'DOMESTIC' | 'FBA' | 'OVERSEAS'
export interface WarehousePage<T> {
records: T[]
pages: number | string
}
export interface WarehousePageQuery {
warehouseType: WarehouseType
page: number
size: number
}
export async function loadAllWarehouseRecords<T>(
warehouseType: WarehouseType,
fetchPage: (query: WarehousePageQuery) => Promise<WarehousePage<T>>,
) {
const records: T[] = []
let page = 1
let pages = 1
do {
const response = await fetchPage({ warehouseType, page, size: 200 })
records.push(...response.records)
pages = Number(response.pages) || page
page += 1
} while (page <= pages)
return records
}