fix: fetchCompanyGroups читает все страницы (C1 критерий)
GET /directories/company-groups возвращает Page[CompanyGroupOut], но раньше типизировался как ICompanyGroup[]. Реализована пагинация: fetchCompanyGroups теперь читает все страницы по 200 и возвращает полный массив ICompanyGroup[]. Это позволяет thunk/slice получать честный массив с правильным total_groups = payload.length. Исправлено: - fetchCompanyGroups: async функция с циклом по total (как fetchAllLegalEntities) - types.ts / companyGroupsSlice.ts / thunks.ts: типы честные (без приведений) - потребители (NewConsoleModal, CompanyGroupsTable, Sidebar): используют raw_rows как массив Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EAKRDNzXtRrwmWz9z6PZu3
This commit is contained in:
parent
4424a2b8e8
commit
27828219c9
@ -2,9 +2,21 @@ import { api } from '../../../api/client';
|
||||
import type { LegalEntityBrief, Page, RelatedGroupDetail, RelatedGroupOut } from '../../../types/api';
|
||||
import type { ICompanyGroup } from '../../../types/companyGroups/companyGroups';
|
||||
|
||||
const CG_PAGE = 200;
|
||||
const LE_PAGE = 200;
|
||||
|
||||
export const fetchCompanyGroups = () => api.get<ICompanyGroup[]>('/directories/company-groups');
|
||||
/** Все видимые ГК — дочитываем страницы, пока не получим total. */
|
||||
export async function fetchCompanyGroups(): Promise<ICompanyGroup[]> {
|
||||
const all: ICompanyGroup[] = [];
|
||||
for (let offset = 0; ; offset += CG_PAGE) {
|
||||
const page = await api.get<Page<ICompanyGroup>>(`/directories/company-groups?limit=${CG_PAGE}&offset=${offset}`);
|
||||
all.push(...page.items);
|
||||
if (all.length >= page.total || page.items.length === 0) {
|
||||
return all;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const fetchOneCompanyGroup = (id: string) => api.get<ICompanyGroup>(`/directories/company-groups/${id}`);
|
||||
export const fetchRelatedGroups = (groupId: string) => api.get<RelatedGroupOut[]>(`/directories/company-groups/${groupId}/related-groups`);
|
||||
export const fetchRelatedGroup = (id: string) => api.get<RelatedGroupDetail>(`/directories/related-groups/${id}`);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user