-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |