use people api and new js api where possible (#5888)

* use people api and new js api where possible

* fix code and tests

* cleanup tests
This commit is contained in:
Denys Vuika
2020-08-12 13:45:48 +01:00
committed by GitHub
parent a0aaf0ea58
commit 4aa936bb9c
7 changed files with 119 additions and 135 deletions

View File

@@ -16,22 +16,26 @@
*/
import { Injectable } from '@angular/core';
import { Observable, from, throwError } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import { Observable, from } from 'rxjs';
import { map } from 'rxjs/operators';
import { ContentService } from './content.service';
import { AlfrescoApiService } from './alfresco-api.service';
import { LogService } from './log.service';
import { EcmUserModel } from '../models/ecm-user.model';
import { PersonEntry } from '@alfresco/js-api';
import { PeopleApi } from '@alfresco/js-api';
@Injectable({
providedIn: 'root'
})
export class EcmUserService {
private _peopleApi: PeopleApi;
constructor(private apiService: AlfrescoApiService,
private contentService: ContentService,
private logService: LogService) {
private contentService: ContentService) {
}
get peopleApi(): PeopleApi {
return this._peopleApi || (this._peopleApi = new PeopleApi(this.apiService.getInstance()));
}
/**
@@ -40,12 +44,9 @@ export class EcmUserService {
* @returns User information
*/
getUserInfo(userName: string): Observable<EcmUserModel> {
return from(this.apiService.getInstance().core.peopleApi.getPerson(userName))
return from(this.peopleApi.getPerson(userName))
.pipe(
map((personEntry: PersonEntry) => {
return new EcmUserModel(personEntry.entry);
}),
catchError((err) => this.handleError(err))
map((personEntry) => new EcmUserModel(personEntry.entry))
);
}
@@ -63,19 +64,6 @@ export class EcmUserService {
* @returns Image URL
*/
getUserProfileImage(avatarId: string): string {
if (avatarId) {
return this.contentService.getContentUrl(avatarId);
}
return null;
return this.contentService.getContentUrl(avatarId);
}
/**
* Throw the error
* @param error
*/
private handleError(error: any) {
this.logService.error(error);
return throwError(error || 'Server error');
}
}