mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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:
@@ -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');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user