dt-common-device 7.2.7 → 7.4.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 (212) hide show
  1. package/dist/alerts/Alert.model.d.ts +1 -1
  2. package/dist/alerts/Alert.model.js +0 -1
  3. package/dist/alerts/Alert.repository.d.ts +1 -0
  4. package/dist/alerts/Alert.repository.js +25 -19
  5. package/dist/alerts/alert.types.d.ts +3 -3
  6. package/dist/config/config.d.ts +1 -0
  7. package/dist/config/config.js +12 -0
  8. package/dist/config/constants.js +7 -1
  9. package/dist/constants/Event.d.ts +1 -0
  10. package/dist/constants/Event.js +1 -0
  11. package/dist/entities/accessGroup/AccessGroup.repository.d.ts +2 -1
  12. package/dist/entities/accessGroup/AccessGroup.repository.js +4 -1
  13. package/dist/entities/accessGroup/AccessGroup.service.d.ts +2 -1
  14. package/dist/entities/accessGroup/AccessGroup.service.js +4 -3
  15. package/dist/entities/device/local/services/Device.service.d.ts +1 -0
  16. package/dist/entities/device/local/services/Device.service.js +12 -5
  17. package/dist/entities/guest/Guest.repository.d.ts +1 -1
  18. package/dist/entities/guest/Guest.repository.js +5 -2
  19. package/dist/entities/guest/Guest.service.d.ts +1 -1
  20. package/dist/entities/guest/Guest.service.js +4 -1
  21. package/dist/entities/schedules/Schedule.repository.d.ts +1 -1
  22. package/dist/entities/schedules/Schedule.repository.js +5 -2
  23. package/dist/entities/schedules/Schedule.service.d.ts +1 -1
  24. package/dist/entities/schedules/Schedule.service.js +4 -1
  25. package/dist/entities/user/User.repository.js +4 -1
  26. package/dist/entities/user/User.service.d.ts +1 -1
  27. package/dist/entities/user/User.service.js +4 -1
  28. package/dist/entities/zone/Zone.service.js +4 -1
  29. package/dist/events/EventHandler.d.ts +1 -0
  30. package/dist/events/EventHandler.js +10 -0
  31. package/dist/events/InternalEventSubscription.d.ts +1 -0
  32. package/dist/events/InternalEventSubscription.js +4 -0
  33. package/dist/issues/Issue.model.d.ts +1 -1
  34. package/dist/issues/Issue.model.js +0 -1
  35. package/dist/issues/Issue.repository.d.ts +1 -0
  36. package/dist/issues/Issue.repository.js +23 -23
  37. package/dist/issues/issue.types.d.ts +3 -3
  38. package/package.json +1 -1
  39. package/dist/admin/Admin.repository.d.ts +0 -7
  40. package/dist/admin/Admin.repository.js +0 -182
  41. package/dist/admin/Admin.service.d.ts +0 -5
  42. package/dist/admin/Admin.service.js +0 -17
  43. package/dist/admin/index.d.ts +0 -1
  44. package/dist/admin/index.js +0 -17
  45. package/dist/audit/AuditProperties.d.ts +0 -16
  46. package/dist/audit/AuditProperties.js +0 -2
  47. package/dist/chronicle/IChronicle.interface.d.ts +0 -14
  48. package/dist/chronicle/IChronicle.interface.js +0 -2
  49. package/dist/chronicle/chronicle.service.d.ts +0 -4
  50. package/dist/chronicle/chronicle.service.js +0 -44
  51. package/dist/connection/Connection.repository.d.ts +0 -8
  52. package/dist/connection/Connection.repository.js +0 -92
  53. package/dist/connection/Connection.service.d.ts +0 -8
  54. package/dist/connection/Connection.service.js +0 -32
  55. package/dist/connection/IConnection.d.ts +0 -28
  56. package/dist/connection/IConnection.js +0 -16
  57. package/dist/connection/index.d.ts +0 -2
  58. package/dist/connection/index.js +0 -18
  59. package/dist/device/cloud/entities/CloudConnection.d.ts +0 -6
  60. package/dist/device/cloud/entities/CloudConnection.js +0 -6
  61. package/dist/device/cloud/entities/CloudDevice.d.ts +0 -16
  62. package/dist/device/cloud/entities/CloudDevice.js +0 -26
  63. package/dist/device/cloud/entities/CloudDeviceService.d.ts +0 -5
  64. package/dist/device/cloud/entities/CloudDeviceService.js +0 -9
  65. package/dist/device/cloud/entities/DeviceFactory.d.ts +0 -7
  66. package/dist/device/cloud/entities/DeviceFactory.js +0 -80
  67. package/dist/device/cloud/entities/index.d.ts +0 -3
  68. package/dist/device/cloud/entities/index.js +0 -19
  69. package/dist/device/cloud/interface.d.ts +0 -101
  70. package/dist/device/cloud/interface.js +0 -3
  71. package/dist/device/cloud/interfaces/ICloudConnection.d.ts +0 -5
  72. package/dist/device/cloud/interfaces/ICloudConnection.js +0 -2
  73. package/dist/device/cloud/interfaces/ICloudDevice.d.ts +0 -9
  74. package/dist/device/cloud/interfaces/ICloudDevice.js +0 -2
  75. package/dist/device/cloud/interfaces/ICloudDeviceService.d.ts +0 -4
  76. package/dist/device/cloud/interfaces/ICloudDeviceService.js +0 -2
  77. package/dist/device/cloud/interfaces/IConnectionService.d.ts +0 -7
  78. package/dist/device/cloud/interfaces/IConnectionService.js +0 -2
  79. package/dist/device/cloud/interfaces/IDeviceConnectionService.d.ts +0 -7
  80. package/dist/device/cloud/interfaces/IDeviceConnectionService.js +0 -3
  81. package/dist/device/cloud/interfaces/IDeviceFactory.d.ts +0 -4
  82. package/dist/device/cloud/interfaces/IDeviceFactory.js +0 -2
  83. package/dist/device/cloud/interfaces/IDeviceService.d.ts +0 -8
  84. package/dist/device/cloud/interfaces/IDeviceService.js +0 -2
  85. package/dist/device/cloud/interfaces/IDevicesService.d.ts +0 -9
  86. package/dist/device/cloud/interfaces/IDevicesService.js +0 -2
  87. package/dist/device/cloud/interfaces/IHubService.d.ts +0 -5
  88. package/dist/device/cloud/interfaces/IHubService.js +0 -2
  89. package/dist/device/cloud/interfaces/IRawDataTransformer.d.ts +0 -4
  90. package/dist/device/cloud/interfaces/IRawDataTransformer.js +0 -2
  91. package/dist/device/cloud/interfaces/IRawDevice.d.ts +0 -17
  92. package/dist/device/cloud/interfaces/IRawDevice.js +0 -11
  93. package/dist/device/cloud/interfaces/index.d.ts +0 -5
  94. package/dist/device/cloud/interfaces/index.js +0 -21
  95. package/dist/device/cloud/services/CloudDevice.service.d.ts +0 -5
  96. package/dist/device/cloud/services/CloudDevice.service.js +0 -9
  97. package/dist/device/cloud/services/Connection.service.d.ts +0 -8
  98. package/dist/device/cloud/services/Connection.service.js +0 -6
  99. package/dist/device/cloud/services/Device.service.d.ts +0 -39
  100. package/dist/device/cloud/services/Device.service.js +0 -9
  101. package/dist/device/cloud/services/DeviceCloudService.d.ts +0 -42
  102. package/dist/device/cloud/services/DeviceCloudService.js +0 -59
  103. package/dist/device/cloud/services/DeviceHub.service.d.ts +0 -3
  104. package/dist/device/cloud/services/DeviceHub.service.js +0 -6
  105. package/dist/device/cloud/services/Hub.service.d.ts +0 -25
  106. package/dist/device/cloud/services/Hub.service.js +0 -9
  107. package/dist/device/cloud/services/SmartThingsDeviceService.d.ts +0 -38
  108. package/dist/device/cloud/services/SmartThingsDeviceService.js +0 -52
  109. package/dist/device/cloud/services/index.d.ts +0 -2
  110. package/dist/device/cloud/services/index.js +0 -18
  111. package/dist/device/cloud/types.d.ts +0 -52
  112. package/dist/device/cloud/types.js +0 -15
  113. package/dist/device/index.d.ts +0 -4
  114. package/dist/device/index.js +0 -20
  115. package/dist/device/local/entities/AlertBuilder.d.ts +0 -87
  116. package/dist/device/local/entities/AlertBuilder.example.d.ts +0 -11
  117. package/dist/device/local/entities/AlertBuilder.example.js +0 -117
  118. package/dist/device/local/entities/AlertBuilder.js +0 -179
  119. package/dist/device/local/entities/IssueBuilder.d.ts +0 -109
  120. package/dist/device/local/entities/IssueBuilder.example.d.ts +0 -16
  121. package/dist/device/local/entities/IssueBuilder.example.js +0 -196
  122. package/dist/device/local/entities/IssueBuilder.js +0 -237
  123. package/dist/device/local/entities/index.d.ts +0 -2
  124. package/dist/device/local/entities/index.js +0 -7
  125. package/dist/device/local/events/EventHandler.d.ts +0 -11
  126. package/dist/device/local/events/EventHandler.js +0 -86
  127. package/dist/device/local/events/Events.d.ts +0 -54
  128. package/dist/device/local/events/Events.js +0 -57
  129. package/dist/device/local/events/index.d.ts +0 -2
  130. package/dist/device/local/events/index.js +0 -7
  131. package/dist/device/local/handler/EventHandler.d.ts +0 -7
  132. package/dist/device/local/handler/EventHandler.js +0 -44
  133. package/dist/device/local/interface.d.ts +0 -0
  134. package/dist/device/local/interface.js +0 -1
  135. package/dist/device/local/interfaces/IConnection.d.ts +0 -26
  136. package/dist/device/local/interfaces/IConnection.js +0 -14
  137. package/dist/device/local/interfaces/IDevice.d.ts +0 -68
  138. package/dist/device/local/interfaces/IDevice.js +0 -10
  139. package/dist/device/local/interfaces/IDtDevice.d.ts +0 -16
  140. package/dist/device/local/interfaces/IDtDevice.js +0 -2
  141. package/dist/device/local/interfaces/IHub.d.ts +0 -46
  142. package/dist/device/local/interfaces/IHub.js +0 -2
  143. package/dist/device/local/interfaces/IProperty.d.ts +0 -29
  144. package/dist/device/local/interfaces/IProperty.js +0 -2
  145. package/dist/device/local/interfaces/ISchedule.d.ts +0 -25
  146. package/dist/device/local/interfaces/ISchedule.js +0 -2
  147. package/dist/device/local/interfaces/index.d.ts +0 -3
  148. package/dist/device/local/interfaces/index.js +0 -19
  149. package/dist/device/local/models/Alert.model.d.ts +0 -28
  150. package/dist/device/local/models/Alert.model.js +0 -222
  151. package/dist/device/local/models/Issue.model.d.ts +0 -28
  152. package/dist/device/local/models/Issue.model.js +0 -260
  153. package/dist/device/local/repository/Alert.repository.d.ts +0 -106
  154. package/dist/device/local/repository/Alert.repository.js +0 -374
  155. package/dist/device/local/repository/Connection.repository.d.ts +0 -8
  156. package/dist/device/local/repository/Connection.repository.js +0 -92
  157. package/dist/device/local/repository/Device.repository.d.ts +0 -30
  158. package/dist/device/local/repository/Device.repository.js +0 -325
  159. package/dist/device/local/repository/Hub.repository.d.ts +0 -13
  160. package/dist/device/local/repository/Hub.repository.js +0 -139
  161. package/dist/device/local/repository/Issue.repository.d.ts +0 -113
  162. package/dist/device/local/repository/Issue.repository.js +0 -401
  163. package/dist/device/local/repository/Property.repository.d.ts +0 -8
  164. package/dist/device/local/repository/Property.repository.js +0 -95
  165. package/dist/device/local/repository/Schedule.repository.d.ts +0 -9
  166. package/dist/device/local/repository/Schedule.repository.js +0 -109
  167. package/dist/device/local/services/Alert.service.d.ts +0 -137
  168. package/dist/device/local/services/Alert.service.js +0 -475
  169. package/dist/device/local/services/AlertService.example.d.ts +0 -55
  170. package/dist/device/local/services/AlertService.example.js +0 -148
  171. package/dist/device/local/services/Connection.service.d.ts +0 -8
  172. package/dist/device/local/services/Connection.service.js +0 -32
  173. package/dist/device/local/services/Device.service.d.ts +0 -40
  174. package/dist/device/local/services/Device.service.js +0 -391
  175. package/dist/device/local/services/DeviceHub.service.d.ts +0 -11
  176. package/dist/device/local/services/DeviceHub.service.js +0 -40
  177. package/dist/device/local/services/Hub.service.d.ts +0 -12
  178. package/dist/device/local/services/Hub.service.js +0 -107
  179. package/dist/device/local/services/Issue.service.d.ts +0 -168
  180. package/dist/device/local/services/Issue.service.js +0 -642
  181. package/dist/device/local/services/IssueService.example.d.ts +0 -68
  182. package/dist/device/local/services/IssueService.example.js +0 -177
  183. package/dist/device/local/services/Property.service.d.ts +0 -8
  184. package/dist/device/local/services/Property.service.js +0 -36
  185. package/dist/device/local/services/Schedule.service.d.ts +0 -9
  186. package/dist/device/local/services/Schedule.service.js +0 -26
  187. package/dist/device/local/services/index.d.ts +0 -3
  188. package/dist/device/local/services/index.js +0 -19
  189. package/dist/pms/IPms.d.ts +0 -6
  190. package/dist/pms/IPms.js +0 -10
  191. package/dist/pms/index.d.ts +0 -1
  192. package/dist/pms/index.js +0 -17
  193. package/dist/property/IProperty.d.ts +0 -29
  194. package/dist/property/IProperty.js +0 -2
  195. package/dist/property/Property.repository.d.ts +0 -8
  196. package/dist/property/Property.repository.js +0 -109
  197. package/dist/property/Property.service.d.ts +0 -8
  198. package/dist/property/Property.service.js +0 -124
  199. package/dist/property/index.d.ts +0 -2
  200. package/dist/property/index.js +0 -18
  201. package/dist/queue/interfaces/IHttpRequestJob.d.ts +0 -9
  202. package/dist/queue/interfaces/IHttpRequestJob.js +0 -2
  203. package/dist/types/alert.types.d.ts +0 -57
  204. package/dist/types/alert.types.js +0 -22
  205. package/dist/types/config.types.d.ts +0 -19
  206. package/dist/types/config.types.js +0 -2
  207. package/dist/types/index.d.ts +0 -3
  208. package/dist/types/index.js +0 -19
  209. package/dist/types/issue.types.d.ts +0 -90
  210. package/dist/types/issue.types.js +0 -40
  211. package/dist/utils/http-utils.d.ts +0 -13
  212. package/dist/utils/http-utils.js +0 -117
@@ -13,7 +13,7 @@ interface IAlertModel extends Model<IAlertDocument, {}, IAlertMethods> {
13
13
  findSnoozed(includeDeleted?: boolean): Promise<IAlertDocument[]>;
14
14
  findExpiredSnooze(includeDeleted?: boolean): Promise<IAlertDocument[]>;
15
15
  }
16
- declare const AlertSchema: mongoose.Schema<IAlertDocument, IAlertModel, IAlertMethods, {}, {}, {}, mongoose.DefaultSchemaOptions, IAlertDocument, mongoose.Document<unknown, {}, mongoose.FlatRecord<IAlertDocument>, {}> & Omit<mongoose.FlatRecord<IAlertDocument> & Required<{
16
+ declare const AlertSchema: mongoose.Schema<IAlertDocument, IAlertModel, IAlertMethods, {}, {}, {}, mongoose.DefaultSchemaOptions, IAlertDocument, mongoose.Document<unknown, {}, mongoose.FlatRecord<IAlertDocument>, {}, mongoose.ResolveSchemaOptions<mongoose.DefaultSchemaOptions>> & Omit<mongoose.FlatRecord<IAlertDocument> & Required<{
17
17
  _id: string;
18
18
  }> & {
19
19
  __v: number;
@@ -117,7 +117,6 @@ const AlertSchema = new mongoose_1.Schema({
117
117
  default: Date.now,
118
118
  },
119
119
  }, {
120
- timestamps: true,
121
120
  collection: "dt_alerts",
122
121
  toJSON: { virtuals: true },
123
122
  toObject: { virtuals: true },
@@ -2,6 +2,7 @@ import { IAlertDocument } from "./Alert.model";
2
2
  import { CreateAlertData, UpdateAlertData, AlertCategory, AlertSeverity, IAlertQuery } from "./alert.types";
3
3
  export declare class AlertRepository {
4
4
  private buildQuery;
5
+ private buildOptions;
5
6
  /**
6
7
  * Create a new alert
7
8
  */
@@ -48,7 +48,7 @@ let AlertRepository = (() => {
48
48
  let _classExtraInitializers = [];
49
49
  let _classThis;
50
50
  var AlertRepository = _classThis = class {
51
- async buildQuery(filters = {}) {
51
+ buildQuery(filters = {}) {
52
52
  const query = {};
53
53
  if (filters.propertyId)
54
54
  query.propertyId = filters.propertyId;
@@ -68,18 +68,34 @@ let AlertRepository = (() => {
68
68
  query.isRead = filters.isRead;
69
69
  if (!filters.includeDeleted)
70
70
  query.isDeleted = false;
71
- if (filters.type)
72
- query.type = filters.type;
71
+ if (filters.type) {
72
+ if (Array.isArray(filters.type)) {
73
+ query.type = { $in: filters.type };
74
+ }
75
+ else {
76
+ query.type = filters.type;
77
+ }
78
+ }
73
79
  // Date filtering
74
80
  if (filters.startDate || filters.endDate) {
75
81
  query.createdAt = {};
76
82
  if (filters.startDate)
77
- query.createdAt.$gte = filters.startDate;
83
+ query.createdAt.$gte = new Date(filters.startDate);
78
84
  if (filters.endDate)
79
- query.createdAt.$lte = filters.endDate;
85
+ query.createdAt.$lte = new Date(filters.endDate);
80
86
  }
81
87
  return query;
82
88
  }
89
+ buildOptions(filters = {}) {
90
+ const options = {};
91
+ if (filters.sort)
92
+ options.sort = filters.sort;
93
+ if (filters.skip)
94
+ options.skip = filters.skip;
95
+ if (filters.limit)
96
+ options.limit = filters.limit;
97
+ return options;
98
+ }
83
99
  /**
84
100
  * Create a new alert
85
101
  */
@@ -120,19 +136,9 @@ let AlertRepository = (() => {
120
136
  */
121
137
  async query(filters = {}) {
122
138
  try {
123
- const query = await this.buildQuery(filters);
124
- const queryBuilder = Alert_model_1.AlertModel.find(query);
125
- if (filters.sort) {
126
- queryBuilder.sort(filters.sort);
127
- }
128
- else {
129
- queryBuilder.sort({ severity: -1, createdAt: -1 });
130
- }
131
- if (filters.skip)
132
- queryBuilder.skip(filters.skip);
133
- if (filters.limit)
134
- queryBuilder.limit(filters.limit);
135
- const results = await queryBuilder.exec();
139
+ const query = this.buildQuery(filters);
140
+ const options = this.buildOptions(filters);
141
+ const results = await Alert_model_1.AlertModel.find(query, null, options);
136
142
  return results.map((result) => result.toObject());
137
143
  }
138
144
  catch (error) {
@@ -184,7 +190,7 @@ let AlertRepository = (() => {
184
190
  */
185
191
  async count(filters = {}) {
186
192
  try {
187
- const query = await this.buildQuery(filters);
193
+ const query = this.buildQuery(filters);
188
194
  return await Alert_model_1.AlertModel.countDocuments(query);
189
195
  }
190
196
  catch (error) {
@@ -75,12 +75,12 @@ export interface IAlertQuery {
75
75
  severity?: AlertSeverity;
76
76
  entityType?: EntityType;
77
77
  entityId?: string;
78
- type?: AlertType;
78
+ type?: AlertType | AlertType[];
79
79
  isActive?: boolean;
80
80
  isRead?: boolean;
81
81
  includeDeleted?: boolean;
82
- startDate?: Date;
83
- endDate?: Date;
82
+ startDate?: string;
83
+ endDate?: string;
84
84
  sort?: {
85
85
  [key: string]: 1 | -1;
86
86
  };
@@ -5,6 +5,7 @@ export declare function getConfig(): IConfig;
5
5
  export declare function getDeviceServiceUrl(): string;
6
6
  export declare function getAdminServiceUrl(): string;
7
7
  export declare function getSqsQueueUrl(): string;
8
+ export declare function getReservationSqsQueueUrl(): string;
8
9
  export declare function getEventSubscription(): InternalEventSubscription | null;
9
10
  export declare function checkRequiredEnv(requiredEnvs: string[]): void;
10
11
  export declare function ensureAuditInitialized(): void;
@@ -8,6 +8,7 @@ exports.getConfig = getConfig;
8
8
  exports.getDeviceServiceUrl = getDeviceServiceUrl;
9
9
  exports.getAdminServiceUrl = getAdminServiceUrl;
10
10
  exports.getSqsQueueUrl = getSqsQueueUrl;
11
+ exports.getReservationSqsQueueUrl = getReservationSqsQueueUrl;
11
12
  exports.getEventSubscription = getEventSubscription;
12
13
  exports.checkRequiredEnv = checkRequiredEnv;
13
14
  exports.ensureAuditInitialized = ensureAuditInitialized;
@@ -149,6 +150,17 @@ function getSqsQueueUrl() {
149
150
  }
150
151
  throw new Error("dt-common-device: AWS_SQS_URL is not configured for this service");
151
152
  }
153
+ function getReservationSqsQueueUrl() {
154
+ if (constants_1.CONFIG_KEYS[sourceKey].env.includes("RESERVATION_SQS_URL")) {
155
+ const reservationSqsQueueUrl = process.env.RESERVATION_SQS_URL;
156
+ if (!reservationSqsQueueUrl) {
157
+ getConfig().LOGGER.error("RESERVATION_SQS_URL must be set in environment variables");
158
+ throw new Error("dt-common-device: RESERVATION_SQS_URL must be set in environment variables");
159
+ }
160
+ return reservationSqsQueueUrl;
161
+ }
162
+ return "";
163
+ }
152
164
  function getEventSubscription() {
153
165
  return eventSubscription;
154
166
  }
@@ -17,7 +17,13 @@ exports.REQUIRED = {
17
17
  };
18
18
  exports.CONFIG_KEYS = {
19
19
  ACCESS: {
20
- env: ["ADMIN_DB_URI", "PMS_DB_URI", "AWS_SQS_URL", "ADMIN_SERVICE"],
20
+ env: [
21
+ "ADMIN_DB_URI",
22
+ "PMS_DB_URI",
23
+ "AWS_SQS_URL",
24
+ "RESERVATION_SQS_URL",
25
+ "ADMIN_SERVICE",
26
+ ],
21
27
  INTERNAL_EVENT_HANDLER: true,
22
28
  db_keys: {
23
29
  access: "DATABASE_URL",
@@ -41,6 +41,7 @@ export declare const DT_EVENT_TYPES: {
41
41
  UNKNOWN: string;
42
42
  };
43
43
  BATTERY: {
44
+ REPLACED: string;
44
45
  STATE: {
45
46
  REPLACE: string;
46
47
  };
@@ -44,6 +44,7 @@ exports.DT_EVENT_TYPES = {
44
44
  UNKNOWN: "device.status.unknown",
45
45
  },
46
46
  BATTERY: {
47
+ REPLACED: "device.battery.replaced",
47
48
  STATE: {
48
49
  REPLACE: "device.battery.state.replace",
49
50
  },
@@ -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()
@@ -6,6 +6,7 @@ export declare class LocalDeviceService {
6
6
  private readonly deviceRepository;
7
7
  private readonly alertService;
8
8
  private readonly issueService;
9
+ private readonly localPropertyService;
9
10
  constructor();
10
11
  createDevice(body: IDevice): Promise<IDevice>;
11
12
  getDevice(deviceId: string, withHubDetails?: boolean): Promise<IDevice>;
@@ -83,6 +83,7 @@ const IAuditProperties_1 = require("../../../../audit/IAuditProperties");
83
83
  const constants_1 = require("../../../../constants");
84
84
  const audit_1 = require("../../../../audit");
85
85
  const issue_types_1 = require("../../../../issues/issue.types");
86
+ const property_1 = require("../../../property");
86
87
  let LocalDeviceService = (() => {
87
88
  let _classDecorators = [(0, typedi_1.Service)()];
88
89
  let _classDescriptor;
@@ -95,6 +96,7 @@ let LocalDeviceService = (() => {
95
96
  this.deviceRepository = typedi_1.default.get(Device_repository_1.DeviceRepository);
96
97
  this.alertService = typedi_1.default.get(Alert_service_1.AlertService);
97
98
  this.issueService = typedi_1.default.get(Issue_service_1.IssueService);
99
+ this.localPropertyService = typedi_1.default.get(property_1.LocalPropertyService);
98
100
  }
99
101
  async createDevice(body) {
100
102
  const device = await this.deviceRepository.createDevice(body);
@@ -355,6 +357,11 @@ let LocalDeviceService = (() => {
355
357
  // Save the battery level in the device
356
358
  await this.deviceRepository.setBatteryLevel(deviceId, batteryLevel);
357
359
  await this.eventHandler.onBatteryLevelChange(deviceId, batteryLevel, auditBody);
360
+ if (oldBatteryLevel?.value < batteryLevel &&
361
+ batteryLevel - oldBatteryLevel?.value > 10) {
362
+ // Battery level has increased (considering as battery has been replaced)
363
+ await this.eventHandler.onBatteryReplaced(deviceId, batteryLevel, auditBody);
364
+ }
358
365
  // Additional condition: if battery level is less than 50, update battery state to "replace"
359
366
  if (batteryLevel < 50) {
360
367
  const batteryState = {
@@ -402,11 +409,11 @@ let LocalDeviceService = (() => {
402
409
  }
403
410
  }
404
411
  async getPropertyBatteryThreshold(propertyId) {
405
- // TODO: Implement property battery threshold retrieval
406
- // This should return the battery threshold for the specific property
407
- // For now, returning a default value of 20%
408
- // In a real implementation, this would fetch from property configuration or settings
409
- return 20; // 20% default threshold
412
+ const preferences = await this.localPropertyService.getPropertyPreferences(propertyId, ["batteryPreference"]);
413
+ if (!preferences) {
414
+ return 20; // 20% default threshold
415
+ }
416
+ return preferences?.settings?.batteryPreference?.value ?? 20;
410
417
  }
411
418
  async checkForDeviceMalfunctions(device, source, reason) {
412
419
  // TODO: Implement device malfunction detection logic
@@ -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");
@@ -10,5 +10,6 @@ export declare class EventHandler {
10
10
  onStatusChangeMany(query: IStatusQuery, status: IStatus, auditProperties: IAuditProperties, eventType: any): Promise<void>;
11
11
  onBatteryLevelChange(deviceId: string, batteryLevel: number, auditProperties: IAuditProperties): Promise<void>;
12
12
  onBatteryStateChange(deviceId: string, batteryState: any, auditProperties: IAuditProperties): Promise<void>;
13
+ onBatteryReplaced(deviceId: string, batteryLevel: number, auditProperties: IAuditProperties): Promise<void>;
13
14
  onDeviceMetaChange(deviceId: string, metaData: Record<string, any>, auditProperties: IAuditProperties): Promise<void>;
14
15
  }
@@ -135,6 +135,16 @@ let EventHandler = (() => {
135
135
  },
136
136
  });
137
137
  }
138
+ async onBatteryReplaced(deviceId, batteryLevel, auditProperties) {
139
+ await (0, audit_1.pushAudit)({
140
+ auditType: Event_1.DT_EVENT_TYPES.DEVICE.BATTERY.REPLACED,
141
+ auditData: {
142
+ deviceId,
143
+ batteryLevel,
144
+ ...auditProperties,
145
+ },
146
+ });
147
+ }
138
148
  async onDeviceMetaChange(deviceId, metaData, auditProperties) {
139
149
  await (0, audit_1.pushAudit)({
140
150
  auditType: Event_1.DT_EVENT_TYPES.DEVICE.METADATA.UPDATED,
@@ -9,6 +9,7 @@ export declare enum InternalEventType {
9
9
  export declare class InternalEventSubscription {
10
10
  private readonly internalEventHandler;
11
11
  private readonly sqsQueueUrl;
12
+ private readonly reservationSqsQueueUrl;
12
13
  private readonly logger;
13
14
  private readonly isInitialized;
14
15
  private isSubscribed;
@@ -18,6 +18,7 @@ class InternalEventSubscription {
18
18
  this.isInitialized = false;
19
19
  this.isSubscribed = false;
20
20
  this.sqsQueueUrl = (0, config_1.getSqsQueueUrl)() || "";
21
+ this.reservationSqsQueueUrl = (0, config_1.getReservationSqsQueueUrl)() || "";
21
22
  this.logger = (0, config_1.getConfig)().LOGGER;
22
23
  this.isInitialized = true;
23
24
  }
@@ -85,6 +86,9 @@ class InternalEventSubscription {
85
86
  return;
86
87
  }
87
88
  try {
89
+ if (this.reservationSqsQueueUrl) {
90
+ await dt_pub_sub_1.eventDispatcher.subscribeToQueue(this.reservationSqsQueueUrl, this.handleMessage.bind(this));
91
+ }
88
92
  await dt_pub_sub_1.eventDispatcher.subscribeToQueue(this.sqsQueueUrl, this.handleMessage.bind(this));
89
93
  this.isSubscribed = true;
90
94
  this.logger.info("Successfully subscribed to internal events", {
@@ -14,7 +14,7 @@ interface IIssueModel extends Model<IIssueDocument, {}, IIssueMethods> {
14
14
  findOverdue(includeDeleted?: boolean): Promise<IIssueDocument[]>;
15
15
  findUpcoming(days?: number, includeDeleted?: boolean): Promise<IIssueDocument[]>;
16
16
  }
17
- declare const IssueSchema: mongoose.Schema<IIssueDocument, IIssueModel, IIssueMethods, {}, {}, {}, mongoose.DefaultSchemaOptions, IIssueDocument, mongoose.Document<unknown, {}, mongoose.FlatRecord<IIssueDocument>, {}> & Omit<mongoose.FlatRecord<IIssueDocument> & Required<{
17
+ declare const IssueSchema: mongoose.Schema<IIssueDocument, IIssueModel, IIssueMethods, {}, {}, {}, mongoose.DefaultSchemaOptions, IIssueDocument, mongoose.Document<unknown, {}, mongoose.FlatRecord<IIssueDocument>, {}, mongoose.ResolveSchemaOptions<mongoose.DefaultSchemaOptions>> & Omit<mongoose.FlatRecord<IIssueDocument> & Required<{
18
18
  _id: string;
19
19
  }> & {
20
20
  __v: number;
@@ -141,7 +141,6 @@ const IssueSchema = new mongoose_1.Schema({
141
141
  default: [],
142
142
  },
143
143
  }, {
144
- timestamps: true,
145
144
  collection: "dt_issues",
146
145
  toJSON: { virtuals: true },
147
146
  toObject: { virtuals: true },
@@ -2,6 +2,7 @@ import { IIssueDocument } from "./Issue.model";
2
2
  import { CreateIssueData, UpdateIssueData, IssuePriority, IssuesCategory, IIssueQuery } from "./issue.types";
3
3
  export declare class IssueRepository {
4
4
  private buildQuery;
5
+ private buildOptions;
5
6
  /**
6
7
  * Create a new issue
7
8
  */
@@ -48,7 +48,7 @@ let IssueRepository = (() => {
48
48
  let _classExtraInitializers = [];
49
49
  let _classThis;
50
50
  var IssueRepository = _classThis = class {
51
- async buildQuery(filters) {
51
+ buildQuery(filters) {
52
52
  const query = {};
53
53
  if (filters.propertyId)
54
54
  query.propertyId = filters.propertyId;
@@ -68,25 +68,35 @@ let IssueRepository = (() => {
68
68
  query.entitySubType = filters.entitySubType;
69
69
  if (filters.entityId)
70
70
  query.entityId = filters.entityId;
71
- if (filters.type)
72
- query.type = filters.type;
71
+ if (filters.type) {
72
+ if (Array.isArray(filters.type)) {
73
+ query.type = { $in: filters.type };
74
+ }
75
+ else {
76
+ query.type = filters.type;
77
+ }
78
+ }
73
79
  if (!filters.includeDeleted)
74
80
  query.isDeleted = false;
75
81
  // Date filtering
76
82
  if (filters.startDate || filters.endDate) {
77
83
  query.createdAt = {};
78
84
  if (filters.startDate)
79
- query.createdAt.$gte = filters.startDate;
85
+ query.createdAt.$gte = new Date(filters.startDate);
80
86
  if (filters.endDate)
81
- query.createdAt.$lte = filters.endDate;
87
+ query.createdAt.$lte = new Date(filters.endDate);
82
88
  }
89
+ return query;
90
+ }
91
+ buildOptions(filters) {
92
+ const options = {};
83
93
  if (filters.sort)
84
- query.sort = filters.sort;
94
+ options.sort = filters.sort;
85
95
  if (filters.limit)
86
- query.limit = filters.limit;
96
+ options.limit = filters.limit;
87
97
  if (filters.skip)
88
- query.skip = filters.skip;
89
- return query;
98
+ options.skip = filters.skip;
99
+ return options;
90
100
  }
91
101
  /**
92
102
  * Create a new issue
@@ -126,19 +136,9 @@ let IssueRepository = (() => {
126
136
  */
127
137
  async query(filters = {}) {
128
138
  try {
129
- const query = await this.buildQuery(filters);
130
- const queryBuilder = Issue_model_1.IssueModel.find(query);
131
- if (filters.sort) {
132
- queryBuilder.sort(filters.sort);
133
- }
134
- else {
135
- queryBuilder.sort({ createdAt: -1 });
136
- }
137
- if (filters.skip)
138
- queryBuilder.skip(filters.skip);
139
- if (filters.limit)
140
- queryBuilder.limit(filters.limit);
141
- const results = await queryBuilder.exec();
139
+ const query = this.buildQuery(filters);
140
+ const options = this.buildOptions(filters);
141
+ const results = await Issue_model_1.IssueModel.find(query, null, options);
142
142
  return results.map((result) => result.toObject());
143
143
  }
144
144
  catch (error) {
@@ -190,7 +190,7 @@ let IssueRepository = (() => {
190
190
  */
191
191
  async count(filters = {}) {
192
192
  try {
193
- const query = await this.buildQuery(filters);
193
+ const query = this.buildQuery(filters);
194
194
  return await Issue_model_1.IssueModel.countDocuments(query);
195
195
  }
196
196
  catch (error) {
@@ -124,14 +124,14 @@ export interface IIssueQuery {
124
124
  assignedTo?: string;
125
125
  status?: IssueStatus;
126
126
  priority?: IssuePriority;
127
- type?: IssueType;
127
+ type?: IssueType | IssueType[];
128
128
  category?: IssuesCategory;
129
129
  entityType?: EntityType;
130
130
  entitySubType?: EntitySubType;
131
131
  entityId?: string;
132
132
  includeDeleted?: boolean;
133
- startDate?: Date;
134
- endDate?: Date;
133
+ startDate?: string;
134
+ endDate?: string;
135
135
  limit?: number;
136
136
  skip?: number;
137
137
  sort?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "7.2.7",
3
+ "version": "7.4.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
- }