| 30 | import { HandleError } from "./helpers"; |
| 31 | |
| 32 | class DeviceProfileStore extends EventEmitter { |
| 33 | client: DeviceProfileServiceClient; |
| 34 | |
| 35 | constructor() { |
| 36 | super(); |
| 37 | this.client = new DeviceProfileServiceClient(""); |
| 38 | } |
| 39 | |
| 40 | create = (req: CreateDeviceProfileRequest, callbackFunc: (resp: CreateDeviceProfileResponse) => void) => { |
| 41 | this.client.create(req, SessionStore.getMetadata(), (err, resp) => { |
| 42 | if (err !== null) { |
| 43 | HandleError(err); |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | notification.success({ |
| 48 | message: "Device profile created", |
| 49 | duration: 3, |
| 50 | }); |
| 51 | |
| 52 | callbackFunc(resp); |
| 53 | }); |
| 54 | }; |
| 55 | |
| 56 | get = (req: GetDeviceProfileRequest, callbackFunc: (resp: GetDeviceProfileResponse) => void) => { |
| 57 | this.client.get(req, SessionStore.getMetadata(), (err, resp) => { |
| 58 | if (err !== null) { |
| 59 | HandleError(err); |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | callbackFunc(resp); |
| 64 | }); |
| 65 | }; |
| 66 | |
| 67 | getByProfileId = ( |
| 68 | req: GetDeviceProfileByProfileIdRequest, |
| 69 | callbackFunc: (resp: GetDeviceProfileByProfileIdResponse) => void, |
| 70 | ) => { |
| 71 | this.client.getByProfileId(req, SessionStore.getMetadata(), (err, resp) => { |
| 72 | if (err !== null) { |
| 73 | HandleError(err); |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | callbackFunc(resp); |
| 78 | }); |
| 79 | }; |
| 80 | |
| 81 | update = (req: UpdateDeviceProfileRequest, callbackFunc: () => void) => { |
| 82 | this.client.update(req, SessionStore.getMetadata(), err => { |
| 83 | if (err !== null) { |
| 84 | HandleError(err); |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | notification.success({ |
| 89 | message: "Device profile updated", |