MCPcopy
hub / github.com/ModelEngine-Group/nexent / listGroups

Function listGroups

frontend/services/groupService.ts:57–93  ·  view source on GitHub ↗
(
  tenantId: string,
  page?: number,
  pageSize?: number
)

Source from the content-addressed store, hash-verified

55 * If page and pageSize are not provided, returns all groups
56 */
57export async function listGroups(
58 tenantId: string,
59 page?: number,
60 pageSize?: number
61): Promise<{ groups: Group[]; total: number; totalPages?: number }> {
62 try {
63 const requestBody: any = {
64 tenant_id: tenantId,
65 sort_by: "created_at",
66 sort_order: "desc",
67 };
68
69 // Only include pagination parameters if both are provided
70 if (page !== undefined && pageSize !== undefined) {
71 requestBody.page = page;
72 requestBody.page_size = pageSize;
73 }
74
75 // Use backend's /groups/list endpoint with tenant_id in request body
76 const response = await fetchWithAuth(API_ENDPOINTS.groups.list, {
77 method: "POST",
78 body: JSON.stringify(requestBody),
79 });
80
81 const result: GroupListResponse = await response.json();
82 return {
83 groups: result.data,
84 total: result.pagination?.total || result.total || 0,
85 totalPages: result.pagination?.total_pages,
86 };
87 } catch (error) {
88 if (error instanceof ApiError) {
89 throw error;
90 }
91 throw new ApiError(500, "Failed to fetch groups");
92 }
93}
94
95/**
96 * Get group details by group ID

Callers 1

useGroupListFunction · 0.90

Calls 2

fetchWithAuthFunction · 0.90
jsonMethod · 0.45

Tested by

no test coverage detected