MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / getGroupMemberProfiles

Function getGroupMemberProfiles

packages/db/src/services/group.service.ts:308–352  ·  view source on GitHub ↗
({
  projectId,
  groupId,
  cursor,
  take,
  search,
}: {
  projectId: string;
  groupId: string;
  cursor?: number;
  take: number;
  search?: string;
})

Source from the content-addressed store, hash-verified

306}
307
308export async function getGroupMemberProfiles({
309 projectId,
310 groupId,
311 cursor,
312 take,
313 search,
314}: {
315 projectId: string;
316 groupId: string;
317 cursor?: number;
318 take: number;
319 search?: string;
320}): Promise<{ data: IServiceProfile[]; count: number }> {
321 const offset = Math.max(0, (cursor ?? 0) * take);
322 const searchCondition = search?.trim()
323 ? `AND (email ILIKE ${sqlstring.escape(`%${search.trim()}%`)} OR first_name ILIKE ${sqlstring.escape(`%${search.trim()}%`)} OR last_name ILIKE ${sqlstring.escape(`%${search.trim()}%`)})`
324 : '';
325
326 const rows = await chQuery<{ id: string; total_count: number }>(`
327 SELECT
328 id,
329 count() OVER () AS total_count
330 FROM ${TABLE_NAMES.profiles} FINAL
331 WHERE project_id = ${sqlstring.escape(projectId)}
332 AND has(groups, ${sqlstring.escape(groupId)})
333 ${searchCondition}
334 ORDER BY created_at DESC
335 LIMIT ${take}
336 OFFSET ${offset}
337 `);
338
339 const count = rows[0]?.total_count ?? 0;
340 const profileIds = rows.map((r) => r.id);
341
342 if (profileIds.length === 0) {
343 return { data: [], count };
344 }
345
346 const profiles = await getProfiles(profileIds, projectId);
347 const byId = new Map(profiles.map((p) => [p.id, p]));
348 const data = profileIds
349 .map((id) => byId.get(id))
350 .filter(Boolean) as IServiceProfile[];
351 return { data, count };
352}
353
354export async function listGroupTypesCore(projectId: string) {
355 const types = await getGroupTypes(projectId);

Callers 4

registerGroupToolsFunction · 0.90
group.tsFile · 0.90
groups.tsFile · 0.90
getGroupCoreFunction · 0.85

Calls 3

getProfilesFunction · 0.90
mapMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected