mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-01 05:03:13 +00:00
29 lines
1 KiB
TypeScript
29 lines
1 KiB
TypeScript
import { workOrdersApi } from "@/domain/work-orders/api/work-orders-api";
|
|
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
|
import { toUnassignedQueueQueryParams } from "@/domain/work-orders/utils/board-query-params";
|
|
|
|
const UNASSIGNED_QUEUE_MAX_PAGES = 50;
|
|
|
|
/** Exhausts GET /board/search pages for the global Unassigned pin (SH-165). */
|
|
export async function fetchUnassignedBoardRows(): Promise<WorkOrderTableRow[]> {
|
|
const rows: WorkOrderTableRow[] = [];
|
|
let page = 0;
|
|
let totalCount = Number.POSITIVE_INFINITY;
|
|
|
|
while (rows.length < totalCount) {
|
|
if (page >= UNASSIGNED_QUEUE_MAX_PAGES) {
|
|
throw new Error(
|
|
"Unable to load the unassigned queue: search result set exceeded the safety page limit.",
|
|
);
|
|
}
|
|
const result = await workOrdersApi.searchBoard(toUnassignedQueueQueryParams(page));
|
|
rows.push(...result.items);
|
|
totalCount = result.totalCount;
|
|
if (result.items.length === 0) {
|
|
break;
|
|
}
|
|
page += 1;
|
|
}
|
|
|
|
return rows;
|
|
}
|