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 listPeopleSpy = spyOn(service.peopleApi, 'listPeople').and.returnValue(Promise.resolve(fakeEcmUserList));
|
||||||
const requestQueryParams: PeopleContentQueryRequestModel = { skipCount: 10, maxItems: 20, sorting: { orderBy: 'firstName', direction: 'asc' } };
|
const requestQueryParams: PeopleContentQueryRequestModel = { skipCount: 10, maxItems: 20, sorting: { orderBy: 'firstName', direction: 'asc' } };
|
||||||
const expectedValue = { skipCount: 10, maxItems: 20, orderBy: ['firstName ASC'] };
|
const expectedValue = { skipCount: 10, maxItems: 20, orderBy: ['firstName ASC'] };
|
||||||
@@ -104,6 +104,16 @@ describe('PeopleContentService', () => {
|
|||||||
expect(listPeopleSpy).toHaveBeenCalledWith(expectedValue);
|
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) => {
|
it('should be able to create new person', (done) => {
|
||||||
spyOn(service.peopleApi, 'createPerson').and.returnValue(Promise.resolve(new PersonEntry({ entry: fakeEcmUser })));
|
spyOn(service.peopleApi, 'createPerson').and.returnValue(Promise.resolve(new PersonEntry({ entry: fakeEcmUser })));
|
||||||
service.createPerson(createNewPersonMock).subscribe((person) => {
|
service.createPerson(createNewPersonMock).subscribe((person) => {
|
||||||
|
@@ -52,8 +52,6 @@ export class PeopleContentService {
|
|||||||
|
|
||||||
private _peopleApi: PeopleApi;
|
private _peopleApi: PeopleApi;
|
||||||
|
|
||||||
defaultSorting = ['firstName ASC'];
|
|
||||||
|
|
||||||
constructor(private apiService: AlfrescoApiService, private logService: LogService) {}
|
constructor(private apiService: AlfrescoApiService, private logService: LogService) {}
|
||||||
|
|
||||||
get peopleApi() {
|
get peopleApi() {
|
||||||
@@ -87,12 +85,12 @@ export class PeopleContentService {
|
|||||||
* @returns Response containing pagination and list of entries
|
* @returns Response containing pagination and list of entries
|
||||||
*/
|
*/
|
||||||
listPeople(requestQuery?: PeopleContentQueryRequestModel): Observable<PeopleContentQueryResponse> {
|
listPeople(requestQuery?: PeopleContentQueryRequestModel): Observable<PeopleContentQueryResponse> {
|
||||||
const orderBy = this.buildOrderArray(requestQuery?.sorting.orderBy, requestQuery?.sorting.direction);
|
const requestQueryParams = { skipCount: requestQuery?.skipCount, maxItems: requestQuery?.maxItems };
|
||||||
const requestQueryParams = {
|
const orderBy = this.buildOrderArray(requestQuery?.sorting);
|
||||||
skipCount: requestQuery?.skipCount,
|
if (orderBy.length) {
|
||||||
maxItems: requestQuery?.maxItems,
|
requestQueryParams['orderBy'] = orderBy;
|
||||||
orderBy
|
}
|
||||||
};
|
|
||||||
const promise = this.peopleApi.listPeople(requestQueryParams);
|
const promise = this.peopleApi.listPeople(requestQueryParams);
|
||||||
return from(promise).pipe(
|
return from(promise).pipe(
|
||||||
map(response => {
|
map(response => {
|
||||||
@@ -127,8 +125,8 @@ export class PeopleContentService {
|
|||||||
return this.hasContentAdminRole;
|
return this.hasContentAdminRole;
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildOrderArray(key: string, direction: string): string[] {
|
private buildOrderArray(sorting: PeopleContentSortingModel): string[] {
|
||||||
return key && direction ? [ `${key} ${direction.toUpperCase()}` ] : this.defaultSorting ;
|
return sorting?.orderBy && sorting?.direction ? [ `${sorting.orderBy} ${sorting.direction.toUpperCase()}` ] : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleError(error: any) {
|
private handleError(error: any) {
|
||||||
|
Reference in New Issue
Block a user