Skip to content

Commit

Permalink
FE: aggiunte API per i devices #11
Browse files Browse the repository at this point in the history
  • Loading branch information
mdslp committed Mar 26, 2020
1 parent 5e2c372 commit c4e6187
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
9 changes: 9 additions & 0 deletions frontend/interfaces/device.tsx
Original file line number Diff line number Diff line change
@@ -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;
}
77 changes: 77 additions & 0 deletions frontend/src/api/deviceApi.tsx
Original file line number Diff line number Diff line change
@@ -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<any> {
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;

0 comments on commit c4e6187

Please sign in to comment.