({
projectId,
groupId,
cursor,
take,
search,
}: {
projectId: string;
groupId: string;
cursor?: number;
take: number;
search?: string;
})
| 306 | } |
| 307 | |
| 308 | export 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 | |
| 354 | export async function listGroupTypesCore(projectId: string) { |
| 355 | const types = await getGroupTypes(projectId); |
no test coverage detected