49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
import type { PlatformTenantResource } from '@/modules/iam'
|
|
import type { InboundListQuery } from './core/types'
|
|
|
|
export type InboundTaskMode = 'measurement' | 'review'
|
|
|
|
export interface ActiveCustomerPage {
|
|
records: PlatformTenantResource[]
|
|
pages: number
|
|
}
|
|
|
|
export interface ActiveCustomerQuery {
|
|
page: number
|
|
size: number
|
|
status: 'ACTIVE'
|
|
}
|
|
|
|
export async function loadAllActiveCustomers(
|
|
fetchPage: (query: ActiveCustomerQuery) => Promise<ActiveCustomerPage>,
|
|
) {
|
|
const records: PlatformTenantResource[] = []
|
|
let page = 1
|
|
let pages = 1
|
|
do {
|
|
const response = await fetchPage({ page, size: 200, status: 'ACTIVE' })
|
|
records.push(...response.records)
|
|
pages = Math.max(1, response.pages)
|
|
page += 1
|
|
} while (page <= pages)
|
|
return records
|
|
}
|
|
|
|
export function buildInboundTaskQuery(
|
|
mode: InboundTaskMode,
|
|
query: Omit<InboundListQuery, 'tab' | 'processStatus' | 'measureReviewStatus'>,
|
|
): InboundListQuery {
|
|
if (mode === 'review') {
|
|
return {
|
|
...query,
|
|
tab: 'WAIT_REVIEW',
|
|
measureReviewStatus: 'PENDING',
|
|
}
|
|
}
|
|
|
|
return {
|
|
...query,
|
|
tab: 'WAIT_MEASURE',
|
|
}
|
|
}
|