dt-common-device 14.0.0 → 14.0.1

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
  }
@@ -106,6 +106,25 @@ let ConnectionRepository = (() => {
106
106
  const result = await this.pool.query(`UPDATE dt_connections SET ${setClause}, "updatedAt" = NOW() WHERE id = $1 RETURNING *`, [connectionId, ...values]);
107
107
  return result.rows[0];
108
108
  }
109
+ async update(connectionId, propertyId, data) {
110
+ // Prevent invalid query if no fields provided
111
+ if (!data || Object.keys(data).length === 0) {
112
+ return null;
113
+ }
114
+ // Build dynamic SET clause
115
+ const setClause = Object.keys(data)
116
+ .map((key, index) => `"${key}" = $${index + 3}`)
117
+ .join(", ");
118
+ const values = Object.values(data);
119
+ const result = await this.pool.query(`UPDATE dt_connections
120
+ SET ${setClause}, "updatedAt" = NOW()
121
+ WHERE id = $1 AND "propertyId" = $2
122
+ RETURNING *`, [connectionId, propertyId, ...values]);
123
+ if (result.rowCount === 0) {
124
+ return null;
125
+ }
126
+ return result.rows[0];
127
+ }
109
128
  };
110
129
  __setFunctionName(_classThis, "ConnectionRepository");
111
130
  (() => {
@@ -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": "14.0.0",
3
+ "version": "14.0.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [