[AAE-5529] Include sorting params in the PeopleContentQueryRequestModel (#7182)

* [AAE-5529] Include sorting params in the PeopleContentQueryRequestModel

* * Added unit tests to the recent changes on people content service

* * Fixed comment
This commit is contained in:
siva kumar
2021-07-28 16:47:15 +05:30
committed by GitHub
parent 29b4190888
commit 4940ffb006
2 changed files with 32 additions and 4 deletions

View File

@@ -32,9 +32,15 @@ export interface PeopleContentQueryResponse {
entries: EcmUserModel[];
}
export interface PeopleContentSortingModel {
orderBy: string;
direction: string;
}
export interface PeopleContentQueryRequestModel {
skipCount: number;
maxItems: number;
skipCount?: number;
maxItems?: number;
sorting?: PeopleContentSortingModel;
}
@Injectable({
@@ -46,6 +52,8 @@ export class PeopleContentService {
private _peopleApi: PeopleApi;
defaultSorting = ['firstName ASC'];
constructor(private apiService: AlfrescoApiService, private logService: LogService) {}
get peopleApi() {
@@ -79,7 +87,13 @@ export class PeopleContentService {
* @returns Response containing pagination and list of entries
*/
listPeople(requestQuery?: PeopleContentQueryRequestModel): Observable<PeopleContentQueryResponse> {
const promise = this.peopleApi.listPeople(requestQuery);
const orderBy = this.buildOrderArray(requestQuery?.sorting.orderBy, requestQuery?.sorting.direction);
const requestQueryParams = {
skipCount: requestQuery?.skipCount,
maxItems: requestQuery?.maxItems,
orderBy
};
const promise = this.peopleApi.listPeople(requestQueryParams);
return from(promise).pipe(
map(response => {
return {
@@ -113,6 +127,10 @@ export class PeopleContentService {
return this.hasContentAdminRole;
}
private buildOrderArray(key: string, direction: string): string[] {
return key && direction ? [ `${key} ${direction.toUpperCase()}` ] : this.defaultSorting ;
}
private handleError(error: any) {
this.logService.error(error);
return throwError(error || 'Server error');