import { HttpClient, HttpParams } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { IListItemAclRights } from '../models/list.item.acl.rights'; import { ISharedItem } from '../models/shared.item'; import { AppConfig } from '../shared/app.config'; import { IListItem } from '../models/list.item'; @Injectable({ providedIn: 'root' }) export class SharedItemService { constructor( public httpClient: HttpClient, public appConfig: AppConfig) { } apiEndpoint() { return this.appConfig.getConfig('apiEndPoint'); } public getSharedUsersForItem(itemCode: string): Observable { return this.httpClient.get(`${this.apiEndpoint()}/api/v1/items/${itemCode}/sharedusers`); } getSharedItemsWithRightsInfo(userCode: string): Observable { return this.httpClient.get(`${this.apiEndpoint()}/api/v1/users/${userCode}/shared`); } shareItem(itemCode: string, userCode: string, userRights: string, expireTimespan: string, deep: boolean): Observable { const body = { rights: userRights, expire: expireTimespan, deep: deep }; return this.httpClient.post(`${this.apiEndpoint()}/api/v1/items/${itemCode}/share/${userCode}`, body); } revokeSharedItem(itemCode: string, userCode: string): Observable { return this.httpClient.delete(`${this.apiEndpoint()}/api/v1/items/${itemCode}/share/${userCode}`); } getSharedItemRights(sharedByMe: boolean): Observable { let params = new HttpParams(); params = params.append('byMe', sharedByMe); return this.httpClient.get(`${this.apiEndpoint()}/api/v1/user/rights`, {params: params}); } getSharedItemsByParent(parentCode: string): Observable { return this.httpClient.get(`${this.apiEndpoint()}/api/v1/items/${parentCode}/sharedchildren`); } getSharedWithCurrentUser(profile: string): Observable { let params = new HttpParams(); if (profile != null) { params = params.append('sharedBy', profile); } return this.httpClient.get(`${this.apiEndpoint()}/api/v1/items/shared/`, {params: params}); } // this method does not belong here, belongs in some sort of item service public copyItem(itemCode: string, newParentCode: string, newUserCode: string): Observable { const body = { itemCode: itemCode, newParentCode: newParentCode, newUserCode: newUserCode }; return this.httpClient.post(`${this.apiEndpoint()}/api/v1/items/copy`, body); } }