dt-common-device 7.6.4 → 7.6.6

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.
@@ -71,7 +71,7 @@ export declare class AlertService {
71
71
  /**
72
72
  * Deactivate an alert with business logic
73
73
  */
74
- deactivateAlert(id: string, updatedBy: string): Promise<IAlertDocument | null>;
74
+ deactivateAlert(query: IAlertQuery, updatedBy: string): Promise<IAlertDocument | null>;
75
75
  /**
76
76
  * Snooze an alert with business logic
77
77
  */
@@ -329,6 +329,7 @@ let AlertService = (() => {
329
329
  entityId: processedAlertData.entityId,
330
330
  entityType: processedAlertData.entityType,
331
331
  entitySubType: processedAlertData.entitySubType,
332
+ isActive: true,
332
333
  });
333
334
  if (existingAlert.length > 0) {
334
335
  await (0, audit_1.pushAudit)({
@@ -483,15 +484,20 @@ let AlertService = (() => {
483
484
  /**
484
485
  * Deactivate an alert with business logic
485
486
  */
486
- async deactivateAlert(id, updatedBy) {
487
- if (!id || !updatedBy) {
488
- throw new Error("Alert ID and updated by user are required");
487
+ async deactivateAlert(query, updatedBy) {
488
+ if (!query || !updatedBy)
489
+ throw new Error("Alert query and updated by user are required");
490
+ const alerts = await this.queryAlerts(query);
491
+ if (!alerts.length)
492
+ return null;
493
+ if (alerts.length > 1) {
494
+ throw new Error("Multiple alerts found, please specify a more specific query");
489
495
  }
490
- const alertModel = await Alert_model_1.AlertModel.findById(id);
491
- if (!alertModel)
496
+ const alert = await Alert_model_1.AlertModel.findById(alerts[0]._id);
497
+ if (!alert)
492
498
  return null;
493
- alertModel.deactivate(updatedBy);
494
- return await alertModel.save();
499
+ alert.deactivate(updatedBy);
500
+ return await alert.save();
495
501
  }
496
502
  /**
497
503
  * Snooze an alert with business logic
@@ -191,7 +191,7 @@ function getLogger() {
191
191
  * Throws an error if not set.
192
192
  */
193
193
  function getAdminPostgresDbUri() {
194
- const fullUri = process.env[db_keys.admin];
194
+ const fullUri = process.env[db_keys?.admin];
195
195
  if (!fullUri) {
196
196
  getConfig().LOGGER.error("ADMIN_DB_URI must be set in environment variables or .env file");
197
197
  throw new Error("dt-common-device: ADMIN_DB_URI must be set in environment variables or .env file");
@@ -199,7 +199,7 @@ function getAdminPostgresDbUri() {
199
199
  return fullUri;
200
200
  }
201
201
  function getAccessPostgresDbUri() {
202
- const fullUri = process.env[db_keys.access];
202
+ const fullUri = process.env[db_keys?.access];
203
203
  if (!fullUri) {
204
204
  getConfig().LOGGER.error("ACCESS_DB_URI must be set in environment variables or .env file");
205
205
  throw new Error("dt-common-device: ACCESS_DB_URI must be set in environment variables or .env file");
@@ -207,7 +207,7 @@ function getAccessPostgresDbUri() {
207
207
  return fullUri;
208
208
  }
209
209
  function getPmsPostgresDbUri() {
210
- const fullUri = process.env[db_keys.pms];
210
+ const fullUri = process.env[db_keys?.pms];
211
211
  if (!fullUri) {
212
212
  getConfig().LOGGER.error("PMS_DB_URI must be set in environment variables or .env file");
213
213
  throw new Error("dt-common-device: PMS_DB_URI must be set in environment variables or .env file");
@@ -36,10 +36,7 @@ export declare const DT_EVENT_TYPES: {
36
36
  CHANGED: string;
37
37
  };
38
38
  STATUS: {
39
- ATTEMPT: {
40
- SUCCESS: string;
41
- FAILED: string;
42
- };
39
+ UPDATED: string;
43
40
  ONLINE: string;
44
41
  OFFLINE: string;
45
42
  UNKNOWN: string;
@@ -39,10 +39,7 @@ exports.DT_EVENT_TYPES = {
39
39
  CHANGED: "device.state.changed",
40
40
  },
41
41
  STATUS: {
42
- ATTEMPT: {
43
- SUCCESS: "device.status.attempt.success",
44
- FAILED: "device.status.attempt.failed",
45
- },
42
+ UPDATED: "device.status.updated",
46
43
  ONLINE: "device.status.online",
47
44
  OFFLINE: "device.status.offline",
48
45
  UNKNOWN: "device.status.unknown",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "7.6.4",
3
+ "version": "7.6.6",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [