import {HttpService, LocalDataService} from "@haventec/common-js/ts"; export class GroupService { private listUrl = '/admin/groups/:applicationUUID/internal?page=:page&size=:size'; private getUrl = '/admin/groups/:applicationUUID/internal/:name'; private updateUrl = '/admin/groups/:applicationUUID/internal'; private deleteUrl = '/admin/groups/:applicationUUID/internal/:name'; private getRolesUrl = '/admin/groups/:applicationUUID/role/:name'; private updateRolesUrl = '/admin/groups/:applicationUUID/role/:name'; private basePath: string; private http: HttpService; constructor( public domainUrl: string, private localDataService: LocalDataService ) { this.http = new HttpService(); this.basePath = domainUrl; } list(page: number, size: number) { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); page = page || 0; size = size || 10; var url = self.basePath + this.listUrl.replace(':applicationUUID', applicationUUID).replace(':page', page.toString()).replace(':size', size.toString()); return this.http.get(url, this.localDataService.getAccessToken()); } get(name: string) { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); var url = self.basePath + this.getUrl.replace(':applicationUUID', applicationUUID).replace(':name', name); return this.http.get(url, this.localDataService.getAccessToken()); } update(name: string, description: string) { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); var url = self.basePath + this.updateUrl.replace(':applicationUUID', applicationUUID); return this.http.post(url, {name: name, description: description}, this.localDataService.getAccessToken()); } delete(name: string) { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); var url = self.basePath + this.deleteUrl.replace(':applicationUUID', applicationUUID).replace(':name', name); return this.http.delete(url, this.localDataService.getAccessToken()); } getRoles(name: string) { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); var url = self.basePath + this.getRolesUrl.replace(':applicationUUID', applicationUUID).replace(':name', name); return this.http.get(url, this.localDataService.getAccessToken()); } updateRoles(name: string, roleNames: Array) { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); var url = self.basePath + this.updateRolesUrl.replace(':applicationUUID', applicationUUID).replace(':name', name); return this.http.post(url, {roleNames: roleNames}, this.localDataService.getAccessToken()); } }