diff --git a/docs/core/services/people-content.service.md b/docs/core/services/people-content.service.md index dcff36a8f1..9d927d0ed0 100644 --- a/docs/core/services/people-content.service.md +++ b/docs/core/services/people-content.service.md @@ -29,9 +29,9 @@ Gets information about a Content Services user. - **Returns** [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)`` - -- **listPeople**(options?: `any`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`EcmUserModel`](../../core/models/ecm-user.model.md)`[]>`
+- **listPeople**(requestQuery?: [`PeopleContentQueryRequestModel`](../../../lib/core/services/people-content.service.ts#32)): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`EcmUserModel`](../../core/models/ecm-user.model.md)`[]>`
Gets a list of people. - - _options:_ `any` - (Optional) Optional parameters supported by JS-API + - _requestQuery:_ [`PeopleContentQueryRequestModel`](../../../lib/core/services/people-content.service.ts) - (Optional) maxItems and skipCount used for pagination - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`EcmUserModel`](../../core/models/ecm-user.model.md)`[]>` - Array of people ## Details diff --git a/lib/core/services/people-content.service.spec.ts b/lib/core/services/people-content.service.spec.ts index 8918ac42e3..e24edb095a 100644 --- a/lib/core/services/people-content.service.spec.ts +++ b/lib/core/services/people-content.service.spec.ts @@ -18,14 +18,13 @@ import { fakeEcmUser, fakeEcmUserList, createNewPersonMock, getFakeUserWithContentAdminCapability } from '../mock/ecm-user.service.mock'; import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock'; import { CoreTestingModule } from '../testing/core.testing.module'; -import { PeopleContentService } from './people-content.service'; +import { PeopleContentService, PeopleContentQueryResponse } from './people-content.service'; import { AlfrescoApiService } from './alfresco-api.service'; import { setupTestBed } from '../testing/setup-test-bed'; import { TranslateModule } from '@ngx-translate/core'; import { TestBed } from '@angular/core/testing'; import { LogService } from './log.service'; import { of } from 'rxjs'; -import { EcmUserModel } from '../models/ecm-user.model'; describe('PeopleContentService', () => { @@ -74,11 +73,15 @@ describe('PeopleContentService', () => { it('should be able to list people', (done) => { spyOn(service.peopleApi, 'listPeople').and.returnValue(Promise.resolve(fakeEcmUserList)); - service.listPeople().subscribe((people: EcmUserModel[]) => { + service.listPeople().subscribe((response: PeopleContentQueryResponse) => { + const people = response.entries, pagination = response.pagination; expect(people).toBeDefined(); - expect(people.length).toEqual(2); expect(people[0].id).toEqual('fake-id'); expect(people[1].id).toEqual('another-fake-id'); + expect(pagination.count).toEqual(2); + expect(pagination.totalItems).toEqual(2); + expect(pagination.hasMoreItems).toBeFalsy(); + expect(pagination.skipCount).toEqual(0); done(); }); }); diff --git a/lib/core/services/people-content.service.ts b/lib/core/services/people-content.service.ts index e499fdff61..48f504029a 100644 --- a/lib/core/services/people-content.service.ts +++ b/lib/core/services/people-content.service.ts @@ -19,7 +19,7 @@ import { Injectable } from '@angular/core'; import { Observable, from, throwError } from 'rxjs'; import { AlfrescoApiService } from './alfresco-api.service'; import { catchError, map } from 'rxjs/operators'; -import { PersonEntry, PeopleApi, PersonBodyCreate } from '@alfresco/js-api'; +import { PersonEntry, PeopleApi, PersonBodyCreate, Pagination } from '@alfresco/js-api'; import { EcmUserModel } from '../models/ecm-user.model'; import { LogService } from './log.service'; @@ -27,6 +27,16 @@ export enum ContentGroups { ALFRESCO_ADMINISTRATORS = 'ALFRESCO_ADMINISTRATORS' } +export interface PeopleContentQueryResponse { + pagination: Pagination; + entries: EcmUserModel[]; +} + +export interface PeopleContentQueryRequestModel { + skipCount: number; + maxItems: number; +} + @Injectable({ providedIn: 'root' }) @@ -65,18 +75,17 @@ export class PeopleContentService { /** * Gets a list of people. - * @param opts Optional parameters supported by JS-API - * @returns Array of people + * @param requestQuery maxItems and skipCount parameters supported by JS-API + * @returns Response containing pagination and list of entries */ - listPeople(options?): Observable { - const promise = this.peopleApi.listPeople(options); + listPeople(requestQuery?: PeopleContentQueryRequestModel): Observable { + const promise = this.peopleApi.listPeople(requestQuery); return from(promise).pipe( map(response => { - const people: EcmUserModel[] = []; - response.list.entries.forEach((person: PersonEntry) => { - people.push( person?.entry); - }); - return people; + return { + pagination: response.list.pagination, + entries: response.list.entries.map((person: PersonEntry) => person.entry) + }; }), catchError((err) => this.handleError(err)) );