From 1e251ab8aa4efcccdb7d72a94a34f30c7b040673 Mon Sep 17 00:00:00 2001 From: arditdomi <32884230+arditdomi@users.noreply.github.com> Date: Tue, 22 Jun 2021 18:08:01 +0100 Subject: [PATCH] [AAE-5392] - Add find people api call (#7119) * [AAE-5392] - Add find people api call * Add documentation --- docs/core/services/people-content.service.md | 5 ++++ .../services/people-content.service.spec.ts | 9 +++++++ lib/core/services/people-content.service.ts | 26 ++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/docs/core/services/people-content.service.md b/docs/core/services/people-content.service.md index 9d927d0ed03..2e74eae1bf2 100644 --- a/docs/core/services/people-content.service.md +++ b/docs/core/services/people-content.service.md @@ -34,6 +34,11 @@ Gets information about a Content Services user. - _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 +- **findPeople**(searchTerm: string, 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. + - _searchTerm:_ `string` - The term to search for + - _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 The class returned by `getPerson` and `getCurrentPerson` is detailed diff --git a/lib/core/services/people-content.service.spec.ts b/lib/core/services/people-content.service.spec.ts index 9c2498087b8..6e675774a68 100644 --- a/lib/core/services/people-content.service.spec.ts +++ b/lib/core/services/people-content.service.spec.ts @@ -94,6 +94,15 @@ describe('PeopleContentService', () => { }); }); + it('should search for users with search term and pagination info', (done) => { + const findPeopleSpy = spyOn(service.queriesApi, 'findPeople').and.returnValue(Promise.resolve({ ...fakeEcmUserList })); + + service.findPeople('fake-term', { skipCount: 5, maxItems: 10 }).subscribe(() => { + expect(findPeopleSpy).toHaveBeenCalledWith('fake-term', { skipCount: 5, maxItems: 10 }); + done(); + }); + }); + it('should be able to create new person', (done) => { spyOn(service.peopleApi, 'createPerson').and.returnValue(Promise.resolve(new PersonEntry({ entry: fakeEcmUser }))); service.createPerson(createNewPersonMock).subscribe((person) => { diff --git a/lib/core/services/people-content.service.ts b/lib/core/services/people-content.service.ts index 48f504029a9..02145cb8f62 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, Pagination } from '@alfresco/js-api'; +import { PersonEntry, PeopleApi, PersonBodyCreate, Pagination, QueriesApi } from '@alfresco/js-api'; import { EcmUserModel } from '../models/ecm-user.model'; import { LogService } from './log.service'; @@ -45,6 +45,7 @@ export class PeopleContentService { hasCheckedIsContentAdmin: boolean = false; private _peopleApi: PeopleApi; + private _queriesApi: QueriesApi; constructor(private apiService: AlfrescoApiService, private logService: LogService) {} @@ -52,6 +53,10 @@ export class PeopleContentService { return this._peopleApi || (this._peopleApi = new PeopleApi(this.apiService.getInstance())); } + get queriesApi() { + return this._queriesApi || (this._queriesApi = new QueriesApi(this.apiService.getInstance())); + } + /** * Gets information about a user identified by their username. * @param personId ID of the target user @@ -91,6 +96,25 @@ export class PeopleContentService { ); } + /** + * Gets a list of people that match the given search criteria. + * @param searchTerm The term to search for + * @param requestQuery maxItems and skipCount parameters supported by JS-API + * @returns Response containing pagination and list of entries + */ + findPeople(searchTerm: string, requestQuery?: PeopleContentQueryRequestModel): Observable { + const promise = this.queriesApi.findPeople(searchTerm, { ...requestQuery }); + return from(promise).pipe( + map(response => { + return { + pagination: response.list.pagination, + entries: response.list.entries.map((person: PersonEntry) => person.entry) + }; + }), + catchError((err) => this.handleError(err)) + ); + } + /** * Creates new person. * @param newPerson Object containing the new person details.