[AAE-4995] Expand ADF PeopleContentService to create new person (#6931)

* [AAE-4995] Expose create/list content users API in ADF PeopleContentService

* * Updated documentation

* * Removed listPeople api

* * Added unit tests and improved old tests

* * Updated doc with js-api doc link

* *Fixed lint errors

* * Fixed failing unit tests
This commit is contained in:
siva kumar
2021-04-21 19:17:54 +05:30
committed by GitHub
parent cd349361d0
commit bf70e471ce
4 changed files with 118 additions and 76 deletions

View File

@@ -16,19 +16,24 @@
*/
import { Injectable } from '@angular/core';
import { Observable, from, of } from 'rxjs';
import { Observable, from, throwError } from 'rxjs';
import { AlfrescoApiService } from './alfresco-api.service';
import { catchError } from 'rxjs/operators';
import { catchError, map } from 'rxjs/operators';
import { PersonEntry, PeopleApi, PersonBodyCreate } from '@alfresco/js-api';
import { EcmUserModel } from '../models/ecm-user.model';
import { LogService } from './log.service';
@Injectable({
providedIn: 'root'
})
export class PeopleContentService {
constructor(private apiService: AlfrescoApiService) {}
private _peopleApi: PeopleApi;
private get peopleApi() {
return this.apiService.getInstance().core.peopleApi;
constructor(private apiService: AlfrescoApiService, private logService: LogService) {}
get peopleApi() {
return this._peopleApi || (this._peopleApi = new PeopleApi(this.apiService.getInstance()));
}
/**
@@ -40,7 +45,7 @@ export class PeopleContentService {
const promise = this.peopleApi.getPerson(personId);
return from(promise).pipe(
catchError((err) => of(err))
catchError((error) => this.handleError(error))
);
}
@@ -51,4 +56,21 @@ export class PeopleContentService {
getCurrentPerson(): Observable<any> {
return this.getPerson('-me-');
}
/**
* Creates new person.
* @param newPerson Object containing the new person details.
* @returns Created new person
*/
createPerson(newPerson: PersonBodyCreate, opts?: any): Observable<EcmUserModel> {
return from(this.peopleApi.createPerson(newPerson, opts)).pipe(
map((res: PersonEntry) => <EcmUserModel> res?.entry),
catchError((error) => this.handleError(error))
);
}
private handleError(error: any) {
this.logService.error(error);
return throwError(error || 'Server error');
}
}