dt-common-device 12.0.2 → 12.0.4

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.
@@ -4,5 +4,7 @@ export declare class ConnectionRepository {
4
4
  constructor();
5
5
  createConnection(data: Partial<IConnection>): Promise<IConnection>;
6
6
  getConnectionById(connectionId: string): Promise<IConnection>;
7
+ getConnectionsByPropertyId(propertyId: string): Promise<IConnection[]>;
8
+ queryConnections(query: Partial<IConnection>): Promise<IConnection[]>;
7
9
  updateConnection(connectionId: string, data: Partial<IConnection>): Promise<any>;
8
10
  }
@@ -69,6 +69,34 @@ let ConnectionRepository = (() => {
69
69
  const result = await this.pool.query("SELECT * FROM dt_connections WHERE id = $1", [connectionId]);
70
70
  return result.rows[0];
71
71
  }
72
+ async getConnectionsByPropertyId(propertyId) {
73
+ const result = await this.pool.query("SELECT * FROM dt_connections WHERE propertyId = $1", [propertyId]);
74
+ if (result.rows.length === 0)
75
+ return [];
76
+ return result.rows;
77
+ }
78
+ async queryConnections(query) {
79
+ // Filter out undefined/null values and build WHERE clause
80
+ const conditions = [];
81
+ const values = [];
82
+ let paramIndex = 1;
83
+ // Build conditions dynamically based on provided query parameters
84
+ Object.keys(query).forEach((key) => {
85
+ const value = query[key];
86
+ if (value !== undefined && value !== null) {
87
+ conditions.push(`"${key}" = $${paramIndex}`);
88
+ values.push(value);
89
+ paramIndex++;
90
+ }
91
+ });
92
+ // Build the SQL query
93
+ let sql = "SELECT * FROM dt_connections";
94
+ if (conditions.length > 0) {
95
+ sql += ` WHERE ${conditions.join(" AND ")}`;
96
+ }
97
+ const result = await this.pool.query(sql, values);
98
+ return result.rows;
99
+ }
72
100
  async updateConnection(connectionId, data) {
73
101
  // Build dynamic SET clause with quoted column names
74
102
  const setClause = Object.keys(data)
@@ -4,5 +4,7 @@ export declare class LocalConnectionService {
4
4
  constructor();
5
5
  createConnection(data: Partial<IConnection>): Promise<IConnection>;
6
6
  getConnection(connectionId: string): Promise<IConnection>;
7
+ getConnectionsByPropertyId(propertyId: string): Promise<IConnection[]>;
8
+ queryConnections(query: Partial<IConnection>): Promise<IConnection[]>;
7
9
  updateConnection(connectionId: string, data: Partial<IConnection>): Promise<IConnection>;
8
10
  }
@@ -22,6 +22,18 @@ class LocalConnectionService {
22
22
  }
23
23
  return await this.connectionRepository.getConnectionById(connectionId);
24
24
  }
25
+ async getConnectionsByPropertyId(propertyId) {
26
+ if (!propertyId) {
27
+ throw new Error("Property ID is required");
28
+ }
29
+ return await this.connectionRepository.getConnectionsByPropertyId(propertyId);
30
+ }
31
+ async queryConnections(query) {
32
+ if (!query || Object.keys(query).length === 0) {
33
+ throw new Error("Query is required");
34
+ }
35
+ return await this.connectionRepository.queryConnections(query);
36
+ }
25
37
  async updateConnection(connectionId, data) {
26
38
  if (!connectionId) {
27
39
  throw new Error("Connection ID is required");
@@ -239,7 +239,7 @@ let IssueService = (() => {
239
239
  title: device.deviceType.type.toLowerCase() === "hub"
240
240
  ? "Hub Offline"
241
241
  : "Device Offline",
242
- description: `${device.name} has gone offline. ${reason ? `Reason: ${reason}.` : ""}`,
242
+ description: `${device.name} has gone offline ${reason ? `Reason: ${reason}` : ""}.`,
243
243
  createdBy: source,
244
244
  category: issue_types_1.IssuesCategory.OPERATIONS,
245
245
  priority: issue_types_1.IssuePriority.CRITICAL,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "12.0.2",
3
+ "version": "12.0.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [