import {HttpService, LocalDataService} from "@haventec/common-js/ts"; export class UserService { private listCPUrl = '/user?page=:page&size=:size'; private listUrl = '/application/:applicationUUID/user?page=:page&size=:size'; private getUrl = '/application/:applicationUUID/user/:username'; private preprovisionUrl = '/user/:applicationUUID/preprovision'; private changelockstatusUrl = '/user/:applicationUUID/locked/:username'; private deleteUrl = '/application/:applicationUUID/user/:username'; private getGroupsUrl = '/user/:applicationUUID/group/:username'; private updateGroupsUrl = '/user/:applicationUUID/group/:username'; private basePath: string; private http: HttpService; constructor( public domainUrl: string, private localDataService: LocalDataService ) { this.http = new HttpService(); this.basePath = domainUrl; } listCloudPortalUsers(page: number, size: number) { let self : any = this; page = page || 0; size = size || 10; var url = self.basePath + this.listCPUrl.replace(':page', page.toString()).replace(':size', size.toString()); return this.http.get(url, this.localDataService.getAccessToken()); } listForApplication(applicationUUID: string, page: number, size: number) { let self : any = this; 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(username: string) { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); var url = self.basePath + this.getUrl.replace(':applicationUUID', applicationUUID).replace(':username', username); return this.http.get(url, this.localDataService.getAccessToken()); } preprovision(username: string, email: string, groupName: string) { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); var url = self.basePath + this.preprovisionUrl.replace(':applicationUUID', applicationUUID); return this.http.post(url, {username: username, email: email, groupName: groupName}, this.localDataService.getAccessToken()); } changelockstatus(username: string) { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); var url = self.basePath + this.changelockstatusUrl.replace(':applicationUUID', applicationUUID).replace(':username', username); return this.http.post(url, null, this.localDataService.getAccessToken()); } delete(username: string) { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); var url = self.basePath + this.deleteUrl.replace(':applicationUUID', applicationUUID).replace(':username', username); return this.http.delete(url, this.localDataService.getAccessToken()); } getGroups(username: string) { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); var url = self.basePath + this.getGroupsUrl.replace(':applicationUUID', applicationUUID).replace(':username', username); return this.http.get(url, this.localDataService.getAccessToken()); } updateGroups(username: string, groupNames: Array) { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); var url = self.basePath + this.updateGroupsUrl.replace(':applicationUUID', applicationUUID).replace(':username', username); return this.http.post(url, {groupNames: groupNames}, this.localDataService.getAccessToken()); } }