/
getEventGroups.ts
33 lines (32 loc) · 1.04 KB
/
getEventGroups.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { IGroup, ISearchResult, searchGroups } from "@esri/arcgis-rest-portal";
import { getEvent } from "../api/events";
import { IArcGISContext } from "../../ArcGISContext";
/**
* Fetches the groups an event is shared with
* @param eventId The ID of the event to fetch the groups for
* @param context An IArcGISContext object
* @returns
*/
export async function getEventGroups(
eventId: string,
context: IArcGISContext
): Promise<IGroup[]> {
const { editGroups: editGroupIds, readGroups: readGroupIds } = await getEvent(
{
eventId,
...context.hubRequestOptions,
}
);
const search = (ids: string[]): Promise<ISearchResult<IGroup>> =>
ids.length
? searchGroups({
q: `id:(${ids.join(" OR ")})`,
num: ids.length,
...context.requestOptions,
})
: Promise.resolve({ results: [] } as ISearchResult<IGroup>);
const [{ results: readGroups }, { results: editGroups }] = await Promise.all(
[readGroupIds, editGroupIds].map(search)
);
return [...readGroups, ...editGroups];
}