import { IGroupTemplate } from "../types" ; import { IHubRequestOptions } from "@esri/hub-common" ; import { _translateTeamTemplate } from "./_translate-team-template" ; import { _createTeamGroup } from "./_create-team-group" ; import { IGroup } from "@esri/arcgis-rest-types" ; param { String } title param { Array } groupTemplates param { IHubRequestOptions } hubRequestOptions private export function _createTeamGroups ( title , groupTemplates , translations , hubRequestOptions ) { const translatedTemplates = groupTemplates . map ( tmpl => { return _translateTeamTemplate ( tmpl , title , translations ) ; } ) ; return Promise . all ( translatedTemplates . map ( grpTmpl => { return _createTeamGroup ( hubRequestOptions . portalSelf . user , grpTmpl , hubRequestOptions ) ; } ) ) . then ( groups => { const props = groups . reduce ( ( acc , grp ) => { if ( grp . config . propertyName ) { acc [ grp . config . propertyName ] = grp . id ; } return acc ; } , { } as any ) ; groups . forEach ( g => delete g . config ) ; return { props , groups : groups as IGroup [ ] } ; } ) . catch ( ex => { throw Error ( `Error in team-utils::_createTeamGroups ${ ex }` ) ; } ) ; }