import { IUser } from "@esri/arcgis-rest-auth" ; import { IHubRequestOptions } from "@esri/hub-common" ; import { createGroup , protectGroup , IGroup } from "@esri/arcgis-rest-portal" ; import { getUniqueGroupTitle } from "./get-unique-group-title" ; import { getAllowedGroupAccess } from "./get-allowed-group-access" ; import { IGroupTemplate } from "../types" ; param { Object } user param { Object } group param { IHubRequestOptions } hubRequestOptions private export function _createTeamGroup ( user , group , hubRequestOptions ) { group . access = getAllowedGroupAccess ( group . access , user , hubRequestOptions . portalSelf ) ; return getUniqueGroupTitle ( group . title , hubRequestOptions ) . then ( uniqueTitle => { group . title = uniqueTitle ; return createGroup ( { group : group as IGroup , authentication : hubRequestOptions . authentication } ) ; } ) . then ( createResponse => { group . id = createResponse . group . id ; return protectGroup ( { id : group . id , authentication : hubRequestOptions . authentication } ) ; } ) . then ( ( ) => { group . userMembership = { username : user . username , memberType : "owner" , applications : 0 } ; return group ; } ) . catch ( ex => { throw Error ( `Error in team-utils::_createTeamGroup ${ ex }` ) ; } ) ; }