From 5d5b582e32ec44b8497442cb927a07f9860894a3 Mon Sep 17 00:00:00 2001 From: siva kumar Date: Mon, 2 Aug 2021 15:10:46 +0530 Subject: [PATCH] [AAE-5529] Include sorting params in the PeopleContentQueryRequestModel (#7193) --- .../services/people-content.service.spec.ts | 12 +++++++++++- lib/core/services/people-content.service.ts | 18 ++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/core/services/people-content.service.spec.ts b/lib/core/services/people-content.service.spec.ts index 3a16fac1f9..a37acebd3f 100644 --- a/lib/core/services/people-content.service.spec.ts +++ b/lib/core/services/people-content.service.spec.ts @@ -94,7 +94,7 @@ describe('PeopleContentService', () => { }); }); - it('should call listPeople api with requested query params', async () => { + it('should call listPeople api with requested sorting params', async () => { const listPeopleSpy = spyOn(service.peopleApi, 'listPeople').and.returnValue(Promise.resolve(fakeEcmUserList)); const requestQueryParams: PeopleContentQueryRequestModel = { skipCount: 10, maxItems: 20, sorting: { orderBy: 'firstName', direction: 'asc' } }; const expectedValue = { skipCount: 10, maxItems: 20, orderBy: ['firstName ASC'] }; @@ -104,6 +104,16 @@ describe('PeopleContentService', () => { expect(listPeopleSpy).toHaveBeenCalledWith(expectedValue); }); + it('should not call listPeople api with sorting params if sorting is not defined', async () => { + const listPeopleSpy = spyOn(service.peopleApi, 'listPeople').and.returnValue(Promise.resolve(fakeEcmUserList)); + const requestQueryParams: PeopleContentQueryRequestModel = { skipCount: 10, maxItems: 20, sorting: undefined }; + const expectedValue = { skipCount: 10, maxItems: 20 }; + + await service.listPeople(requestQueryParams).toPromise(); + + expect(listPeopleSpy).toHaveBeenCalledWith(expectedValue); + }); + 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 b7274101a7..6a3a5300b6 100644 --- a/lib/core/services/people-content.service.ts +++ b/lib/core/services/people-content.service.ts @@ -52,8 +52,6 @@ export class PeopleContentService { private _peopleApi: PeopleApi; - defaultSorting = ['firstName ASC']; - constructor(private apiService: AlfrescoApiService, private logService: LogService) {} get peopleApi() { @@ -87,12 +85,12 @@ export class PeopleContentService { * @returns Response containing pagination and list of entries */ listPeople(requestQuery?: PeopleContentQueryRequestModel): Observable { - const orderBy = this.buildOrderArray(requestQuery?.sorting.orderBy, requestQuery?.sorting.direction); - const requestQueryParams = { - skipCount: requestQuery?.skipCount, - maxItems: requestQuery?.maxItems, - orderBy - }; + const requestQueryParams = { skipCount: requestQuery?.skipCount, maxItems: requestQuery?.maxItems }; + const orderBy = this.buildOrderArray(requestQuery?.sorting); + if (orderBy.length) { + requestQueryParams['orderBy'] = orderBy; + } + const promise = this.peopleApi.listPeople(requestQueryParams); return from(promise).pipe( map(response => { @@ -127,8 +125,8 @@ export class PeopleContentService { return this.hasContentAdminRole; } - private buildOrderArray(key: string, direction: string): string[] { - return key && direction ? [ `${key} ${direction.toUpperCase()}` ] : this.defaultSorting ; + private buildOrderArray(sorting: PeopleContentSortingModel): string[] { + return sorting?.orderBy && sorting?.direction ? [ `${sorting.orderBy} ${sorting.direction.toUpperCase()}` ] : []; } private handleError(error: any) {