mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
[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:
parent
4bf9433c82
commit
40bbeb13f0
@ -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>` -
|
||||
|
||||
- **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.
|
||||
- _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
|
||||
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
@ -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<EcmUserModel[]> {
|
||||
const promise = this.peopleApi.listPeople(options);
|
||||
listPeople(requestQuery?: PeopleContentQueryRequestModel): Observable<PeopleContentQueryResponse> {
|
||||
const promise = this.peopleApi.listPeople(requestQuery);
|
||||
return from(promise).pipe(
|
||||
map(response => {
|
||||
const people: EcmUserModel[] = [];
|
||||
response.list.entries.forEach((person: PersonEntry) => {
|
||||
people.push(<EcmUserModel> person?.entry);
|
||||
});
|
||||
return people;
|
||||
return {
|
||||
pagination: response.list.pagination,
|
||||
entries: response.list.entries.map((person: PersonEntry) => <EcmUserModel> person.entry)
|
||||
};
|
||||
}),
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user