dt-common-device 13.8.1 → 13.8.2

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.
@@ -7,4 +7,5 @@ export declare class ConnectionRepository {
7
7
  getConnectionsByPropertyId(propertyId: string): Promise<IConnection[]>;
8
8
  queryConnections(query: Partial<IConnection>): Promise<IConnection[]>;
9
9
  updateConnection(connectionId: string, data: Partial<IConnection>): Promise<any>;
10
+ update(connectionId: string, propertyId: string, data: Partial<IConnection>): Promise<any>;
10
11
  }
@@ -114,6 +114,25 @@ let ConnectionRepository = (() => {
114
114
  const result = await this.pool.query(`UPDATE dt_connections SET ${setClause}, "updatedAt" = NOW() WHERE id = $1 RETURNING *`, [connectionId, ...values]);
115
115
  return result.rows[0];
116
116
  }
117
+ async update(connectionId, propertyId, data) {
118
+ // Prevent invalid query if no fields provided
119
+ if (!data || Object.keys(data).length === 0) {
120
+ return null;
121
+ }
122
+ // Build dynamic SET clause
123
+ const setClause = Object.keys(data)
124
+ .map((key, index) => `"${key}" = $${index + 3}`)
125
+ .join(", ");
126
+ const values = Object.values(data);
127
+ const result = await this.pool.query(`UPDATE dt_connections
128
+ SET ${setClause}, "updatedAt" = NOW()
129
+ WHERE id = $1 AND "propertyId" = $2
130
+ RETURNING *`, [connectionId, propertyId, ...values]);
131
+ if (result.rowCount === 0) {
132
+ return null;
133
+ }
134
+ return result.rows[0];
135
+ }
117
136
  };
118
137
  __setFunctionName(_classThis, "ConnectionRepository");
119
138
  (() => {
@@ -1,10 +1,15 @@
1
1
  import { IConnection } from "./IConnection";
2
2
  export declare class LocalConnectionService {
3
3
  private readonly connectionRepository;
4
+ private readonly redisUtils;
4
5
  constructor();
5
6
  createConnection(data: Partial<IConnection>): Promise<IConnection>;
6
7
  getConnection(connectionId: string): Promise<IConnection>;
7
8
  getConnectionsByPropertyId(propertyId: string): Promise<IConnection[]>;
8
9
  queryConnections(query: Partial<IConnection>): Promise<IConnection[]>;
9
10
  updateConnection(connectionId: string, data: Partial<IConnection>): Promise<IConnection>;
11
+ update(data: {
12
+ connectionId: string;
13
+ propertyId: string;
14
+ }, dataToUpdate: Partial<IConnection>): Promise<IConnection>;
10
15
  }
@@ -41,6 +41,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.LocalConnectionService = void 0;
42
42
  const typedi_1 = require("typedi");
43
43
  const Connection_repository_1 = require("./Connection.repository");
44
+ const utils_1 = require("../../utils");
44
45
  let LocalConnectionService = (() => {
45
46
  let _classDecorators = [(0, typedi_1.Service)()];
46
47
  let _classDescriptor;
@@ -49,6 +50,7 @@ let LocalConnectionService = (() => {
49
50
  var LocalConnectionService = _classThis = class {
50
51
  constructor() {
51
52
  this.connectionRepository = typedi_1.Container.get(Connection_repository_1.ConnectionRepository);
53
+ this.redisUtils = typedi_1.Container.get(utils_1.RedisUtils);
52
54
  }
53
55
  async createConnection(data) {
54
56
  if (!data.connectionName ||
@@ -81,7 +83,19 @@ let LocalConnectionService = (() => {
81
83
  if (!connectionId) {
82
84
  throw new Error("Connection ID is required");
83
85
  }
84
- return await this.connectionRepository.updateConnection(connectionId, data);
86
+ const connection = await this.connectionRepository.updateConnection(connectionId, data);
87
+ await this.redisUtils.del(`connection:${connectionId}`);
88
+ await this.redisUtils.del(`property_connections:${connection.propertyId}`);
89
+ return connection;
90
+ }
91
+ async update(data, dataToUpdate) {
92
+ if (!data.connectionId || !data.propertyId) {
93
+ throw new Error("Connection ID and Property ID are required");
94
+ }
95
+ const connection = await this.connectionRepository.update(data.connectionId, data.propertyId, dataToUpdate);
96
+ await this.redisUtils.del(`connection:${data.connectionId}`);
97
+ await this.redisUtils.del(`property_connections:${data.propertyId}`);
98
+ return connection;
85
99
  }
86
100
  };
87
101
  __setFunctionName(_classThis, "LocalConnectionService");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "13.8.1",
3
+ "version": "13.8.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [