import {HttpService, LocalDataService} from "@haventec/common-js/ts"; export class PropertyService { private listUrl = '/admin/property/:applicationUUID/category'; private getUrl = '/admin/property/:applicationUUID/category/:categoryname'; private updateUrl = '/admin/property/:applicationUUID/category'; private deleteUrl = '/admin/property/:applicationUUID/category/:categoryname'; private deletePropertyUrl = '/admin/property/:applicationUUID/category/:categoryname/name/:propertyname'; private getSmtpDetailsUrl = '/configuration/smtp'; private updateSmtpDetailsUrl = '/configuration/smtp'; private testStoredSmtpDetailsUrl = '/configuration/smtp/test-connection'; private basePath: string; private http: HttpService; constructor( public domainUrl: string, private localDataService: LocalDataService ) { this.http = new HttpService(); this.basePath = domainUrl; } list() { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); var url = self.basePath + this.listUrl.replace(':applicationUUID', applicationUUID); return this.http.get(url, this.localDataService.getAccessToken()); } get(categoryname: string) { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); var url = self.basePath + this.getUrl.replace(':applicationUUID', applicationUUID).replace(':categoryname', categoryname); return this.http.get(url, this.localDataService.getAccessToken()); } update(category: string, name: string, value: string) { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); var url = self.basePath + this.updateUrl.replace(':applicationUUID', applicationUUID); return this.http.post(url, {category: category, name: name, value: value}, this.localDataService.getAccessToken()); } deleteCategory(categoryname: string) { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); var url = self.basePath + this.deleteUrl.replace(':applicationUUID', applicationUUID).replace(':categoryname', categoryname); return this.http.delete(url, this.localDataService.getAccessToken()); } deleteCategoryProperty(categoryname: string, propertyname: string) { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); var url = self.basePath + this.deletePropertyUrl.replace(':applicationUUID', applicationUUID).replace(':categoryname', categoryname).replace(':propertyname', propertyname); return this.http.delete(url, this.localDataService.getAccessToken()); } getSmtpDetails() { let self : any = this; var url = self.basePath + this.getSmtpDetailsUrl; return this.http.get(url, this.localDataService.getAccessToken()); } updateSmtpDetails(host: string, port: string, username: string, password: string, enabled: boolean, tlsEnabled: boolean) { let self : any = this; var url = self.basePath + this.updateSmtpDetailsUrl; return this.http.put(url, {host: host, port: port, username: username, password: password, enabled: enabled, tlsEnabled: tlsEnabled}, this.localDataService.getAccessToken()); } testStoredSmtpConfiguration() { let self : any = this; var url = self.basePath + this.testStoredSmtpDetailsUrl; return this.http.get(url, this.localDataService.getAccessToken()); } }