@Injectable()
export class DeviceService {
+ private getDeviceUrl = SERVER_URL + '/device';
private getAllDevicesUrl = SERVER_URL + '/devices';
private updateDevicesUrl = SERVER_URL + '/devices/update';
);
}
+ getDevice(id: number): Observable<Device> {
+ const url = `${this.getDeviceUrl}?id=${id}`;
+
+ return this.http.get<Device>(url).pipe(
+ tap(
+ ok => this.logger.info(`Got device`),
+ error => this.logger.error(`Get device error`),
+ ),
+ );
+ }
+
updateDevices(updateDevices: UpdateDevice[]): Observable<Device[]> {
const updates = new UpdateDevices(updateDevices);
--- /dev/null
+import { Injectable } from '@angular/core';
+import { HttpClient } from '@angular/common/http';
+import { Observable } from 'rxjs/Observable';
+import { tap } from 'rxjs/operators';
+import { UpdatedDevicePolicies, PolicyGroup } from '../models';
+import { SERVER_URL } from '../../../config';
+import { NGXLogger } from 'ngx-logger';
+
+@Injectable()
+export class PolicyService {
+ private getDefaultPoliciesUrl = SERVER_URL + '/policies';
+ private getDevicePoliciesUrl = SERVER_URL + '/policies/device';
+ private setDevicePoliciesUrl = SERVER_URL + '/policies/device';
+
+ constructor(private http: HttpClient, private logger: NGXLogger) { }
+
+ getDefaultPolicies(): Observable<PolicyGroup[]> {
+ return this.http.get<PolicyGroup[]>(this.getDefaultPoliciesUrl).pipe(
+ tap(
+ ok => this.logger.info('Got default device policies'),
+ error => this.logger.error('Get default device policies error'),
+ ),
+ );
+ }
+
+ getDevicePolicies(deviceId: number): Observable<PolicyGroup[]> {
+ const url = `${this.getDevicePoliciesUrl}?id=${deviceId}`;
+
+ return this.http.get<PolicyGroup[]>(url).pipe(
+ tap(
+ ok => this.logger.info('Got device policies'),
+ error => this.logger.error('Get device policies error'),
+ ),
+ );
+ }
+
+ setDevicePolicies(deviceId: number, updatedPolicies: UpdatedDevicePolicies): Observable<any> {
+ const url = `${this.setDevicePoliciesUrl}?id=${deviceId}`;
+ this.logger.info(updatedPolicies);
+
+ return this.http.put<any>(url, updatedPolicies).pipe(
+ tap(
+ ok => this.logger.info('Device policies are successfully updated'),
+ error => this.logger.error('Update device policies error'),
+ ),
+ );
+ }
+}