import {HttpService, LocalDataService} from "@haventec/common-js/ts"; export class DeviceService { private listUrl = '/admin/devices/:applicationUUID/device?page=:page&size=:size'; private getUrl = '/admin/devices/:applicationUUID/device/:udid'; private updateUrl = '/admin/devices/:applicationUUID/device'; private changelockstatusUrl = '/admin/devices/:applicationUUID/locked/:udid'; private deleteUrl = '/admin/devices/:applicationUUID/device/:udid'; 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(udid: string) { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); var url = self.basePath + this.getUrl.replace(':applicationUUID', applicationUUID).replace(':udid', udid); return this.http.get(url, this.localDataService.getAccessToken()); } update(udid: string, deviceName: string, failedAttempts: number) { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); var url = self.basePath + this.updateUrl.replace(':applicationUUID', applicationUUID); return this.http.post(url, {udid: udid, deviceName: deviceName, failedAttempts: failedAttempts}, this.localDataService.getAccessToken()); } changelockstatus(udid: string) { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); var url = self.basePath + this.changelockstatusUrl.replace(':applicationUUID', applicationUUID).replace(':udid', udid); return this.http.post(url, null, this.localDataService.getAccessToken()); } delete(udid: string) { let self : any = this; let applicationUUID = self.localDataService.getApplicationUuid(); var url = self.basePath + this.deleteUrl.replace(':applicationUUID', applicationUUID).replace(':udid', udid); return this.http.delete(url, this.localDataService.getAccessToken()); } }