dt-common-device 6.1.0 → 6.2.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.
@@ -77,7 +77,9 @@ const lodash_1 = require("lodash");
77
77
  const Device_repository_1 = require("../repository/Device.repository");
78
78
  const Alert_service_1 = require("../../../../alerts/Alert.service");
79
79
  const Issue_service_1 = require("../../../../issues/Issue.service");
80
+ const Service_1 = require("../../../../constants/Service");
80
81
  const typedi_1 = __importStar(require("typedi"));
82
+ const IAuditProperties_1 = require("../../../../audit/IAuditProperties");
81
83
  const constants_1 = require("../../../../constants");
82
84
  const audit_1 = require("../../../../audit");
83
85
  let LocalDeviceService = (() => {
@@ -148,7 +150,6 @@ let LocalDeviceService = (() => {
148
150
  },
149
151
  });
150
152
  }
151
- //TODO: Also check if state is coming in the body and publish audit based on which state is changing to get the audit type
152
153
  await this.deviceRepository.updateDevice(deviceId, body);
153
154
  return await this.eventHandler.onDeviceUpdate(deviceId, body, auditBody);
154
155
  }
@@ -156,6 +157,29 @@ let LocalDeviceService = (() => {
156
157
  if (!query || !updateData) {
157
158
  throw new Error("Query and update data are required");
158
159
  }
160
+ if (updateData?.status) {
161
+ const auditType = updateData?.status?.online
162
+ ? constants_1.DT_EVENT_TYPES.DEVICE.STATUS.ONLINE
163
+ : constants_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE;
164
+ const devices = await this.deviceRepository.queryDevices(query);
165
+ devices.forEach((device) => {
166
+ (0, audit_1.pushAudit)({
167
+ auditType,
168
+ auditData: {
169
+ resource: IAuditProperties_1.Resource.DEVICE,
170
+ source: Service_1.Source.DEVICE_ACTION,
171
+ propertyId: device.propertyId,
172
+ deviceId: device.deviceId,
173
+ zoneId: device.zoneId,
174
+ deviceType: device.deviceType,
175
+ deviceName: device.name,
176
+ deviceStatus: device.status,
177
+ oldStatus: device.status,
178
+ newStatus: updateData.status,
179
+ },
180
+ });
181
+ });
182
+ }
159
183
  return await this.deviceRepository.updateDevices(query, updateData);
160
184
  }
161
185
  async deleteDevice(deviceId, auditBody) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "6.1.0",
3
+ "version": "6.2.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [