dt-common-device 7.8.14 → 7.9.0

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 (222) hide show
  1. package/dist/audit/AuditUtils.js +172 -100
  2. package/dist/entities/accessGroup/AccessGroup.repository.d.ts +2 -1
  3. package/dist/entities/accessGroup/AccessGroup.repository.js +4 -1
  4. package/dist/entities/accessGroup/AccessGroup.service.d.ts +2 -1
  5. package/dist/entities/accessGroup/AccessGroup.service.js +4 -3
  6. package/dist/entities/device/local/repository/DeviceProfile.repository.d.ts +5 -0
  7. package/dist/{device/cloud/entities/DeviceFactory.js → entities/device/local/repository/DeviceProfile.repository.js} +12 -27
  8. package/dist/entities/device/local/services/Device.service.js +3 -3
  9. package/dist/entities/guest/Guest.repository.d.ts +1 -1
  10. package/dist/entities/guest/Guest.repository.js +5 -2
  11. package/dist/entities/guest/Guest.service.d.ts +1 -1
  12. package/dist/entities/guest/Guest.service.js +4 -1
  13. package/dist/entities/schedules/Schedule.repository.d.ts +1 -1
  14. package/dist/entities/schedules/Schedule.repository.js +5 -2
  15. package/dist/entities/schedules/Schedule.service.d.ts +1 -1
  16. package/dist/entities/schedules/Schedule.service.js +4 -1
  17. package/dist/entities/user/User.repository.js +4 -1
  18. package/dist/entities/user/User.service.d.ts +1 -1
  19. package/dist/entities/user/User.service.js +4 -1
  20. package/dist/entities/zone/Zone.service.js +4 -1
  21. package/package.json +1 -1
  22. package/dist/admin/Admin.repository.d.ts +0 -7
  23. package/dist/admin/Admin.repository.js +0 -182
  24. package/dist/admin/Admin.service.d.ts +0 -5
  25. package/dist/admin/Admin.service.js +0 -17
  26. package/dist/admin/index.d.ts +0 -1
  27. package/dist/admin/index.js +0 -17
  28. package/dist/audit/AuditProperties.d.ts +0 -16
  29. package/dist/audit/AuditProperties.js +0 -2
  30. package/dist/chronicle/IChronicle.interface.d.ts +0 -14
  31. package/dist/chronicle/IChronicle.interface.js +0 -2
  32. package/dist/chronicle/chronicle.service.d.ts +0 -4
  33. package/dist/chronicle/chronicle.service.js +0 -44
  34. package/dist/connection/Connection.repository.d.ts +0 -8
  35. package/dist/connection/Connection.repository.js +0 -92
  36. package/dist/connection/Connection.service.d.ts +0 -8
  37. package/dist/connection/Connection.service.js +0 -32
  38. package/dist/connection/IConnection.d.ts +0 -28
  39. package/dist/connection/IConnection.js +0 -16
  40. package/dist/connection/index.d.ts +0 -2
  41. package/dist/connection/index.js +0 -18
  42. package/dist/device/cloud/entities/CloudConnection.d.ts +0 -6
  43. package/dist/device/cloud/entities/CloudConnection.js +0 -6
  44. package/dist/device/cloud/entities/CloudDevice.d.ts +0 -16
  45. package/dist/device/cloud/entities/CloudDevice.js +0 -26
  46. package/dist/device/cloud/entities/CloudDeviceService.d.ts +0 -5
  47. package/dist/device/cloud/entities/CloudDeviceService.js +0 -9
  48. package/dist/device/cloud/entities/DeviceFactory.d.ts +0 -7
  49. package/dist/device/cloud/entities/index.d.ts +0 -3
  50. package/dist/device/cloud/entities/index.js +0 -19
  51. package/dist/device/cloud/interface.d.ts +0 -101
  52. package/dist/device/cloud/interface.js +0 -3
  53. package/dist/device/cloud/interfaces/ICloudConnection.d.ts +0 -5
  54. package/dist/device/cloud/interfaces/ICloudConnection.js +0 -2
  55. package/dist/device/cloud/interfaces/ICloudDevice.d.ts +0 -9
  56. package/dist/device/cloud/interfaces/ICloudDevice.js +0 -2
  57. package/dist/device/cloud/interfaces/ICloudDeviceService.d.ts +0 -4
  58. package/dist/device/cloud/interfaces/ICloudDeviceService.js +0 -2
  59. package/dist/device/cloud/interfaces/IConnectionService.d.ts +0 -7
  60. package/dist/device/cloud/interfaces/IConnectionService.js +0 -2
  61. package/dist/device/cloud/interfaces/IDeviceConnectionService.d.ts +0 -7
  62. package/dist/device/cloud/interfaces/IDeviceConnectionService.js +0 -3
  63. package/dist/device/cloud/interfaces/IDeviceFactory.d.ts +0 -4
  64. package/dist/device/cloud/interfaces/IDeviceFactory.js +0 -2
  65. package/dist/device/cloud/interfaces/IDeviceService.d.ts +0 -8
  66. package/dist/device/cloud/interfaces/IDeviceService.js +0 -2
  67. package/dist/device/cloud/interfaces/IDevicesService.d.ts +0 -9
  68. package/dist/device/cloud/interfaces/IDevicesService.js +0 -2
  69. package/dist/device/cloud/interfaces/IHubService.d.ts +0 -5
  70. package/dist/device/cloud/interfaces/IHubService.js +0 -2
  71. package/dist/device/cloud/interfaces/IRawDataTransformer.d.ts +0 -4
  72. package/dist/device/cloud/interfaces/IRawDataTransformer.js +0 -2
  73. package/dist/device/cloud/interfaces/IRawDevice.d.ts +0 -17
  74. package/dist/device/cloud/interfaces/IRawDevice.js +0 -11
  75. package/dist/device/cloud/interfaces/index.d.ts +0 -5
  76. package/dist/device/cloud/interfaces/index.js +0 -21
  77. package/dist/device/cloud/services/CloudDevice.service.d.ts +0 -5
  78. package/dist/device/cloud/services/CloudDevice.service.js +0 -9
  79. package/dist/device/cloud/services/Connection.service.d.ts +0 -8
  80. package/dist/device/cloud/services/Connection.service.js +0 -6
  81. package/dist/device/cloud/services/Device.service.d.ts +0 -39
  82. package/dist/device/cloud/services/Device.service.js +0 -9
  83. package/dist/device/cloud/services/DeviceCloudService.d.ts +0 -42
  84. package/dist/device/cloud/services/DeviceCloudService.js +0 -59
  85. package/dist/device/cloud/services/DeviceHub.service.d.ts +0 -3
  86. package/dist/device/cloud/services/DeviceHub.service.js +0 -6
  87. package/dist/device/cloud/services/Hub.service.d.ts +0 -25
  88. package/dist/device/cloud/services/Hub.service.js +0 -9
  89. package/dist/device/cloud/services/SmartThingsDeviceService.d.ts +0 -38
  90. package/dist/device/cloud/services/SmartThingsDeviceService.js +0 -52
  91. package/dist/device/cloud/services/index.d.ts +0 -2
  92. package/dist/device/cloud/services/index.js +0 -18
  93. package/dist/device/cloud/types.d.ts +0 -52
  94. package/dist/device/cloud/types.js +0 -15
  95. package/dist/device/index.d.ts +0 -4
  96. package/dist/device/index.js +0 -20
  97. package/dist/device/local/entities/AlertBuilder.d.ts +0 -87
  98. package/dist/device/local/entities/AlertBuilder.example.d.ts +0 -11
  99. package/dist/device/local/entities/AlertBuilder.example.js +0 -117
  100. package/dist/device/local/entities/AlertBuilder.js +0 -179
  101. package/dist/device/local/entities/IssueBuilder.d.ts +0 -109
  102. package/dist/device/local/entities/IssueBuilder.example.d.ts +0 -16
  103. package/dist/device/local/entities/IssueBuilder.example.js +0 -196
  104. package/dist/device/local/entities/IssueBuilder.js +0 -237
  105. package/dist/device/local/entities/index.d.ts +0 -2
  106. package/dist/device/local/entities/index.js +0 -7
  107. package/dist/device/local/events/EventHandler.d.ts +0 -11
  108. package/dist/device/local/events/EventHandler.js +0 -86
  109. package/dist/device/local/events/Events.d.ts +0 -54
  110. package/dist/device/local/events/Events.js +0 -57
  111. package/dist/device/local/events/index.d.ts +0 -2
  112. package/dist/device/local/events/index.js +0 -7
  113. package/dist/device/local/handler/EventHandler.d.ts +0 -7
  114. package/dist/device/local/handler/EventHandler.js +0 -44
  115. package/dist/device/local/interface.d.ts +0 -0
  116. package/dist/device/local/interface.js +0 -1
  117. package/dist/device/local/interfaces/IConnection.d.ts +0 -26
  118. package/dist/device/local/interfaces/IConnection.js +0 -14
  119. package/dist/device/local/interfaces/IDevice.d.ts +0 -68
  120. package/dist/device/local/interfaces/IDevice.js +0 -10
  121. package/dist/device/local/interfaces/IDtDevice.d.ts +0 -16
  122. package/dist/device/local/interfaces/IDtDevice.js +0 -2
  123. package/dist/device/local/interfaces/IHub.d.ts +0 -46
  124. package/dist/device/local/interfaces/IHub.js +0 -2
  125. package/dist/device/local/interfaces/IProperty.d.ts +0 -29
  126. package/dist/device/local/interfaces/IProperty.js +0 -2
  127. package/dist/device/local/interfaces/ISchedule.d.ts +0 -25
  128. package/dist/device/local/interfaces/ISchedule.js +0 -2
  129. package/dist/device/local/interfaces/index.d.ts +0 -3
  130. package/dist/device/local/interfaces/index.js +0 -19
  131. package/dist/device/local/models/Alert.model.d.ts +0 -28
  132. package/dist/device/local/models/Alert.model.js +0 -222
  133. package/dist/device/local/models/Issue.model.d.ts +0 -28
  134. package/dist/device/local/models/Issue.model.js +0 -260
  135. package/dist/device/local/repository/Alert.repository.d.ts +0 -106
  136. package/dist/device/local/repository/Alert.repository.js +0 -374
  137. package/dist/device/local/repository/Connection.repository.d.ts +0 -8
  138. package/dist/device/local/repository/Connection.repository.js +0 -92
  139. package/dist/device/local/repository/Device.repository.d.ts +0 -30
  140. package/dist/device/local/repository/Device.repository.js +0 -325
  141. package/dist/device/local/repository/Hub.repository.d.ts +0 -13
  142. package/dist/device/local/repository/Hub.repository.js +0 -139
  143. package/dist/device/local/repository/Issue.repository.d.ts +0 -113
  144. package/dist/device/local/repository/Issue.repository.js +0 -401
  145. package/dist/device/local/repository/Property.repository.d.ts +0 -8
  146. package/dist/device/local/repository/Property.repository.js +0 -95
  147. package/dist/device/local/repository/Schedule.repository.d.ts +0 -9
  148. package/dist/device/local/repository/Schedule.repository.js +0 -109
  149. package/dist/device/local/services/Alert.service.d.ts +0 -137
  150. package/dist/device/local/services/Alert.service.js +0 -475
  151. package/dist/device/local/services/AlertService.example.d.ts +0 -55
  152. package/dist/device/local/services/AlertService.example.js +0 -148
  153. package/dist/device/local/services/Connection.service.d.ts +0 -8
  154. package/dist/device/local/services/Connection.service.js +0 -32
  155. package/dist/device/local/services/Device.service.d.ts +0 -40
  156. package/dist/device/local/services/Device.service.js +0 -391
  157. package/dist/device/local/services/DeviceHub.service.d.ts +0 -11
  158. package/dist/device/local/services/DeviceHub.service.js +0 -40
  159. package/dist/device/local/services/Hub.service.d.ts +0 -12
  160. package/dist/device/local/services/Hub.service.js +0 -107
  161. package/dist/device/local/services/Issue.service.d.ts +0 -168
  162. package/dist/device/local/services/Issue.service.js +0 -642
  163. package/dist/device/local/services/IssueService.example.d.ts +0 -68
  164. package/dist/device/local/services/IssueService.example.js +0 -177
  165. package/dist/device/local/services/Property.service.d.ts +0 -8
  166. package/dist/device/local/services/Property.service.js +0 -36
  167. package/dist/device/local/services/Schedule.service.d.ts +0 -9
  168. package/dist/device/local/services/Schedule.service.js +0 -26
  169. package/dist/device/local/services/index.d.ts +0 -3
  170. package/dist/device/local/services/index.js +0 -19
  171. package/dist/pms/IPms.d.ts +0 -6
  172. package/dist/pms/IPms.js +0 -10
  173. package/dist/pms/index.d.ts +0 -1
  174. package/dist/pms/index.js +0 -18
  175. package/dist/pms/webhookQueue/examples/index.d.ts +0 -2
  176. package/dist/pms/webhookQueue/examples/index.js +0 -18
  177. package/dist/pms/webhookQueue/examples/pms-integration.d.ts +0 -65
  178. package/dist/pms/webhookQueue/examples/pms-integration.js +0 -254
  179. package/dist/pms/webhookQueue/examples/usage.d.ts +0 -7
  180. package/dist/pms/webhookQueue/examples/usage.js +0 -175
  181. package/dist/pms/webhookQueue/index.d.ts +0 -3
  182. package/dist/pms/webhookQueue/index.js +0 -20
  183. package/dist/pms/webhookQueue/interfaces/IWebhookQueue.d.ts +0 -33
  184. package/dist/pms/webhookQueue/interfaces/IWebhookQueue.js +0 -2
  185. package/dist/pms/webhookQueue/interfaces/IWebhookWorker.d.ts +0 -38
  186. package/dist/pms/webhookQueue/interfaces/IWebhookWorker.js +0 -2
  187. package/dist/pms/webhookQueue/interfaces/index.d.ts +0 -1
  188. package/dist/pms/webhookQueue/interfaces/index.js +0 -17
  189. package/dist/pms/webhookQueue/services/WebhookQueueFactory.d.ts +0 -38
  190. package/dist/pms/webhookQueue/services/WebhookQueueFactory.js +0 -131
  191. package/dist/pms/webhookQueue/services/WebhookQueueIntegration.d.ts +0 -70
  192. package/dist/pms/webhookQueue/services/WebhookQueueIntegration.js +0 -207
  193. package/dist/pms/webhookQueue/services/WebhookQueueService.d.ts +0 -45
  194. package/dist/pms/webhookQueue/services/WebhookQueueService.js +0 -270
  195. package/dist/pms/webhookQueue/services/WebhookWorker.d.ts +0 -37
  196. package/dist/pms/webhookQueue/services/WebhookWorker.js +0 -201
  197. package/dist/pms/webhookQueue/services/index.d.ts +0 -1
  198. package/dist/pms/webhookQueue/services/index.js +0 -17
  199. package/dist/pms/webhookQueue/types/index.d.ts +0 -1
  200. package/dist/pms/webhookQueue/types/index.js +0 -17
  201. package/dist/pms/webhookQueue/types/webhook.types.d.ts +0 -39
  202. package/dist/pms/webhookQueue/types/webhook.types.js +0 -2
  203. package/dist/property/IProperty.d.ts +0 -29
  204. package/dist/property/IProperty.js +0 -2
  205. package/dist/property/Property.repository.d.ts +0 -8
  206. package/dist/property/Property.repository.js +0 -109
  207. package/dist/property/Property.service.d.ts +0 -8
  208. package/dist/property/Property.service.js +0 -124
  209. package/dist/property/index.d.ts +0 -2
  210. package/dist/property/index.js +0 -18
  211. package/dist/queue/interfaces/IHttpRequestJob.d.ts +0 -9
  212. package/dist/queue/interfaces/IHttpRequestJob.js +0 -2
  213. package/dist/types/alert.types.d.ts +0 -57
  214. package/dist/types/alert.types.js +0 -22
  215. package/dist/types/config.types.d.ts +0 -19
  216. package/dist/types/config.types.js +0 -2
  217. package/dist/types/index.d.ts +0 -3
  218. package/dist/types/index.js +0 -19
  219. package/dist/types/issue.types.d.ts +0 -90
  220. package/dist/types/issue.types.js +0 -40
  221. package/dist/utils/http-utils.d.ts +0 -13
  222. package/dist/utils/http-utils.js +0 -117
@@ -78,6 +78,7 @@ const services_1 = require("../entities/device/local/services");
78
78
  const typedi_1 = __importStar(require("typedi"));
79
79
  const pms_1 = require("../entities/pms");
80
80
  const admin_1 = require("../entities/admin");
81
+ const config_1 = require("../config/config");
81
82
  let AuditUtils = (() => {
82
83
  let _classDecorators = [(0, typedi_1.Service)()];
83
84
  let _classDescriptor;
@@ -132,57 +133,74 @@ let AuditUtils = (() => {
132
133
  return audit;
133
134
  }
134
135
  async populateAuditFields(audit) {
135
- const { propertyId, propertyName, userId, userName, guestId, guestName, deviceId, deviceName, zoneId, zoneName, accessGroupId, accessGroupName, scheduleId, } = audit;
136
- if (propertyId && !propertyName) {
137
- if (propertyId === "triggered_externally") {
138
- audit.propertyName = "Triggered Externally";
136
+ try {
137
+ const { propertyId, propertyName, userId, userName, guestId, guestName, deviceId, deviceName, zoneId, zoneName, accessGroupId, accessGroupName, scheduleId, } = audit;
138
+ if (propertyId && !propertyName) {
139
+ (0, config_1.getLogger)().info(`Property ID: ${propertyId}`);
140
+ if (propertyId === "triggered_externally") {
141
+ audit.propertyName = "Triggered Externally";
142
+ }
143
+ else if (propertyId === "property_not_found") {
144
+ (0, config_1.getLogger)().info(`Property ID: ${propertyId}`);
145
+ audit.propertyName = "Property Not Found";
146
+ }
147
+ else {
148
+ (0, config_1.getLogger)().info(`Property ID: ${propertyId}`);
149
+ audit.propertyName = await this.getPropertyName(propertyId);
150
+ }
139
151
  }
140
- else {
141
- audit.propertyName = await this.getPropertyName(propertyId);
152
+ if (!propertyId && deviceId) {
153
+ audit.propertyId = await this.getFieldFromDevice(deviceId, "propertyId");
154
+ audit.propertyName = await this.getPropertyName(audit.propertyId);
155
+ }
156
+ if (zoneId && !zoneName)
157
+ audit.zoneName = await this.getZoneName(zoneId);
158
+ if (!zoneId && deviceId) {
159
+ audit.zoneId = await this.getFieldFromDevice(deviceId, "zoneId");
160
+ audit.zoneName = await this.getZoneName(audit.zoneId);
161
+ }
162
+ if (userId && !userName)
163
+ audit.userName = await this.getUserName(userId);
164
+ if (guestId && !guestName)
165
+ audit.guestName = await this.getGuestName(guestId);
166
+ if (deviceId && !deviceName) {
167
+ audit.deviceName = await this.getDeviceName(deviceId);
168
+ }
169
+ if (accessGroupId && !accessGroupName)
170
+ audit.accessGroupName = await this.getAccessGroupName(accessGroupId);
171
+ if (scheduleId) {
172
+ const { scheduleStartDate, scheduleEndDate, scheduleDuration, scheduleSource, scheduleStatus, } = await this.getScheduleDetails(scheduleId);
173
+ audit.scheduleStartDate = scheduleStartDate;
174
+ audit.scheduleEndDate = scheduleEndDate;
175
+ audit.scheduleDuration = scheduleDuration;
176
+ audit.scheduleSource = scheduleSource;
177
+ audit.scheduleStatus = scheduleStatus;
142
178
  }
143
179
  }
144
- if (!propertyId && deviceId) {
145
- audit.propertyId = await this.getFieldFromDevice(deviceId, "propertyId");
146
- audit.propertyName = await this.getPropertyName(audit.propertyId);
147
- }
148
- if (zoneId && !zoneName)
149
- audit.zoneName = await this.getZoneName(zoneId);
150
- if (!zoneId && deviceId) {
151
- audit.zoneId = await this.getFieldFromDevice(deviceId, "zoneId");
152
- audit.zoneName = await this.getZoneName(audit.zoneId);
153
- }
154
- if (userId && !userName)
155
- audit.userName = await this.getUserName(userId);
156
- if (guestId && !guestName)
157
- audit.guestName = await this.getGuestName(guestId);
158
- if (deviceId && !deviceName) {
159
- audit.deviceName = await this.getDeviceName(deviceId);
160
- }
161
- if (accessGroupId && !accessGroupName)
162
- audit.accessGroupName = await this.getAccessGroupName(accessGroupId);
163
- if (scheduleId) {
164
- const { scheduleStartDate, scheduleEndDate, scheduleDuration, scheduleSource, scheduleStatus, } = await this.getScheduleDetails(scheduleId);
165
- audit.scheduleStartDate = scheduleStartDate;
166
- audit.scheduleEndDate = scheduleEndDate;
167
- audit.scheduleDuration = scheduleDuration;
168
- audit.scheduleSource = scheduleSource;
169
- audit.scheduleStatus = scheduleStatus;
180
+ catch (error) {
181
+ (0, config_1.getLogger)().error("Error in populateAuditFields:", error);
170
182
  }
171
183
  }
172
184
  /**
173
185
  * Generic utility to get cached entity data from Redis using individual keys
174
186
  */
175
187
  async getCachedEntityData(entityType, entityId, fetchFunction) {
176
- const cacheKey = `${this.CACHE_PREFIX}:${entityType}:${entityId}`;
177
- // Try to get from cache first
178
- const cachedData = await this.redisUtils.get(cacheKey);
179
- if (cachedData) {
180
- return JSON.parse(cachedData);
188
+ try {
189
+ const cacheKey = `${this.CACHE_PREFIX}:${entityType}:${entityId}`;
190
+ // Try to get from cache first
191
+ const cachedData = await this.redisUtils.get(cacheKey);
192
+ if (cachedData) {
193
+ return JSON.parse(cachedData);
194
+ }
195
+ // If not in cache, fetch from database and cache it
196
+ const entityData = await fetchFunction();
197
+ await this.redisUtils.set(cacheKey, JSON.stringify(entityData), this.CACHE_TTL);
198
+ return entityData;
199
+ }
200
+ catch (error) {
201
+ (0, config_1.getLogger)().error("Error in getCachedEntityData:", error);
202
+ throw error;
181
203
  }
182
- // If not in cache, fetch from database and cache it
183
- const entityData = await fetchFunction();
184
- await this.redisUtils.set(cacheKey, JSON.stringify(entityData), this.CACHE_TTL);
185
- return entityData;
186
204
  }
187
205
  /**
188
206
  * Utility to calculate schedule duration in days
@@ -192,85 +210,139 @@ let AuditUtils = (() => {
192
210
  return Math.ceil(duration / (1000 * 60 * 60 * 24));
193
211
  }
194
212
  async getPropertyName(propertyId) {
195
- return this.getCachedEntityData("property", propertyId, async () => {
196
- const property = await typedi_1.default.get(property_1.LocalPropertyService).getProperty(propertyId);
197
- return property?.name || "";
198
- });
213
+ try {
214
+ return await this.getCachedEntityData("property", propertyId, async () => {
215
+ const property = await typedi_1.default.get(property_1.LocalPropertyService).getProperty(propertyId);
216
+ return property?.name || "property_not_found";
217
+ });
218
+ }
219
+ catch (error) {
220
+ (0, config_1.getLogger)().error("Error in getPropertyName:", error);
221
+ return "";
222
+ }
199
223
  }
200
224
  async getFieldFromDevice(deviceId, field) {
201
- const redisKey = `device:${deviceId}`;
202
- const redisDevice = await this.redisUtils.hget(redisKey, "device");
203
- if (redisDevice) {
204
- return redisDevice[field];
225
+ try {
226
+ const redisKey = `device:${deviceId}`;
227
+ const redisDevice = await this.redisUtils.hget(redisKey, "device");
228
+ if (redisDevice) {
229
+ return redisDevice[field];
230
+ }
231
+ else {
232
+ const device = await typedi_1.default.get(services_1.LocalDeviceService).getDevice(deviceId);
233
+ await this.redisUtils.hset(redisKey, "device", JSON.stringify(device));
234
+ await this.redisUtils.expire(redisKey, this.CACHE_TTL);
235
+ return device[field];
236
+ }
205
237
  }
206
- else {
207
- const device = await typedi_1.default.get(services_1.LocalDeviceService).getDevice(deviceId);
208
- await this.redisUtils.hset(redisKey, "device", JSON.stringify(device));
209
- await this.redisUtils.expire(redisKey, this.CACHE_TTL);
210
- return device[field];
238
+ catch (error) {
239
+ (0, config_1.getLogger)().error("Error in getFieldFromDevice:", error);
240
+ return "";
211
241
  }
212
242
  }
213
243
  async getUserName(userId) {
214
- return this.getCachedEntityData("user", userId, async () => {
215
- const user = await typedi_1.default.get(admin_1.AdminService).getUser(userId);
216
- if (!user)
217
- return "";
218
- return `${user?.firstName || ""} ${user?.lastName || ""}`.trim();
219
- });
244
+ try {
245
+ return await this.getCachedEntityData("user", userId, async () => {
246
+ const user = await typedi_1.default.get(admin_1.AdminService).getUser(userId);
247
+ if (!user)
248
+ return "user_not_found";
249
+ return `${user?.firstName || ""} ${user?.lastName || ""}`.trim();
250
+ });
251
+ }
252
+ catch (error) {
253
+ (0, config_1.getLogger)().error("Error in getUserName:", error);
254
+ return "";
255
+ }
220
256
  }
221
257
  async getGuestName(guestId) {
222
- return this.getCachedEntityData("guest", guestId, async () => {
223
- const guest = await typedi_1.default.get(pms_1.PmsService).getGuest(guestId);
224
- if (!guest)
225
- return "";
226
- return `${guest?.firstName || ""} ${guest?.lastName || ""}`.trim();
227
- });
258
+ try {
259
+ return await this.getCachedEntityData("guest", guestId, async () => {
260
+ const guest = await typedi_1.default.get(pms_1.PmsService).getGuest(guestId);
261
+ if (!guest)
262
+ return "";
263
+ return `${guest?.firstName || ""} ${guest?.lastName || ""}`.trim();
264
+ });
265
+ }
266
+ catch (error) {
267
+ (0, config_1.getLogger)().error("Error in getGuestName:", error);
268
+ return "";
269
+ }
228
270
  }
229
271
  async getDeviceName(deviceId) {
230
- return this.getCachedEntityData("device", deviceId, async () => {
231
- const device = await typedi_1.default.get(services_1.LocalDeviceService).querySelect({ deviceId }, ["name"]);
232
- if (!device)
233
- return "";
234
- return device[0]?.name || "";
235
- });
272
+ try {
273
+ return await this.getCachedEntityData("device", deviceId, async () => {
274
+ const device = await typedi_1.default.get(services_1.LocalDeviceService).querySelect({ deviceId }, ["name"]);
275
+ if (!device)
276
+ return "";
277
+ return device[0]?.name || "";
278
+ });
279
+ }
280
+ catch (error) {
281
+ (0, config_1.getLogger)().error("Error in getDeviceName:", error);
282
+ return "";
283
+ }
236
284
  }
237
285
  async getZoneName(zoneId) {
238
- return this.getCachedEntityData("zone", zoneId, async () => {
239
- const zone = await typedi_1.default.get(admin_1.AdminService).getZone(zoneId);
240
- if (!zone)
241
- return "";
242
- return zone?.name || "";
243
- });
286
+ try {
287
+ return await this.getCachedEntityData("zone", zoneId, async () => {
288
+ const zone = await typedi_1.default.get(admin_1.AdminService).getZone(zoneId);
289
+ if (!zone)
290
+ return "";
291
+ return zone?.name || "";
292
+ });
293
+ }
294
+ catch (error) {
295
+ (0, config_1.getLogger)().error("Error in getZoneName:", error);
296
+ return "";
297
+ }
244
298
  }
245
299
  async getAccessGroupName(accessGroupId) {
246
- return this.getCachedEntityData("accessGroup", accessGroupId, async () => {
247
- const accessGroup = await typedi_1.default.get(admin_1.AdminService).getAccessGroup(accessGroupId);
248
- if (!accessGroup)
249
- return "";
250
- return accessGroup?.name || "";
251
- });
300
+ try {
301
+ return await this.getCachedEntityData("accessGroup", accessGroupId, async () => {
302
+ const accessGroup = await typedi_1.default.get(admin_1.AdminService).getAccessGroup(accessGroupId);
303
+ if (!accessGroup)
304
+ return "";
305
+ return accessGroup?.name || "";
306
+ });
307
+ }
308
+ catch (error) {
309
+ (0, config_1.getLogger)().error("Error in getAccessGroupName:", error);
310
+ return "";
311
+ }
252
312
  }
253
313
  async getScheduleDetails(scheduleId) {
254
- return this.getCachedEntityData("schedule", scheduleId, async () => {
255
- const schedule = await typedi_1.default.get(pms_1.PmsService).getSchedule(scheduleId);
256
- if (!schedule) {
314
+ try {
315
+ return await this.getCachedEntityData("schedule", scheduleId, async () => {
316
+ const schedule = await typedi_1.default.get(pms_1.PmsService).getSchedule(scheduleId);
317
+ if (!schedule) {
318
+ return {
319
+ scheduleStartDate: "",
320
+ scheduleEndDate: "",
321
+ scheduleDuration: 0,
322
+ scheduleSource: "",
323
+ scheduleStatus: "",
324
+ };
325
+ }
326
+ const scheduleDuration = this.calculateScheduleDuration(schedule.startTime, schedule.endTime);
257
327
  return {
258
- scheduleStartDate: "",
259
- scheduleEndDate: "",
260
- scheduleDuration: 0,
261
- scheduleSource: "",
262
- scheduleStatus: "",
328
+ scheduleStartDate: schedule.startTime,
329
+ scheduleEndDate: schedule.endTime,
330
+ scheduleDuration,
331
+ scheduleSource: schedule.source,
332
+ scheduleStatus: schedule.status,
263
333
  };
264
- }
265
- const scheduleDuration = this.calculateScheduleDuration(schedule.startTime, schedule.endTime);
334
+ });
335
+ }
336
+ catch (error) {
337
+ (0, config_1.getLogger)().error("Error in getScheduleDetails:", error);
266
338
  return {
267
- scheduleStartDate: schedule.startTime,
268
- scheduleEndDate: schedule.endTime,
269
- scheduleDuration,
270
- scheduleSource: schedule.source,
271
- scheduleStatus: schedule.status,
339
+ scheduleStartDate: "",
340
+ scheduleEndDate: "",
341
+ scheduleDuration: 0,
342
+ scheduleSource: "",
343
+ scheduleStatus: "",
272
344
  };
273
- });
345
+ }
274
346
  }
275
347
  };
276
348
  __setFunctionName(_classThis, "AuditUtils");
@@ -1,5 +1,6 @@
1
+ import { IAccessGroup } from "./IAccessGroup";
1
2
  export declare class AccessGroupRepository {
2
3
  private readonly postgres;
3
4
  constructor();
4
- getAccessGroup(accessGroupId: string): Promise<any>;
5
+ getAccessGroup(accessGroupId: string): Promise<IAccessGroup | null>;
5
6
  }
@@ -56,7 +56,10 @@ let AccessGroupRepository = (() => {
56
56
  WHERE "id" = $1
57
57
  `;
58
58
  const result = await this.postgres.query(query, [accessGroupId]);
59
- return result.rows[0];
59
+ if (result.rows.length > 0) {
60
+ return result.rows[0];
61
+ }
62
+ return null;
60
63
  }
61
64
  };
62
65
  __setFunctionName(_classThis, "AccessGroupRepository");
@@ -1,5 +1,6 @@
1
+ import { IAccessGroup } from "./IAccessGroup";
1
2
  export declare class AccessGroupService {
2
3
  private readonly accessGroupRepository;
3
4
  constructor();
4
- getAccessGroup(accessGroupId: string): Promise<any>;
5
+ getAccessGroup(accessGroupId: string): Promise<IAccessGroup | null>;
5
6
  }
@@ -87,7 +87,10 @@ let AccessGroupService = (() => {
87
87
  if (!accessGroupId) {
88
88
  throw new Error("Access Group ID is required");
89
89
  }
90
- return await this.accessGroupRepository.getAccessGroup(accessGroupId);
90
+ const accessGroup = await this.accessGroupRepository.getAccessGroup(accessGroupId);
91
+ if (!accessGroup)
92
+ return null;
93
+ return accessGroup;
91
94
  }
92
95
  };
93
96
  __setFunctionName(_classThis, "AccessGroupService");
@@ -101,5 +104,3 @@ let AccessGroupService = (() => {
101
104
  return AccessGroupService = _classThis;
102
105
  })();
103
106
  exports.AccessGroupService = AccessGroupService;
104
- // Accessgroup.getAccessGroup(accessGroupId)
105
- // GetAccessGroup()
@@ -0,0 +1,5 @@
1
+ export declare class DeviceProfileRepository {
2
+ private readonly axiosInstance;
3
+ constructor();
4
+ getDeviceBaseLine(deviceId: string): Promise<void>;
5
+ }
@@ -37,44 +37,29 @@ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, p
37
37
  if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
38
38
  return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
39
39
  };
40
- var __importDefault = (this && this.__importDefault) || function (mod) {
41
- return (mod && mod.__esModule) ? mod : { "default": mod };
42
- };
43
40
  Object.defineProperty(exports, "__esModule", { value: true });
44
- exports.DeviceFactory = void 0;
45
- const Device_service_1 = require("../../local/services/Device.service");
46
- const typedi_1 = __importDefault(require("typedi"));
47
- const typedi_2 = require("typedi");
48
- let DeviceFactory = (() => {
49
- let _classDecorators = [(0, typedi_2.Service)()];
41
+ exports.DeviceProfileRepository = void 0;
42
+ const typedi_1 = require("typedi");
43
+ const utils_1 = require("../../../../utils");
44
+ let DeviceProfileRepository = (() => {
45
+ let _classDecorators = [(0, typedi_1.Service)()];
50
46
  let _classDescriptor;
51
47
  let _classExtraInitializers = [];
52
48
  let _classThis;
53
- var DeviceFactory = _classThis = class {
49
+ var DeviceProfileRepository = _classThis = class {
54
50
  constructor() {
55
- // Use dependency injection instead of creating new instance
56
- this.localDeviceService = typedi_1.default.get(Device_service_1.LocalDeviceService);
57
- }
58
- async getDevice(deviceId) {
59
- try {
60
- return await this.localDeviceService.getDevice(deviceId);
61
- }
62
- catch (error) {
63
- // Log the error for debugging purposes
64
- console.error(`DeviceFactory: Failed to get device ${deviceId}:`, error);
65
- // Re-throw the error with additional context
66
- throw new Error(`DeviceFactory: Unable to retrieve device ${deviceId}. ${error instanceof Error ? error.message : "Unknown error occurred"}`);
67
- }
51
+ this.axiosInstance = (0, utils_1.getDeviceServiceAxiosInstance)();
68
52
  }
53
+ async getDeviceBaseLine(deviceId) { }
69
54
  };
70
- __setFunctionName(_classThis, "DeviceFactory");
55
+ __setFunctionName(_classThis, "DeviceProfileRepository");
71
56
  (() => {
72
57
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
73
58
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
74
- DeviceFactory = _classThis = _classDescriptor.value;
59
+ DeviceProfileRepository = _classThis = _classDescriptor.value;
75
60
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
76
61
  __runInitializers(_classThis, _classExtraInitializers);
77
62
  })();
78
- return DeviceFactory = _classThis;
63
+ return DeviceProfileRepository = _classThis;
79
64
  })();
80
- exports.DeviceFactory = DeviceFactory;
65
+ exports.DeviceProfileRepository = DeviceProfileRepository;
@@ -137,7 +137,7 @@ let LocalDeviceService = (() => {
137
137
  await this.handleOnlineStatus(device, device.status, body.status, auditBody?.source || Service_1.Source.SYSTEM, auditBody);
138
138
  }
139
139
  else {
140
- await this.handleOfflineStatus(device, device.status, body.status, auditBody?.source || Service_1.Source.SYSTEM, auditBody);
140
+ await this.handleOfflineStatus(device, device.status, body.status, auditBody?.source || Service_1.Source.SYSTEM, auditBody, body.status.error?.message);
141
141
  }
142
142
  if (body.state?.batteryPercentage?.value) {
143
143
  await this.setBatteryLevel(deviceId, body.state?.batteryPercentage?.value, auditBody?.source || Service_1.Source.SYSTEM, auditBody);
@@ -278,8 +278,8 @@ let LocalDeviceService = (() => {
278
278
  await this.eventHandler.onStatusChangeMany(query, newStatus, auditBody, eventType);
279
279
  }
280
280
  async handleOfflineStatus(device, oldStatus, newStatus, source, auditBody, reason, currentTime) {
281
- const isExistingStatusOnline = oldStatus?.online === true;
282
- const isExistingStatusOffline = oldStatus?.online === false;
281
+ const isExistingStatusOnline = oldStatus?.liveStatus === "ONLINE";
282
+ const isExistingStatusOffline = oldStatus?.liveStatus === "OFFLINE";
283
283
  if (isExistingStatusOnline) {
284
284
  // Existing status is Online
285
285
  newStatus.online = true;
@@ -2,5 +2,5 @@ import { IGuest } from "./IGuest";
2
2
  export declare class GuestRepository {
3
3
  private readonly pmsPostgres;
4
4
  constructor();
5
- getGuest(guestId: string): Promise<IGuest>;
5
+ getGuest(guestId: string): Promise<IGuest | null>;
6
6
  }
@@ -52,8 +52,11 @@ let GuestRepository = (() => {
52
52
  }
53
53
  async getGuest(guestId) {
54
54
  try {
55
- const guest = await this.pmsPostgres.query(`SELECT * FROM dt_guests WHERE "id" = $1`, [guestId]);
56
- return guest.rows[0];
55
+ const guest = await this.pmsPostgres.query(`SELECT * FROM dt_guest WHERE "id" = $1`, [guestId]);
56
+ if (guest.rows.length > 0) {
57
+ return guest.rows[0];
58
+ }
59
+ return null;
57
60
  }
58
61
  catch (error) {
59
62
  console.error("Error in getGuest:", error);
@@ -2,5 +2,5 @@ import { IGuest } from "./IGuest";
2
2
  export declare class GuestService {
3
3
  private readonly guestRepository;
4
4
  constructor();
5
- getGuest(guestId: string): Promise<IGuest>;
5
+ getGuest(guestId: string): Promise<IGuest | null>;
6
6
  }
@@ -88,7 +88,10 @@ let GuestService = (() => {
88
88
  if (!guestId) {
89
89
  throw new Error("Guest ID is required");
90
90
  }
91
- return await this.guestRepository.getGuest(guestId);
91
+ const guest = await this.guestRepository.getGuest(guestId);
92
+ if (!guest)
93
+ return null;
94
+ return guest;
92
95
  }
93
96
  };
94
97
  __setFunctionName(_classThis, "GuestService");
@@ -2,5 +2,5 @@ import { ISchedule } from "./ISchedule";
2
2
  export declare class ScheduleRepository {
3
3
  private readonly pmsPostgres;
4
4
  constructor();
5
- getSchedule(scheduleId: string): Promise<ISchedule>;
5
+ getSchedule(scheduleId: string): Promise<ISchedule | null>;
6
6
  }
@@ -52,8 +52,11 @@ let ScheduleRepository = (() => {
52
52
  }
53
53
  async getSchedule(scheduleId) {
54
54
  try {
55
- const schedule = await this.pmsPostgres.query(`SELECT * FROM dt_schedules WHERE "id" = $1`, [scheduleId]);
56
- return schedule.rows[0];
55
+ const schedule = await this.pmsPostgres.query(`SELECT * FROM dt_schedule WHERE "id" = $1`, [scheduleId]);
56
+ if (schedule.rows.length > 0) {
57
+ return schedule.rows[0];
58
+ }
59
+ return null;
57
60
  }
58
61
  catch (error) {
59
62
  console.error("Error in getSchedule:", error);
@@ -2,5 +2,5 @@ import { ISchedule } from "./ISchedule";
2
2
  export declare class ScheduleService {
3
3
  private readonly scheduleRepository;
4
4
  constructor();
5
- getSchedule(scheduleId: string): Promise<ISchedule>;
5
+ getSchedule(scheduleId: string): Promise<ISchedule | null>;
6
6
  }
@@ -88,7 +88,10 @@ let ScheduleService = (() => {
88
88
  if (!scheduleId) {
89
89
  throw new Error("Schedule ID is required");
90
90
  }
91
- return await this.scheduleRepository.getSchedule(scheduleId);
91
+ const schedule = await this.scheduleRepository.getSchedule(scheduleId);
92
+ if (!schedule)
93
+ return null;
94
+ return schedule;
92
95
  }
93
96
  };
94
97
  __setFunctionName(_classThis, "ScheduleService");
@@ -52,7 +52,10 @@ let UserRepository = (() => {
52
52
  }
53
53
  async getUser(userId) {
54
54
  const user = await this.postgres.query(`SELECT * FROM dt_users WHERE "id" = $1`, [userId]);
55
- return user.rows[0];
55
+ if (user.rows.length > 0) {
56
+ return user.rows[0];
57
+ }
58
+ return null;
56
59
  }
57
60
  };
58
61
  __setFunctionName(_classThis, "UserRepository");
@@ -2,5 +2,5 @@ import { IUser } from "./IUser";
2
2
  export declare class UserService {
3
3
  private readonly userRepository;
4
4
  constructor();
5
- getUser(userId: string): Promise<IUser>;
5
+ getUser(userId: string): Promise<IUser | null>;
6
6
  }
@@ -87,7 +87,10 @@ let UserService = (() => {
87
87
  if (!userId) {
88
88
  throw new Error("User ID is required");
89
89
  }
90
- return await this.userRepository.getUser(userId);
90
+ const user = await this.userRepository.getUser(userId);
91
+ if (!user)
92
+ return null;
93
+ return user;
91
94
  }
92
95
  };
93
96
  __setFunctionName(_classThis, "UserService");
@@ -88,7 +88,10 @@ let ZoneService = (() => {
88
88
  if (!zoneId) {
89
89
  throw new Error("Zone ID is required");
90
90
  }
91
- return await this.zoneRepository.getZone(zoneId);
91
+ const zone = await this.zoneRepository.getZone(zoneId);
92
+ if (!zone)
93
+ return null;
94
+ return zone;
92
95
  }
93
96
  };
94
97
  __setFunctionName(_classThis, "ZoneService");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "7.8.14",
3
+ "version": "7.9.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -1,7 +0,0 @@
1
- export declare class AdminRepository {
2
- private readonly axiosInstance;
3
- private readonly deviceRepository;
4
- private readonly postgres;
5
- constructor();
6
- getZonesByAccessGroupIds(accessGroupIds: string[]): Promise<any[]>;
7
- }