Skip to content

Commit

Permalink
chore(:necktie:): break group source and tests out into individual files
Browse files Browse the repository at this point in the history
AFFECTS PACKAGES:
@esri/arcgis-rest-groups
  • Loading branch information
jgravois committed Sep 18, 2018
1 parent 03d3418 commit 174e6cd
Show file tree
Hide file tree
Showing 15 changed files with 681 additions and 560 deletions.
34 changes: 34 additions & 0 deletions packages/arcgis-rest-groups/src/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import {
request,
IRequestOptions,
getPortalUrl
} from "@esri/arcgis-rest-request";

import { IGroupAdd } from "@esri/arcgis-rest-common-types";

import { serializeGroup } from "./helpers";

export interface IGroupAddRequestOptions extends IRequestOptions {
group: IGroupAdd;
}

/**
* Create a new Group.
* Note: The group name must be unique within the user's organization.
* @param requestOptions - Options for the request, including a group object
* @returns A Promise that will resolve with the success/failure status of the request
*/
export function createGroup(
requestOptions: IGroupAddRequestOptions
): Promise<any> {
const url = `${getPortalUrl(requestOptions)}/community/createGroup`;
const options: IGroupAddRequestOptions = {
...requestOptions
};
// serialize the group into something Portal will accept
options.params = serializeGroup(requestOptions.group);
return request(url, options);
}
95 changes: 95 additions & 0 deletions packages/arcgis-rest-groups/src/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import {
request,
IRequestOptions,
getPortalUrl
} from "@esri/arcgis-rest-request";

import { IPagingParams, IGroup, IItem } from "@esri/arcgis-rest-common-types";

export interface IPagingParamsRequestOptions extends IRequestOptions {
paging: IPagingParams;
}

export interface IGroupContentResult {
total: number;
start: number;
num: number;
nextStart: number;
items: IItem[];
}

export interface IGroupUsersResult {
owner: string;
admins: string[];
users: string[];
}

/**
*
* @param id - Group Id
* @param requestOptions - Options for the request
* @returns A Promise that will resolve with the data from the response.
*/
export function getGroup(
id: string,
requestOptions?: IRequestOptions
): Promise<IGroup> {
const url = `${getPortalUrl(requestOptions)}/community/groups/${id}`;
// default to a GET request
const options: IRequestOptions = {
...{ httpMethod: "GET" },
...requestOptions
};
return request(url, options);
}

/**
* Returns the content of a Group. Since the group may contain 1000s of items
* the requestParams allow for paging.
* @param id - Group Id
* @param requestOptions - Options for the request, including paging parameters.
* @returns A Promise that will resolve with the content of the group.
*/
export function getGroupContent(
id: string,
requestOptions?: IPagingParamsRequestOptions
): Promise<IGroup> {
const url = `${getPortalUrl(requestOptions)}/content/groups/${id}`;

// default to a GET request
const options: IRequestOptions = {
...{ httpMethod: "GET" },
params: { start: 1, num: 100 },
...requestOptions
} as IPagingParamsRequestOptions;

// is this the most concise way to mixin with the defaults above?
if (requestOptions && requestOptions.paging) {
options.params = { ...requestOptions.paging };
}

return request(url, options);
}

/**
* Get the usernames of the admins and members. Does not return actual 'User' objects. Those must be
* retrieved via separate calls to the User's API.
* @param id - Group Id
* @param requestOptions - Options for the request
* @returns A Promise that will resolve with arrays of the group admin usernames and the member usernames
*/
export function getGroupUsers(
id: string,
requestOptions?: IRequestOptions
): Promise<IGroupUsersResult> {
const url = `${getPortalUrl(requestOptions)}/community/groups/${id}/users`;
// default to a GET request
const options: IRequestOptions = {
...{ httpMethod: "GET" },
...requestOptions
};
return request(url, options);
}
Loading

0 comments on commit 174e6cd

Please sign in to comment.