mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-5529] Include sorting params in the PeopleContentQueryRequestModel (#7193)
This commit is contained in:
@@ -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) => {
|
||||
|
@@ -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<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 => {
|
||||
@@ -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) {
|
||||
|
Reference in New Issue
Block a user