dt-common-device 6.0.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.
@@ -1,49 +1,132 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
19
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
20
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
21
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
22
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
23
+ var _, done = false;
24
+ for (var i = decorators.length - 1; i >= 0; i--) {
25
+ var context = {};
26
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
27
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
28
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
29
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
30
+ if (kind === "accessor") {
31
+ if (result === void 0) continue;
32
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
33
+ if (_ = accept(result.get)) descriptor.get = _;
34
+ if (_ = accept(result.set)) descriptor.set = _;
35
+ if (_ = accept(result.init)) initializers.unshift(_);
36
+ }
37
+ else if (_ = accept(result)) {
38
+ if (kind === "field") initializers.unshift(_);
39
+ else descriptor[key] = _;
40
+ }
41
+ }
42
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
43
+ done = true;
44
+ };
45
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
46
+ var useValue = arguments.length > 2;
47
+ for (var i = 0; i < initializers.length; i++) {
48
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
49
+ }
50
+ return useValue ? value : void 0;
51
+ };
52
+ var __importStar = (this && this.__importStar) || (function () {
53
+ var ownKeys = function(o) {
54
+ ownKeys = Object.getOwnPropertyNames || function (o) {
55
+ var ar = [];
56
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
57
+ return ar;
58
+ };
59
+ return ownKeys(o);
60
+ };
61
+ return function (mod) {
62
+ if (mod && mod.__esModule) return mod;
63
+ var result = {};
64
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
65
+ __setModuleDefault(result, mod);
66
+ return result;
67
+ };
68
+ })();
69
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
70
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
71
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
4
72
  };
5
73
  Object.defineProperty(exports, "__esModule", { value: true });
6
74
  exports.AdminService = void 0;
7
- const typedi_1 = __importDefault(require("typedi"));
75
+ const typedi_1 = __importStar(require("typedi"));
8
76
  const Admin_repository_1 = require("./Admin.repository");
9
- class AdminService {
10
- constructor() {
11
- this.adminRepository = typedi_1.default.get(Admin_repository_1.AdminRepository);
12
- }
13
- async getZonesByAccessGroupIds(accessGroupIds) {
14
- try {
15
- return await this.adminRepository.getZonesByAccessGroupIds(accessGroupIds);
77
+ let AdminService = (() => {
78
+ let _classDecorators = [(0, typedi_1.Service)()];
79
+ let _classDescriptor;
80
+ let _classExtraInitializers = [];
81
+ let _classThis;
82
+ var AdminService = _classThis = class {
83
+ constructor() {
84
+ this.adminRepository = typedi_1.default.get(Admin_repository_1.AdminRepository);
16
85
  }
17
- catch (error) {
18
- console.log(error);
86
+ async getZonesByAccessGroupIds(accessGroupIds) {
87
+ try {
88
+ return await this.adminRepository.getZonesByAccessGroupIds(accessGroupIds);
89
+ }
90
+ catch (error) {
91
+ console.log(error);
92
+ }
19
93
  }
20
- }
21
- async getAccessGroup(accessGroupId) {
22
- if (!accessGroupId) {
23
- throw new Error("Access Group ID is required");
94
+ async getAccessGroup(accessGroupId) {
95
+ if (!accessGroupId) {
96
+ throw new Error("Access Group ID is required");
97
+ }
98
+ const accessGroup = await this.adminRepository.getAccessGroup(accessGroupId);
99
+ if (!accessGroup)
100
+ return null;
101
+ return accessGroup;
24
102
  }
25
- const accessGroup = await this.adminRepository.getAccessGroup(accessGroupId);
26
- if (!accessGroup)
27
- return null;
28
- return accessGroup;
29
- }
30
- async getZone(zoneId) {
31
- if (!zoneId) {
32
- throw new Error("Zone ID is required");
103
+ async getZone(zoneId) {
104
+ if (!zoneId) {
105
+ throw new Error("Zone ID is required");
106
+ }
107
+ const zone = await this.adminRepository.getZone(zoneId);
108
+ if (!zone)
109
+ return null;
110
+ return zone;
33
111
  }
34
- const zone = await this.adminRepository.getZone(zoneId);
35
- if (!zone)
36
- return null;
37
- return zone;
38
- }
39
- async getUser(userId) {
40
- if (!userId) {
41
- throw new Error("User ID is required");
112
+ async getUser(userId) {
113
+ if (!userId) {
114
+ throw new Error("User ID is required");
115
+ }
116
+ const user = await this.adminRepository.getUser(userId);
117
+ if (!user)
118
+ return null;
119
+ return user;
42
120
  }
43
- const user = await this.adminRepository.getUser(userId);
44
- if (!user)
45
- return null;
46
- return user;
47
- }
48
- }
121
+ };
122
+ __setFunctionName(_classThis, "AdminService");
123
+ (() => {
124
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
125
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
126
+ AdminService = _classThis = _classDescriptor.value;
127
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
128
+ __runInitializers(_classThis, _classExtraInitializers);
129
+ })();
130
+ return AdminService = _classThis;
131
+ })();
49
132
  exports.AdminService = AdminService;
@@ -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.0.0",
3
+ "version": "6.2.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [