From c4e6187fe86beb2891561c33daecc1b2735a1990 Mon Sep 17 00:00:00 2001 From: Melania Dello Spedale La Paglia Date: Thu, 26 Mar 2020 17:18:54 +0100 Subject: [PATCH] FE: aggiunte API per i devices #11 --- frontend/interfaces/device.tsx | 9 ++++ frontend/src/api/deviceApi.tsx | 77 ++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 frontend/interfaces/device.tsx create mode 100644 frontend/src/api/deviceApi.tsx diff --git a/frontend/interfaces/device.tsx b/frontend/interfaces/device.tsx new file mode 100644 index 0000000..5ffbe48 --- /dev/null +++ b/frontend/interfaces/device.tsx @@ -0,0 +1,9 @@ +export interface IDevice { + id?: number; + dns_name_auto?: string; + dns_name_manual?: string; + is_gw?: boolean; + gw_id?: number; + mac_address?: string; + tenant_id: number; +} diff --git a/frontend/src/api/deviceApi.tsx b/frontend/src/api/deviceApi.tsx new file mode 100644 index 0000000..6cb3f45 --- /dev/null +++ b/frontend/src/api/deviceApi.tsx @@ -0,0 +1,77 @@ +import * as _ from 'lodash'; +import api from './api'; +import BBPromise from 'bluebird'; +import { IPaginationOpts } from '../../interfaces/rest'; +import { IDevice } from '../../interfaces/device'; + +class DevicesApi extends api { + + create(device: IDevice) { + return new BBPromise((resolve, reject) => { + const url = '/api/private/device/create'; + let params = device; + this.getClient(axiosClient => { + axiosClient.post(url, { params }) + .then((data) => { + resolve(data); + }).catch((error) => { + resolve(error); + }); + }, null, false); + }); + } + + update(device: IDevice) { + return new BBPromise((resolve, reject) => { + const url = '/api/private/device/update'; + let params = device; + this.getClient(axiosClient => { + axiosClient.put(url, params) + .then((data) => { + resolve(data); + }).catch((error) => { + resolve(error); + }); + }, null, false); + }); + } + + getAll(options?: IPaginationOpts, search?: string) { + return new BBPromise((resolve, reject) => { + const url = '/api/private/device/getAll'; + let params: any = {}; + if (options) { + params = { options }; + } + if (search) { + params.search = search + } + this.getClient(axiosClient => { + axiosClient.get(url, { params }) + .then((data) => { + resolve(data); + }).catch((error) => { + resolve(error); + }); + }, null, false); + }); + } + + async delete(tenant_id: number): BBPromise { + return new BBPromise((resolve, reject) => { + const url = '/api/private/device/delete'; + const params = { id: tenant_id }; + this.getClient(axiosClient => { + axiosClient.delete(url, { params }) + .then((data) => { + resolve(data); + }).catch((error) => { + resolve(error); + }); + }); + }); + } +} + +const treatmentsApi = new DevicesApi(); +export default treatmentsApi;