[AAE-5208] Add pagination info to listPeople function in PeopleContentService (#7055)

* [AAE-5208] Add pagination info to listPeople function in PeopleContentService

* Change documentation
This commit is contained in:
Thomas Hunter 2021-06-02 12:49:47 +02:00 committed by GitHub
parent 4bf9433c82
commit 40bbeb13f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 16 deletions

View File

@ -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)`<boolean>` - - **Returns** [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)`<boolean>` -
- **listPeople**(options?: `any`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`EcmUserModel`](../../core/models/ecm-user.model.md)`[]>`<br/> - **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)`[]>`<br/>
Gets a list of people. 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 - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`EcmUserModel`](../../core/models/ecm-user.model.md)`[]>` - Array of people
## Details ## Details

View File

@ -18,14 +18,13 @@
import { fakeEcmUser, fakeEcmUserList, createNewPersonMock, getFakeUserWithContentAdminCapability } from '../mock/ecm-user.service.mock'; import { fakeEcmUser, fakeEcmUserList, createNewPersonMock, getFakeUserWithContentAdminCapability } from '../mock/ecm-user.service.mock';
import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock'; import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock';
import { CoreTestingModule } from '../testing/core.testing.module'; 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 { AlfrescoApiService } from './alfresco-api.service';
import { setupTestBed } from '../testing/setup-test-bed'; import { setupTestBed } from '../testing/setup-test-bed';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { LogService } from './log.service'; import { LogService } from './log.service';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { EcmUserModel } from '../models/ecm-user.model';
describe('PeopleContentService', () => { describe('PeopleContentService', () => {
@ -74,11 +73,15 @@ describe('PeopleContentService', () => {
it('should be able to list people', (done) => { it('should be able to list people', (done) => {
spyOn(service.peopleApi, 'listPeople').and.returnValue(Promise.resolve(fakeEcmUserList)); 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).toBeDefined();
expect(people.length).toEqual(2);
expect(people[0].id).toEqual('fake-id'); expect(people[0].id).toEqual('fake-id');
expect(people[1].id).toEqual('another-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(); done();
}); });
}); });

View File

@ -19,7 +19,7 @@ import { Injectable } from '@angular/core';
import { Observable, from, throwError } from 'rxjs'; import { Observable, from, throwError } from 'rxjs';
import { AlfrescoApiService } from './alfresco-api.service'; import { AlfrescoApiService } from './alfresco-api.service';
import { catchError, map } from 'rxjs/operators'; 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 { EcmUserModel } from '../models/ecm-user.model';
import { LogService } from './log.service'; import { LogService } from './log.service';
@ -27,6 +27,16 @@ export enum ContentGroups {
ALFRESCO_ADMINISTRATORS = 'ALFRESCO_ADMINISTRATORS' ALFRESCO_ADMINISTRATORS = 'ALFRESCO_ADMINISTRATORS'
} }
export interface PeopleContentQueryResponse {
pagination: Pagination;
entries: EcmUserModel[];
}
export interface PeopleContentQueryRequestModel {
skipCount: number;
maxItems: number;
}
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
@ -65,18 +75,17 @@ export class PeopleContentService {
/** /**
* Gets a list of people. * Gets a list of people.
* @param opts Optional parameters supported by JS-API * @param requestQuery maxItems and skipCount parameters supported by JS-API
* @returns Array of people * @returns Response containing pagination and list of entries
*/ */
listPeople(options?): Observable<EcmUserModel[]> { listPeople(requestQuery?: PeopleContentQueryRequestModel): Observable<PeopleContentQueryResponse> {
const promise = this.peopleApi.listPeople(options); const promise = this.peopleApi.listPeople(requestQuery);
return from(promise).pipe( return from(promise).pipe(
map(response => { map(response => {
const people: EcmUserModel[] = []; return {
response.list.entries.forEach((person: PersonEntry) => { pagination: response.list.pagination,
people.push(<EcmUserModel> person?.entry); entries: response.list.entries.map((person: PersonEntry) => <EcmUserModel> person.entry)
}); };
return people;
}), }),
catchError((err) => this.handleError(err)) catchError((err) => this.handleError(err))
); );