dt-common-device 3.0.10 → 3.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/dist/config/config.d.ts +1 -2
  2. package/dist/config/config.js +4 -5
  3. package/dist/device/local/repository/Schedule.repository.d.ts +0 -1
  4. package/dist/device/local/repository/Schedule.repository.js +6 -6
  5. package/dist/queue/entities/HybridHttpQueue.d.ts +4 -14
  6. package/dist/queue/entities/HybridHttpQueue.js +31 -119
  7. package/dist/queue/interfaces/IHybridHttpQueue.d.ts +2 -12
  8. package/dist/queue/interfaces/IJobResult.d.ts +1 -8
  9. package/dist/queue/interfaces/index.d.ts +0 -1
  10. package/dist/queue/interfaces/index.js +0 -1
  11. package/dist/queue/services/QueueService.d.ts +2 -12
  12. package/dist/queue/types/queue.types.d.ts +10 -29
  13. package/dist/queue/utils/jobUtils.d.ts +0 -3
  14. package/dist/queue/utils/jobUtils.js +0 -48
  15. package/dist/queue/utils/queueUtils.d.ts +7 -0
  16. package/dist/queue/utils/queueUtils.js +113 -4
  17. package/package.json +6 -1
  18. package/.eslintrc.js +0 -44
  19. package/src/alerts/Alert.model.ts +0 -289
  20. package/src/alerts/Alert.repository.ts +0 -487
  21. package/src/alerts/Alert.service.ts +0 -711
  22. package/src/alerts/AlertBuilder.example.ts +0 -126
  23. package/src/alerts/AlertBuilder.ts +0 -208
  24. package/src/alerts/AlertService.example.ts +0 -232
  25. package/src/alerts/alert.types.ts +0 -64
  26. package/src/alerts/index.ts +0 -3
  27. package/src/config/config.ts +0 -202
  28. package/src/config/config.types.ts +0 -21
  29. package/src/connection/Connection.repository.ts +0 -52
  30. package/src/connection/Connection.service.ts +0 -39
  31. package/src/connection/IConnection.ts +0 -27
  32. package/src/connection/index.ts +0 -3
  33. package/src/constants/ConnectionProviders.ts +0 -11
  34. package/src/constants/Event.ts +0 -89
  35. package/src/constants/Service.ts +0 -17
  36. package/src/constants/index.ts +0 -3
  37. package/src/db/db.ts +0 -24
  38. package/src/db/index.ts +0 -2
  39. package/src/db/redis.ts +0 -20
  40. package/src/device/cloud/entities/CloudDevice.ts +0 -40
  41. package/src/device/cloud/entities/CloudDeviceService.ts +0 -8
  42. package/src/device/cloud/entities/DeviceFactory.ts +0 -27
  43. package/src/device/cloud/entities/index.ts +0 -3
  44. package/src/device/cloud/interfaces/ICloudDevice.ts +0 -14
  45. package/src/device/cloud/interfaces/ICloudDeviceService.ts +0 -6
  46. package/src/device/cloud/interfaces/IDeviceFactory.ts +0 -5
  47. package/src/device/cloud/interfaces/IRawDataTransformer.ts +0 -5
  48. package/src/device/cloud/interfaces/IRawDevice.ts +0 -19
  49. package/src/device/cloud/interfaces/index.ts +0 -5
  50. package/src/device/local/interfaces/IDevice.ts +0 -62
  51. package/src/device/local/interfaces/IDtDevice.ts +0 -16
  52. package/src/device/local/interfaces/ISchedule.ts +0 -40
  53. package/src/device/local/interfaces/index.ts +0 -3
  54. package/src/device/local/repository/Device.repository.ts +0 -368
  55. package/src/device/local/repository/Hub.repository.ts +0 -107
  56. package/src/device/local/repository/Schedule.repository.ts +0 -72
  57. package/src/device/local/services/Device.service.ts +0 -436
  58. package/src/device/local/services/Hub.service.ts +0 -57
  59. package/src/device/local/services/Schedule.service.ts +0 -26
  60. package/src/device/local/services/index.ts +0 -3
  61. package/src/docs/Alert.model.md +0 -319
  62. package/src/docs/Alerts&IssuesModel.md +0 -312
  63. package/src/docs/Issue.model.md +0 -386
  64. package/src/docs/SECURITY.md +0 -67
  65. package/src/docs/TROUBLESHOOTING.md +0 -184
  66. package/src/events/BaseEventHandler.ts +0 -145
  67. package/src/events/BaseEventTransformer.ts +0 -97
  68. package/src/events/DeviceEventHandler.ts +0 -213
  69. package/src/events/DeviceEventTransformerFactory.ts +0 -77
  70. package/src/events/EventHandler.ts +0 -124
  71. package/src/events/EventHandlerOrchestrator.ts +0 -119
  72. package/src/events/EventProcessingService.ts +0 -248
  73. package/src/events/InternalEventSubscription.ts +0 -194
  74. package/src/events/index.ts +0 -9
  75. package/src/events/interfaces/DeviceEvent.ts +0 -56
  76. package/src/events/interfaces/IEventHandler.ts +0 -28
  77. package/src/events/interfaces/IEventTransformer.ts +0 -8
  78. package/src/events/interfaces/IInternalEvent.ts +0 -33
  79. package/src/events/interfaces/index.ts +0 -4
  80. package/src/index.ts +0 -43
  81. package/src/issues/Issue.model.ts +0 -350
  82. package/src/issues/Issue.repository.ts +0 -517
  83. package/src/issues/Issue.service.ts +0 -932
  84. package/src/issues/IssueBuilder.example.ts +0 -210
  85. package/src/issues/IssueBuilder.ts +0 -263
  86. package/src/issues/IssueService.example.ts +0 -310
  87. package/src/issues/index.ts +0 -2
  88. package/src/issues/issue.types.ts +0 -98
  89. package/src/property/IProperty.ts +0 -30
  90. package/src/property/Property.repository.ts +0 -53
  91. package/src/property/Property.service.ts +0 -38
  92. package/src/property/index.ts +0 -2
  93. package/src/queue/entities/HybridHttpQueue.ts +0 -274
  94. package/src/queue/entities/index.ts +0 -1
  95. package/src/queue/index.ts +0 -6
  96. package/src/queue/interfaces/IHttpRequestJob.ts +0 -10
  97. package/src/queue/interfaces/IHybridHttpQueue.ts +0 -25
  98. package/src/queue/interfaces/IJobResult.ts +0 -15
  99. package/src/queue/interfaces/IRateLimitConfig.ts +0 -5
  100. package/src/queue/interfaces/index.ts +0 -4
  101. package/src/queue/services/QueueService.ts +0 -40
  102. package/src/queue/services/index.ts +0 -1
  103. package/src/queue/types/http.types.ts +0 -23
  104. package/src/queue/types/index.ts +0 -2
  105. package/src/queue/types/queue.types.ts +0 -21
  106. package/src/queue/utils/index.ts +0 -3
  107. package/src/queue/utils/jobUtils.ts +0 -79
  108. package/src/queue/utils/queueUtils.ts +0 -84
  109. package/src/queue/utils/rateLimit.utils.ts +0 -131
  110. package/src/utils/http.utils.ts +0 -143
  111. package/src/utils/index.ts +0 -2
  112. package/src/utils/redis.utils.ts +0 -74
  113. package/tsconfig.json +0 -20
@@ -1,62 +0,0 @@
1
- // Interfaces for DeviceService methods
2
-
3
- export interface IDevice {
4
- deviceId: string;
5
- propertyId: string;
6
- zoneId: string;
7
- name: string;
8
- hubId: string[];
9
- specifications: {
10
- manufacturer?: string;
11
- model?: string;
12
- firmware?: {
13
- version?: string;
14
- newVersionAvailable?: boolean;
15
- newVersion?: string;
16
- mandatoryUpdate?: boolean;
17
- };
18
- };
19
- protocol: {
20
- location?: {
21
- id?: string;
22
- name?: string;
23
- city?: string;
24
- };
25
- name?: string;
26
- room?: {
27
- id?: string;
28
- name?: string;
29
- };
30
- accountId?: string;
31
- };
32
- connection: {
33
- id: string;
34
- name: string;
35
- };
36
- deviceType: {
37
- id: string;
38
- type: string;
39
- };
40
- status: IStatus;
41
- isActive: {
42
- value: boolean;
43
- lastUpdated: string;
44
- };
45
- state?: Record<string, any>;
46
- metaData?: Record<string, any>;
47
- createdAt?: Date;
48
- updatedAt?: Date;
49
- hubDeviceDetails?: IDevice[];
50
- capabilities?: Record<string, any>;
51
- }
52
-
53
- export class IStatus {
54
- online: boolean = false;
55
- liveStatus?: "ONLINE" | "OFFLINE";
56
- error?: {
57
- type?: string;
58
- message?: string;
59
- default?: object;
60
- };
61
- lastUpdated?: string;
62
- }
@@ -1,16 +0,0 @@
1
- export interface IDtDevice {
2
- id: string;
3
- name: string;
4
- type: string;
5
- zoneId: string;
6
- deviceType: string;
7
- deviceId: string;
8
- deviceNetworkId: string;
9
- propertyId: string;
10
- connectionId: string;
11
- hubId: string;
12
- isBatteryLowAlertSent: boolean;
13
- createdAt: string;
14
- updatedAt: string;
15
- isActive: boolean;
16
- }
@@ -1,40 +0,0 @@
1
- export interface ISchedule {
2
- id?: string;
3
- name: string;
4
- deviceId: string;
5
- scheduleId: string | null; // generated from cloud api, optional
6
- state: {
7
- targetTemperature?: number;
8
- temperatureUnit?: "C" | "F";
9
- mode?: "cool" | "heat" | "fan" | "dry" | "auto";
10
- swing?:
11
- | "stopped"
12
- | "rangeFull"
13
- | "fixedTop"
14
- | "fixedMiddleTop"
15
- | "fixedMiddle"
16
- | "fixedMiddleBottom"
17
- | "fixedBottom";
18
- fanLevel?: "auto" | "low" | "medium" | "high";
19
- };
20
- startTime: string; // ISO date string
21
- endTime: string; // ISO date string
22
- recurringDays: (
23
- | "Monday"
24
- | "Tuesday"
25
- | "Wednesday"
26
- | "Thursday"
27
- | "Friday"
28
- | "Saturday"
29
- | "Sunday"
30
- )[];
31
- createTime?: string; // ISO date string, optional
32
- nextTime?: string; // ISO date string, optional
33
- nextTimeSecondsFromNow?: number;
34
- targetTimeLocal: string; // ISO date string
35
- timezone: string;
36
- scheduleInheritedFrom: "zone" | "device";
37
- zoneId: string;
38
- userId: string;
39
- status?: "SET" | "UNSET";
40
- }
@@ -1,3 +0,0 @@
1
- export * from "./IDevice";
2
- export * from "./IDtDevice";
3
- export * from "./ISchedule";
@@ -1,368 +0,0 @@
1
- import { IDevice, IStatus } from "../interfaces/IDevice";
2
- import { getConfig } from "../../../config/config";
3
- import { getPostgresClient } from "../../../db";
4
- import { Service } from "typedi";
5
- import { IDtDevice } from "../interfaces/IDtDevice";
6
- import { getDeviceServiceAxiosInstance } from "../../../utils/http.utils";
7
-
8
- @Service()
9
- export class DeviceRepository {
10
- private readonly postgres;
11
- private readonly axiosInstance;
12
-
13
- constructor() {
14
- this.postgres = getPostgresClient();
15
- this.axiosInstance = getDeviceServiceAxiosInstance();
16
- }
17
-
18
- async createDevice(body: IDevice): Promise<IDevice> {
19
- try {
20
- const response = await this.axiosInstance.post(`/devices`, body);
21
- return response.data;
22
- } catch (error: any) {
23
- getConfig().LOGGER.error("Failed to create device:", error);
24
- throw new Error(
25
- `Failed to create device: ${error.message || "Unknown error"}`
26
- );
27
- }
28
- }
29
-
30
- async getDevice(
31
- deviceId: string,
32
- withHubDetails: boolean = false
33
- ): Promise<IDevice> {
34
- try {
35
- const response = await this.axiosInstance.get(
36
- `/devices/${deviceId}?withHubDetails=${withHubDetails} `
37
- );
38
- return response.data;
39
- } catch (error: any) {
40
- getConfig().LOGGER.error(`Failed to get device ${deviceId}:`, error);
41
- throw new Error(
42
- `Failed to get device: ${error.message || "Unknown error"}`
43
- );
44
- }
45
- }
46
-
47
- async updateDevice(deviceId: string, body: any): Promise<IDevice> {
48
- try {
49
- const response = await this.axiosInstance.put(
50
- `/devices/${deviceId}`,
51
- body
52
- );
53
- return response.data;
54
- } catch (error: any) {
55
- getConfig().LOGGER.error(`Failed to update device ${deviceId}:`, error);
56
- throw new Error(
57
- `Failed to update device: ${error.message || "Unknown error"}`
58
- );
59
- }
60
- }
61
-
62
- async deleteDevice(deviceId: string): Promise<void> {
63
- try {
64
- await this.axiosInstance.delete(`/devices/${deviceId}`);
65
- } catch (error: any) {
66
- getConfig().LOGGER.error(`Failed to delete device ${deviceId}:`, error);
67
- throw new Error(
68
- `Failed to delete device: ${error.message || "Unknown error"}`
69
- );
70
- }
71
- }
72
-
73
- async getDevices(
74
- deviceIds: string[],
75
- withHubDetails: boolean = false
76
- ): Promise<IDevice[]> {
77
- try {
78
- const response = await this.axiosInstance.get(`/devices`, {
79
- params: { deviceIds, withHubDetails },
80
- });
81
- return response.data;
82
- } catch (error: any) {
83
- getConfig().LOGGER.error("Failed to get devices:", error);
84
- throw new Error(
85
- `Failed to get devices: ${error.message || "Unknown error"}`
86
- );
87
- }
88
- }
89
-
90
- async getPropertyDevices(
91
- propertyId: string,
92
- selectDeviceId: boolean = false,
93
- type?: string,
94
- withHubDetails: boolean = false
95
- ): Promise<IDevice[]> {
96
- try {
97
- const response = await this.axiosInstance.get(`/devices`, {
98
- params: { propertyId, selectDeviceId, type, withHubDetails },
99
- });
100
- return response.data;
101
- } catch (error: any) {
102
- getConfig().LOGGER.error(
103
- `Failed to get property devices for ${propertyId}:`,
104
- error
105
- );
106
- throw new Error(
107
- `Failed to get property devices: ${error.message || "Unknown error"}`
108
- );
109
- }
110
- }
111
-
112
- async getPropertyDeviceIds(
113
- propertyId: string,
114
- selectDeviceId: boolean = false,
115
- manufacturer: string
116
- ) {
117
- try {
118
- const response = await this.axiosInstance.get(`/devices`, {
119
- params: { propertyId, selectDeviceId, manufacturer },
120
- });
121
- return response.data;
122
- } catch (error: any) {
123
- getConfig().LOGGER.error(
124
- `Failed to get property device IDs for ${propertyId}:`,
125
- error
126
- );
127
- throw new Error(
128
- `Failed to get property device IDs: ${error.message || "Unknown error"}`
129
- );
130
- }
131
- }
132
-
133
- async getState(deviceId: string): Promise<any> {
134
- try {
135
- const response = await this.axiosInstance.get(
136
- `/devices/${deviceId}/state`
137
- );
138
- return response.data;
139
- } catch (error: any) {
140
- getConfig().LOGGER.error(
141
- `Failed to get device state for ${deviceId}:`,
142
- error
143
- );
144
- throw new Error(
145
- `Failed to get device state: ${error.message || "Unknown error"}`
146
- );
147
- }
148
- }
149
-
150
- async setState(deviceId: string, state: any): Promise<any> {
151
- try {
152
- const response = await this.axiosInstance.put(
153
- `/devices/${deviceId}/state`,
154
- state
155
- );
156
- return response.data;
157
- } catch (error: any) {
158
- getConfig().LOGGER.error(
159
- `Failed to set device state for ${deviceId}:`,
160
- error
161
- );
162
- throw new Error(
163
- `Failed to set device state: ${error.message || "Unknown error"}`
164
- );
165
- }
166
- }
167
-
168
- async getStatus(deviceId: string): Promise<Record<string, any>> {
169
- try {
170
- const response = await this.axiosInstance.get(
171
- `/devices/${deviceId}/status`
172
- );
173
- return response.data;
174
- } catch (error: any) {
175
- getConfig().LOGGER.error(
176
- `Failed to get device status for ${deviceId}:`,
177
- error
178
- );
179
- throw new Error(
180
- `Failed to get device status: ${error.message || "Unknown error"}`
181
- );
182
- }
183
- }
184
-
185
- async setStatus(deviceId: string, newStatus: IStatus) {
186
- try {
187
- const response = await this.axiosInstance.put(
188
- `/devices/${deviceId}/status`,
189
- newStatus
190
- );
191
- return response.data;
192
- } catch (error: any) {
193
- getConfig().LOGGER.error(
194
- `Failed to set device status for ${deviceId}:`,
195
- error
196
- );
197
- throw new Error(
198
- `Failed to set device status: ${error.message || "Unknown error"}`
199
- );
200
- }
201
- }
202
-
203
- async getBatteryLevel(deviceId: string): Promise<Record<string, any>> {
204
- try {
205
- const response = await this.axiosInstance.get(
206
- `/devices/${deviceId}/battery-level`
207
- );
208
- return response.data;
209
- } catch (error: any) {
210
- getConfig().LOGGER.error(
211
- `Failed to get battery level for ${deviceId}:`,
212
- error
213
- );
214
- throw new Error(
215
- `Failed to get battery level: ${error.message || "Unknown error"}`
216
- );
217
- }
218
- }
219
-
220
- async setBatteryLevel(deviceId: string, newBatteryLevel: any) {
221
- try {
222
- const response = await this.axiosInstance.put(
223
- `/devices/${deviceId}/battery-level`,
224
- { newBatteryLevel }
225
- );
226
- return response.data;
227
- } catch (error: any) {
228
- getConfig().LOGGER.error(
229
- `Failed to set battery level for ${deviceId}:`,
230
- error
231
- );
232
- throw new Error(
233
- `Failed to set battery level: ${error.message || "Unknown error"}`
234
- );
235
- }
236
- }
237
-
238
- async getMetaData(deviceId: string): Promise<any> {
239
- try {
240
- const response = await this.axiosInstance.get(
241
- `/devices/${deviceId}/metaData`
242
- );
243
- return response.data;
244
- } catch (error: any) {
245
- getConfig().LOGGER.error(
246
- `Failed to get metadata for ${deviceId}:`,
247
- error
248
- );
249
- throw new Error(
250
- `Failed to get metadata: ${error.message || "Unknown error"}`
251
- );
252
- }
253
- }
254
-
255
- async setMetaData(deviceId: string, metaData: Record<string, any>) {
256
- try {
257
- const response = await this.axiosInstance.put(
258
- `/devices/${deviceId}/metaData`,
259
- metaData
260
- );
261
- return response.data;
262
- } catch (error: any) {
263
- getConfig().LOGGER.error(
264
- `Failed to set metadata for ${deviceId}:`,
265
- error
266
- );
267
- throw new Error(
268
- `Failed to set metadata: ${error.message || "Unknown error"}`
269
- );
270
- }
271
- }
272
-
273
- async getDevicesByAccessGroup(accessGroupId: string): Promise<IDtDevice[]> {
274
- try {
275
- const result = await this.postgres.query(
276
- `SELECT d.* FROM dt_devices d
277
- INNER JOIN dt_zones_collection_map zcm ON d.zoneId = zcm.zoneId
278
- WHERE zcm.collectionId = $1`,
279
- [accessGroupId]
280
- );
281
-
282
- if (result.rows.length > 0) {
283
- return result.rows;
284
- }
285
- return [];
286
- } catch (error) {
287
- getConfig().LOGGER.error(
288
- `Failed to get devices by access group ${accessGroupId}:`,
289
- error
290
- );
291
- throw new Error("Failed to get devices by access group");
292
- }
293
- }
294
-
295
- async getDevicesByZone(zoneId: string): Promise<IDtDevice[]> {
296
- try {
297
- const result = await this.postgres.query(
298
- "SELECT * FROM dt_devices WHERE zoneId = $1",
299
- [zoneId]
300
- );
301
- if (result.rows.length > 0) {
302
- return result.rows;
303
- }
304
- return [];
305
- } catch (error) {
306
- getConfig().LOGGER.error(
307
- `Failed to get devices by zone ${zoneId}:`,
308
- error
309
- );
310
- throw new Error("Failed to get device by zone");
311
- }
312
- }
313
-
314
- async querySelect(query: any, fields: string[]) {
315
- try {
316
- const response = await this.axiosInstance.post(`/devices/select`, {
317
- query,
318
- fields,
319
- });
320
- return response.data;
321
- } catch (error: any) {
322
- getConfig().LOGGER.error("Failed to query select devices:", error);
323
- throw new Error(
324
- `Failed to query select devices: ${error.message || "Unknown error"}`
325
- );
326
- }
327
- }
328
-
329
- //remove - use existing query function
330
- async queryCount(query: any): Promise<number> {
331
- try {
332
- const response = await this.axiosInstance.post(`/devices/count`, query);
333
- return response.data;
334
- } catch (error: any) {
335
- getConfig().LOGGER.error("Failed to query count devices:", error);
336
- throw new Error(
337
- `Failed to query count devices: ${error.message || "Unknown error"}`
338
- );
339
- }
340
- }
341
-
342
- async deleteDevices(query: any) {
343
- try {
344
- const response = await this.axiosInstance.post(
345
- `/devices/deleteMany`,
346
- query
347
- );
348
- return response.data;
349
- } catch (error: any) {
350
- getConfig().LOGGER.error("Failed to delete devices:", error);
351
- throw new Error(
352
- `Failed to delete devices: ${error.message || "Unknown error"}`
353
- );
354
- }
355
- }
356
-
357
- async queryDevices(query: any) {
358
- try {
359
- const response = await this.axiosInstance.post(`/devices/query`, query);
360
- return response.data;
361
- } catch (error: any) {
362
- getConfig().LOGGER.error("Failed to query devices:", error);
363
- throw new Error(
364
- `Failed to query devices: ${error.message || "Unknown error"}`
365
- );
366
- }
367
- }
368
- }
@@ -1,107 +0,0 @@
1
- import { getConfig } from "../../../config/config";
2
- import { getPostgresClient } from "../../../db";
3
- import { Service } from "typedi";
4
- import { IDevice } from "../interfaces";
5
- import { getDeviceServiceAxiosInstance } from "../../../utils/http.utils";
6
-
7
- @Service()
8
- export class HubRepository {
9
- private readonly postgres;
10
- private readonly axiosInstance;
11
-
12
- constructor() {
13
- this.postgres = getPostgresClient();
14
- this.axiosInstance = getDeviceServiceAxiosInstance();
15
- }
16
-
17
- async addHub(body: Partial<IDevice>): Promise<IDevice> {
18
- try {
19
- const response = await this.axiosInstance.post(`/devices/hubs`, body);
20
- return response.data;
21
- } catch (error: any) {
22
- getConfig().LOGGER.error("Failed to add hub:", error);
23
- throw new Error(`Failed to add hub: ${error.message || "Unknown error"}`);
24
- }
25
- }
26
-
27
- async getHubs(hubIds: string[]): Promise<IDevice[]> {
28
- try {
29
- const query = hubIds?.length ? `?ids=${hubIds.join(",")}` : "";
30
- const response = await this.axiosInstance.get(`/devices/hubs${query}`);
31
- return response.data;
32
- } catch (error: any) {
33
- getConfig().LOGGER.error("Failed to get hubs:", error);
34
- throw new Error(
35
- `Failed to get hubs: ${error.message || "Unknown error"}`
36
- );
37
- }
38
- }
39
-
40
- async getHub(hubId: string): Promise<IDevice> {
41
- try {
42
- const response = await this.axiosInstance.get(`/devices/hubs/${hubId}`);
43
- return response.data;
44
- } catch (error: any) {
45
- getConfig().LOGGER.error(`Failed to get hub ${hubId}:`, error);
46
- throw new Error(
47
- `Failed to get hub ${hubId}: ${error.message || "Unknown error"}`
48
- );
49
- }
50
- }
51
-
52
- async updateHub(hubId: string, body: any): Promise<IDevice> {
53
- try {
54
- const response = await this.axiosInstance.put(
55
- `/devices/hubs/${hubId}`,
56
- body
57
- );
58
- return response.data;
59
- } catch (error: any) {
60
- getConfig().LOGGER.error(`Failed to update hub ${hubId}:`, error);
61
- throw new Error(
62
- `Failed to update hub ${hubId}: ${error.message || "Unknown error"}`
63
- );
64
- }
65
- }
66
-
67
- async getStatus(hubId: string): Promise<"ONLINE" | "OFFLINE" | "UNKNOWN"> {
68
- try {
69
- const response = await this.axiosInstance.get(
70
- `/devices/hubs/${hubId}/status`
71
- );
72
- return response.data;
73
- } catch (error: any) {
74
- getConfig().LOGGER.error(`Failed to get hub status ${hubId}:`, error);
75
- throw new Error(
76
- `Failed to get hub status ${hubId}: ${error.message || "Unknown error"}`
77
- );
78
- }
79
- }
80
-
81
- async deleteHub(hubId: string): Promise<any> {
82
- try {
83
- const response = await this.axiosInstance.delete(
84
- `/devices/hubs/${hubId}`
85
- );
86
- return response.data;
87
- } catch (error: any) {
88
- getConfig().LOGGER.error(`Failed to delete hub ${hubId}:`, error);
89
- throw new Error(
90
- `Failed to delete hub ${hubId}: ${error.message || "Unknown error"}`
91
- );
92
- }
93
- }
94
-
95
- async deleteAllHubs(hubIds: string[]): Promise<any> {
96
- try {
97
- const query = hubIds.length ? `?ids=${hubIds.join(",")}` : "";
98
- const response = await this.axiosInstance.delete(`/devices/hubs${query}`);
99
- return response.data;
100
- } catch (error: any) {
101
- getConfig().LOGGER.error("Failed to delete all hubs:", error);
102
- throw new Error(
103
- `Failed to delete all hubs: ${error.message || "Unknown error"}`
104
- );
105
- }
106
- }
107
- }
@@ -1,72 +0,0 @@
1
- import { Service } from "typedi";
2
- import { getLogger } from "../../../config/config";
3
- import { ISchedule } from "../interfaces/ISchedule";
4
- import { getDeviceServiceAxiosInstance } from "../../../utils/http.utils";
5
-
6
- @Service()
7
- export class ScheduleRepository {
8
- private readonly axiosInstance;
9
- private readonly logger = getLogger();
10
-
11
- constructor() {
12
- this.axiosInstance = getDeviceServiceAxiosInstance();
13
- }
14
-
15
- async getSchedule(scheduleId: string) {
16
- try {
17
- const response = await this.axiosInstance.get(
18
- `/devices/schedule?id=${scheduleId}`
19
- );
20
- return response.data;
21
- } catch (error: any) {
22
- this.logger.error(`Failed to get schedule ${scheduleId}:`, error);
23
- const errorMessage =
24
- error.response?.data?.message || error.message || "Unknown error";
25
- throw new Error(`Failed to get schedule: ${errorMessage}`);
26
- }
27
- }
28
-
29
- async getScheduleByZone(zoneId: string) {
30
- try {
31
- const response = await this.axiosInstance.get(
32
- `/devices/schedules?zoneId=${zoneId}`
33
- );
34
- return response.data;
35
- } catch (error: any) {
36
- this.logger.error(`Failed to get schedule by zone ${zoneId}:`, error);
37
- const errorMessage =
38
- error.response?.data?.message || error.message || "Unknown error";
39
- throw new Error(`Failed to get schedule: ${errorMessage}`);
40
- }
41
- }
42
-
43
- async setSchedule(scheduleId: string, schedule: ISchedule) {
44
- try {
45
- const response = await this.axiosInstance.put(
46
- `/devices/schedules/${scheduleId}`,
47
- schedule
48
- );
49
- return response.data;
50
- } catch (error: any) {
51
- this.logger.error(`Failed to update schedule ${scheduleId}:`, error);
52
- const errorMessage =
53
- error.response?.data?.message || error.message || "Unknown error";
54
- throw new Error(`Failed to update schedule: ${errorMessage}`);
55
- }
56
- }
57
-
58
- async deleteSchedule(scheduleId: string) {
59
- try {
60
- const response = await this.axiosInstance.delete(
61
- `/devices/schedules/${scheduleId}`
62
- );
63
- return response.data;
64
- } catch (error: any) {
65
- this.logger.error(
66
- `Failed to delete schedule from DB ${scheduleId}:`,
67
- error
68
- );
69
- throw new Error(`Failed to delete schedule from DB: ${error.message}`);
70
- }
71
- }
72
- }