Skip to content

Commit

Permalink
[AAE-5529] Include sorting params in the PeopleContentQueryRequestMod…
Browse files Browse the repository at this point in the history
…el (#7193)
  • Loading branch information
sivakumar414ram committed Aug 2, 2021
1 parent 4befb77 commit 5d5b582
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
12 changes: 11 additions & 1 deletion lib/core/services/people-content.service.spec.ts
Expand Up @@ -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'] };
Expand All @@ -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) => {
Expand Down
18 changes: 8 additions & 10 deletions lib/core/services/people-content.service.ts
Expand Up @@ -52,8 +52,6 @@ export class PeopleContentService {

private _peopleApi: PeopleApi;

defaultSorting = ['firstName ASC'];

constructor(private apiService: AlfrescoApiService, private logService: LogService) {}

get peopleApi() {
Expand Down Expand Up @@ -87,12 +85,12 @@ export class PeopleContentService {
* @returns Response containing pagination and list of entries
*/
listPeople(requestQuery?: PeopleContentQueryRequestModel): Observable<PeopleContentQueryResponse> {
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 => {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 5d5b582

Please sign in to comment.