import { request , IRequestOptions , ArcGISRequestError } from "@esri/arcgis-rest-request" ; import { getPortalUrl } from "../util/get-portal-url" ; import { chunk } from "../util/array" ; export interface IRemoveGroupUsersOptions extends IRequestOptions { /**
     * Group ID
     */ id : string ; /**
     * An array of usernames to be removed from the group
     */ users ? : string [ ] ; } export interface IRemoveGroupUsersResult { /**
     * An array of usernames that were not removed
     */ notRemoved ? : string [ ] ; /**
     * An array of request errors
     */ errors ? : ArcGISRequestError [ ] ; } param requestOptions returns export function removeGroupUsers ( requestOptions ) { const { id , users : usersToRemove } = requestOptions ; const url = `${ getPortalUrl ( requestOptions ) }/community/groups/${ id }/removeUsers` ; const safeSend = ( users ) => { const options = { ... requestOptions , users , params : { users } } ; return request ( url , options ) . catch ( error => ( { errors : [ error ] } ) ) ; } ; const promises = chunk ( usersToRemove , 25 ) . map ( usersChunk => safeSend ( usersChunk ) ) ; return Promise . all ( promises ) . then ( results => { const filtered = ( propName ) => results . filter ( result => result [ propName ] ) . reduce ( ( collection , result ) => collection . concat ( result [ propName ] ) , [ ] ) ; const errors = filtered ( 'errors' ) ; const consolidated = { notRemoved : filtered ( 'notRemoved' ) } ; return errors . length ? { ... consolidated , errors } : consolidated ; } ) ; }