dt-common-device 9.0.1 → 9.1.1

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.
@@ -606,7 +606,7 @@ let AlertService = (() => {
606
606
  if (alerts.length > 1) {
607
607
  throw new Error("Multiple alerts found, please specify a more specific query");
608
608
  }
609
- const alert = await Alert_model_1.AlertModel.findById(alerts[0]._id);
609
+ const alert = await Alert_model_1.AlertModel.findById(alerts[0]._id || alerts[0].id);
610
610
  if (!alert)
611
611
  return null;
612
612
  alert.deactivate(updatedBy);
@@ -619,9 +619,7 @@ let AlertService = (() => {
619
619
  if (!id || !updatedBy) {
620
620
  throw new Error("Alert ID and updated by user are required");
621
621
  }
622
- if (!until) {
623
- until = new Date(Date.now() + 1000 * 60 * 60 * 24); // 1 day
624
- }
622
+ until ?? (until = new Date(Date.now() + 1000 * 60 * 60 * 24)); // 1 day
625
623
  // Business logic: Validate snooze date
626
624
  this.validateSnoozeDate(until);
627
625
  const alertModel = await Alert_model_1.AlertModel.findById(id);
@@ -18,7 +18,6 @@ export declare class AuditUtils {
18
18
  private getPropertyName;
19
19
  private getFieldFromDevice;
20
20
  private getUserName;
21
- private getGuestName;
22
21
  private getDeviceName;
23
22
  private getZoneName;
24
23
  private getAccessGroupName;
@@ -162,7 +162,9 @@ let AuditUtils = (() => {
162
162
  if (userId && !userName)
163
163
  audit.userName = await this.getUserName(userId);
164
164
  if (guestId && !guestName)
165
- audit.guestName = await this.getGuestName(guestId);
165
+ audit.guestName = "Guest";
166
+ if (guestName)
167
+ audit.guestName = "Guest";
166
168
  if (deviceId && !deviceName) {
167
169
  audit.deviceName = await this.getDeviceName(deviceId);
168
170
  }
@@ -254,20 +256,6 @@ let AuditUtils = (() => {
254
256
  return "";
255
257
  }
256
258
  }
257
- async getGuestName(guestId) {
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 instanceof Error ? error.message : error}`);
268
- return "";
269
- }
270
- }
271
259
  async getDeviceName(deviceId) {
272
260
  try {
273
261
  return await this.getCachedEntityData("device", deviceId, async () => {
@@ -30,7 +30,6 @@ export interface IAuditProperties {
30
30
  userId?: string;
31
31
  userName?: string;
32
32
  guestId?: string;
33
- guestName?: string;
34
33
  deviceId?: string;
35
34
  deviceName?: string;
36
35
  zoneId?: string;
@@ -236,27 +236,37 @@ let LocalDeviceService = (() => {
236
236
  throw new Error("Device ID and new status are required");
237
237
  }
238
238
  const device = await this.getDevice(deviceId);
239
- const oldStatus = device.status;
240
- const currentTime = new Date().toISOString();
241
- // Determine if the new status is ONLINE or OFFLINE
242
- const isNewStatusOnline = newStatus?.liveStatus === "ONLINE";
243
- const isNewStatusOffline = newStatus?.liveStatus === "OFFLINE";
244
- if (isNewStatusOffline) {
245
- // New Status = OFFLINE
246
- await this.handleOfflineStatus(device, oldStatus, newStatus, source, auditBody, reason, currentTime);
247
- }
248
- else if (isNewStatusOnline) {
249
- // New Status = ONLINE
250
- await this.handleOnlineStatus(device, oldStatus, newStatus, source, auditBody, reason, currentTime);
239
+ //NOTE: Baseline logic only apply for device type of LOCK
240
+ if (device?.deviceType?.type === "LOCK") {
241
+ const oldStatus = device.status;
242
+ const currentTime = new Date().toISOString();
243
+ // Determine if the new status is ONLINE or OFFLINE
244
+ const isNewStatusOnline = newStatus?.liveStatus === "ONLINE";
245
+ const isNewStatusOffline = newStatus?.liveStatus === "OFFLINE";
246
+ if (isNewStatusOffline) {
247
+ // New Status = OFFLINE
248
+ await this.handleOfflineStatus(device, oldStatus, newStatus, source, auditBody, reason, currentTime);
249
+ }
250
+ else if (isNewStatusOnline) {
251
+ // New Status = ONLINE
252
+ await this.handleOnlineStatus(device, oldStatus, newStatus, source, auditBody, reason, currentTime);
253
+ }
254
+ else {
255
+ // For any other status, just update normally
256
+ await this.deviceRepository.setStatus(deviceId, newStatus);
257
+ await this.eventHandler.onStatusChange(deviceId, newStatus, auditBody, constants_1.DT_EVENT_TYPES.DEVICE.STATUS.UNKNOWN);
258
+ }
251
259
  }
252
260
  else {
253
- // For any other status, just update normally
261
+ // For DeviceTypes other than LOCK, just update normally (HUB, THERMOSTATS)
262
+ const eventType = newStatus.online
263
+ ? constants_1.DT_EVENT_TYPES.DEVICE.STATUS.ONLINE
264
+ : constants_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE;
254
265
  await this.deviceRepository.setStatus(deviceId, newStatus);
255
- await this.eventHandler.onStatusChange(deviceId, newStatus, auditBody, constants_1.DT_EVENT_TYPES.DEVICE.STATUS.UNKNOWN);
266
+ await this.eventHandler.onStatusChange(deviceId, newStatus, auditBody, eventType);
256
267
  }
257
268
  }
258
269
  async setStatusMany(query, newStatus, source, auditBody) {
259
- //TODO: Compare old and new if different then update
260
270
  if (!query || !newStatus) {
261
271
  throw new Error("Query and new status are required");
262
272
  }
@@ -266,15 +276,19 @@ let LocalDeviceService = (() => {
266
276
  : constants_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE;
267
277
  const devices = await this.deviceRepository.queryDevices(query);
268
278
  for (const device of devices) {
269
- if (newStatus.online) {
270
- await this.handleOnlineStatus(device, device.status, newStatus, source, auditBody);
279
+ if (device?.deviceType?.type === "LOCK") {
280
+ if (newStatus.online) {
281
+ await this.handleOnlineStatus(device, device.status, newStatus, source, auditBody);
282
+ }
283
+ else {
284
+ await this.handleOfflineStatus(device, device.status, newStatus, source, auditBody);
285
+ }
271
286
  }
272
287
  else {
273
- await this.handleOfflineStatus(device, device.status, newStatus, source, auditBody);
288
+ await this.deviceRepository.setStatus(device.deviceId, newStatus);
289
+ await this.eventHandler.onStatusChange(device.deviceId, newStatus, auditBody, eventType);
274
290
  }
275
291
  }
276
- await this.deviceRepository.setStatusMany(query, newStatus);
277
- await this.eventHandler.onStatusChangeMany(query, newStatus, auditBody, eventType);
278
292
  }
279
293
  async handleOfflineStatus(device, oldStatus, newStatus, source, auditBody, reason, currentTime) {
280
294
  currentTime = currentTime ?? new Date().toISOString();
@@ -580,7 +580,7 @@ let IssueService = (() => {
580
580
  });
581
581
  }
582
582
  // Add comment using the model instance methods
583
- const issueModel = await Issue_model_1.IssueModel.findById({ _id: issueId });
583
+ const issueModel = await Issue_model_1.IssueModel.findById(issueId);
584
584
  if (issueModel) {
585
585
  issueModel.addComment(commentData);
586
586
  return await issueModel.save();
@@ -31,7 +31,7 @@ export declare enum EntitySubType {
31
31
  YANOLJA = "YANOLJA",
32
32
  SKYTOUCH = "SKYTOUCH",
33
33
  SMARTTHINGS = "SMARTTHINGS",
34
- TTLock = "TTLock",
34
+ TTLOCK = "TTLOCK",
35
35
  TUYA = "TUYA",
36
36
  VERDANT = "VERDANT",
37
37
  SENSIBO = "SENSIBO",
@@ -40,7 +40,7 @@ var EntitySubType;
40
40
  EntitySubType["SKYTOUCH"] = "SKYTOUCH";
41
41
  // DEVICE PROVIDERS
42
42
  EntitySubType["SMARTTHINGS"] = "SMARTTHINGS";
43
- EntitySubType["TTLock"] = "TTLock";
43
+ EntitySubType["TTLOCK"] = "TTLOCK";
44
44
  EntitySubType["TUYA"] = "TUYA";
45
45
  EntitySubType["VERDANT"] = "VERDANT";
46
46
  EntitySubType["SENSIBO"] = "SENSIBO";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "9.0.1",
3
+ "version": "9.1.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [