Skip to content

Commit

Permalink
[ACA-1606] use new api siteservice (#5693)
Browse files Browse the repository at this point in the history
* use new apu siteservice

* refactor import

* added getSiteMembershipRequests

Co-authored-by: Cilibiu Bogdan <bogdan.cilibiu@ness.com>
  • Loading branch information
eromano and pionnegru committed May 13, 2020
1 parent 6da489a commit b76bb75
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 6 deletions.
48 changes: 48 additions & 0 deletions lib/core/services/sites.service.spec.ts
Expand Up @@ -105,4 +105,52 @@ describe('Sites service', () => {
}
});
});

it('should get a list of membership requests', (done) => {
service.getSiteMembershipRequests().subscribe((data) => {
expect(data.list.entries[0].entry.site.id).toBe('site-id');
expect(data.list.entries[0].entry.person.id).toBe('user-id');
done();
});

jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: {
'list': {
'pagination': {
'count': 1,
'hasMoreItems': false,
'totalItems': 1,
'skipCount': 0,
'maxItems': 100
},
'entries': [
{
'entry': {
'id': 'site-id',
'createdAt': '2020-05-13T07:46:36.180Z',
'site': {
'id': 'site-id',
'guid': 'b4cff62a-664d-4d45-9302-98723eac1319',
'title': 'Sample Site',
'description': '',
'visibility': 'MODERATED',
'preset': 'preset',
'role': 'Manager'
},
'person': {
'id': 'user-id',
'firstName': 'string',
'lastName': 'string',
'displayName': 'string'
},
'message': 'message'
}
}
]
}
}
});
});
});
26 changes: 20 additions & 6 deletions lib/core/services/sites.service.ts
Expand Up @@ -18,16 +18,18 @@
import { Injectable } from '@angular/core';
import { Observable, from, throwError } from 'rxjs';
import { AlfrescoApiService } from './alfresco-api.service';
import { SitePaging, SiteEntry } from '@alfresco/js-api';
import { SitePaging, SiteEntry, SitesApi, SiteMembershipRequestWithPersonPaging } from '@alfresco/js-api';
import { catchError } from 'rxjs/operators';

@Injectable({
providedIn: 'root'
})
export class SitesService {

constructor(
private apiService: AlfrescoApiService) {
sitesApi: SitesApi;

constructor(private apiService: AlfrescoApiService) {
this.sitesApi = new SitesApi(apiService.getInstance());
}

/**
Expand All @@ -41,7 +43,7 @@ export class SitesService {
include: ['properties']
};
const queryOptions = Object.assign({}, defaultOptions, opts);
return from(this.apiService.getInstance().core.sitesApi.getSites(queryOptions))
return from(this.sitesApi.listSites(queryOptions))
.pipe(
catchError((err: any) => this.handleError(err))
);
Expand All @@ -54,7 +56,7 @@ export class SitesService {
* @returns Information about the site
*/
getSite(siteId: string, opts?: any): Observable<SiteEntry | {}> {
return from(this.apiService.getInstance().core.sitesApi.getSite(siteId, opts))
return from(this.sitesApi.getSite(siteId, opts))
.pipe(
catchError((err: any) => this.handleError(err))
);
Expand All @@ -69,7 +71,7 @@ export class SitesService {
deleteSite(siteId: string, permanentFlag: boolean = true): Observable<any> {
const options: any = {};
options.permanent = permanentFlag;
return from(this.apiService.getInstance().core.sitesApi.deleteSite(siteId, options))
return from(this.sitesApi.deleteSite(siteId, options))
.pipe(
catchError((err: any) => this.handleError(err))
);
Expand Down Expand Up @@ -101,6 +103,18 @@ export class SitesService {
return this.apiService.getInstance().getEcmUsername();
}

/**
* Gets a list of site membership requests.
* @param opts Options supported by JS-API
* @returns Site membership requests
*/
getSiteMembershipRequests(opts?: any): Observable<SiteMembershipRequestWithPersonPaging | {}> {
return from(this.sitesApi.getSiteMembershipRequests(opts))
.pipe(
catchError((err: any) => this.handleError(err))
);
}

private handleError(error: any): any {
console.error(error);
return throwError(error || 'Server error');
Expand Down

0 comments on commit b76bb75

Please sign in to comment.