dt-common-device 12.0.0 → 12.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.
- package/dist/entities/admin/Admin.repository.d.ts +1 -2
- package/dist/entities/admin/Admin.repository.js +19 -15
- package/dist/entities/admin/Admin.service.d.ts +1 -1
- package/dist/entities/admin/Admin.service.js +2 -2
- package/dist/entities/connection/Connection.repository.d.ts +1 -0
- package/dist/entities/connection/Connection.repository.js +22 -0
- package/dist/entities/connection/Connection.service.d.ts +1 -0
- package/dist/entities/connection/Connection.service.js +3 -0
- package/dist/issues/Issue.service.js +1 -1
- package/package.json +1 -1
|
@@ -3,9 +3,8 @@ export declare class AdminRepository {
|
|
|
3
3
|
private readonly deviceRepository;
|
|
4
4
|
private readonly postgres;
|
|
5
5
|
private readonly localDeviceService;
|
|
6
|
-
private readonly redisUtils;
|
|
7
6
|
constructor();
|
|
8
|
-
getZonesByAccessGroupIds(accessGroupIds: string[]
|
|
7
|
+
getZonesByAccessGroupIds(accessGroupIds: string[]): Promise<any[]>;
|
|
9
8
|
getZonesByAccessGroups(accessGroupIds: string[]): Promise<any[]>;
|
|
10
9
|
getAccessGroup(accessGroupId: string, propertyId?: string): Promise<IAccessGroup | null>;
|
|
11
10
|
getZoneAccessGroupByZoneId(zoneId: string): Promise<IZoneAccessGroup[] | null>;
|
|
@@ -78,7 +78,6 @@ const Device_repository_1 = require("../device/local/repository/Device.repositor
|
|
|
78
78
|
const db_1 = require("../../db/db");
|
|
79
79
|
const interfaces_1 = require("../device/cloud/interfaces");
|
|
80
80
|
const services_1 = require("../device/local/services");
|
|
81
|
-
const config_1 = require("../../config/config");
|
|
82
81
|
let AdminRepository = (() => {
|
|
83
82
|
let _classDecorators = [(0, typedi_1.Service)()];
|
|
84
83
|
let _classDescriptor;
|
|
@@ -89,9 +88,25 @@ let AdminRepository = (() => {
|
|
|
89
88
|
this.deviceRepository = typedi_1.default.get(Device_repository_1.DeviceRepository);
|
|
90
89
|
this.postgres = (0, db_1.getPostgresClient)();
|
|
91
90
|
this.localDeviceService = typedi_1.default.get(services_1.LocalDeviceService);
|
|
92
|
-
this.redisUtils = typedi_1.default.get(utils_1.RedisUtils);
|
|
93
91
|
}
|
|
94
|
-
async getZonesByAccessGroupIds(accessGroupIds
|
|
92
|
+
async getZonesByAccessGroupIds(accessGroupIds) {
|
|
93
|
+
// // Get propertyId from any of the accessGroupIds
|
|
94
|
+
// const accessGroupIdsResult = await this.postgres.query(
|
|
95
|
+
// `SELECT "propertyId" FROM dt_collections WHERE "id" = ANY($1) LIMIT 1`,
|
|
96
|
+
// [accessGroupIds]
|
|
97
|
+
// );
|
|
98
|
+
// const propertyId = accessGroupIdsResult.rows[0].propertyId;
|
|
99
|
+
// const sortedAccessGroupIds = [...accessGroupIds].sort((a, b) =>
|
|
100
|
+
// a.localeCompare(b)
|
|
101
|
+
// );
|
|
102
|
+
// // Check if the result is already cached
|
|
103
|
+
// const redisKey = `${propertyId}:zonesAndDevicesByAccessGroupIds:${sortedAccessGroupIds.join(
|
|
104
|
+
// ","
|
|
105
|
+
// )}`;
|
|
106
|
+
// const cachedResult = await this.redisUtils.get(redisKey);
|
|
107
|
+
// if (cachedResult) {
|
|
108
|
+
// return JSON.parse(cachedResult);
|
|
109
|
+
// }
|
|
95
110
|
// If not cached, get the result from the database
|
|
96
111
|
const result = await this.postgres.query(`SELECT
|
|
97
112
|
"zc"."id" AS "zoneCollectionMapId",
|
|
@@ -125,18 +140,7 @@ let AdminRepository = (() => {
|
|
|
125
140
|
const collectionZone = [];
|
|
126
141
|
for (let zone of response) {
|
|
127
142
|
let zoneIds = [];
|
|
128
|
-
|
|
129
|
-
const redisKey = `${propertyId}:childZones:${zone.zoneId}`;
|
|
130
|
-
const zonesCache = await this.redisUtils.get(redisKey);
|
|
131
|
-
if (zonesCache !== null && zonesCache !== undefined) {
|
|
132
|
-
(0, config_1.getLogger)().info(`Got child zones from redis`);
|
|
133
|
-
zones = JSON.parse(zonesCache);
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
const response = await (0, utils_1.getAdminServiceAxiosInstance)().get(`/zones/child?zoneId=${zone.zoneId}`);
|
|
137
|
-
zones = response?.data?.data;
|
|
138
|
-
await this.redisUtils.set(redisKey, JSON.stringify(zones), 86400);
|
|
139
|
-
}
|
|
143
|
+
const zones = (await (0, utils_1.getAdminServiceAxiosInstance)().get(`/zones/child?zoneId=${zone.zoneId}`))?.data?.data;
|
|
140
144
|
zoneIds.push(zone.zoneId);
|
|
141
145
|
if (zones.childZones?.length > 0) {
|
|
142
146
|
const nestedZoneIds = new Set(_zones(zones.childZones));
|
|
@@ -3,7 +3,7 @@ export declare class AdminService {
|
|
|
3
3
|
private readonly adminRepository;
|
|
4
4
|
private readonly redisUtils;
|
|
5
5
|
constructor();
|
|
6
|
-
getZonesByAccessGroupIds(accessGroupIds: string[]
|
|
6
|
+
getZonesByAccessGroupIds(accessGroupIds: string[]): Promise<any[] | undefined>;
|
|
7
7
|
getZonesByAccessGroups(accessGroupIds: string[]): Promise<any[] | undefined>;
|
|
8
8
|
getAccessGroup(accessGroupId: string, propertyId?: string): Promise<IAccessGroup | null>;
|
|
9
9
|
getAccessGroupByZoneId(zoneId: string): Promise<IAccessGroup[] | []>;
|
|
@@ -85,9 +85,9 @@ let AdminService = (() => {
|
|
|
85
85
|
this.adminRepository = typedi_1.default.get(Admin_repository_1.AdminRepository);
|
|
86
86
|
this.redisUtils = typedi_1.default.get(redis_utils_1.RedisUtils);
|
|
87
87
|
}
|
|
88
|
-
async getZonesByAccessGroupIds(accessGroupIds
|
|
88
|
+
async getZonesByAccessGroupIds(accessGroupIds) {
|
|
89
89
|
try {
|
|
90
|
-
return await this.adminRepository.getZonesByAccessGroupIds(accessGroupIds
|
|
90
|
+
return await this.adminRepository.getZonesByAccessGroupIds(accessGroupIds);
|
|
91
91
|
}
|
|
92
92
|
catch (error) {
|
|
93
93
|
console.log(error);
|
|
@@ -4,5 +4,6 @@ export declare class ConnectionRepository {
|
|
|
4
4
|
constructor();
|
|
5
5
|
createConnection(data: Partial<IConnection>): Promise<IConnection>;
|
|
6
6
|
getConnectionById(connectionId: string): Promise<IConnection>;
|
|
7
|
+
queryConnections(query: Partial<IConnection>): Promise<IConnection[]>;
|
|
7
8
|
updateConnection(connectionId: string, data: Partial<IConnection>): Promise<any>;
|
|
8
9
|
}
|
|
@@ -69,6 +69,28 @@ 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 queryConnections(query) {
|
|
73
|
+
// Filter out undefined/null values and build WHERE clause
|
|
74
|
+
const conditions = [];
|
|
75
|
+
const values = [];
|
|
76
|
+
let paramIndex = 1;
|
|
77
|
+
// Build conditions dynamically based on provided query parameters
|
|
78
|
+
Object.keys(query).forEach((key) => {
|
|
79
|
+
const value = query[key];
|
|
80
|
+
if (value !== undefined && value !== null) {
|
|
81
|
+
conditions.push(`"${key}" = $${paramIndex}`);
|
|
82
|
+
values.push(value);
|
|
83
|
+
paramIndex++;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
// Build the SQL query
|
|
87
|
+
let sql = "SELECT * FROM dt_connections";
|
|
88
|
+
if (conditions.length > 0) {
|
|
89
|
+
sql += ` WHERE ${conditions.join(" AND ")}`;
|
|
90
|
+
}
|
|
91
|
+
const result = await this.pool.query(sql, values);
|
|
92
|
+
return result.rows;
|
|
93
|
+
}
|
|
72
94
|
async updateConnection(connectionId, data) {
|
|
73
95
|
// Build dynamic SET clause with quoted column names
|
|
74
96
|
const setClause = Object.keys(data)
|
|
@@ -4,5 +4,6 @@ export declare class LocalConnectionService {
|
|
|
4
4
|
constructor();
|
|
5
5
|
createConnection(data: Partial<IConnection>): Promise<IConnection>;
|
|
6
6
|
getConnection(connectionId: string): Promise<IConnection>;
|
|
7
|
+
queryConnections(query: Partial<IConnection>): Promise<IConnection[]>;
|
|
7
8
|
updateConnection(connectionId: string, data: Partial<IConnection>): Promise<IConnection>;
|
|
8
9
|
}
|
|
@@ -22,6 +22,9 @@ class LocalConnectionService {
|
|
|
22
22
|
}
|
|
23
23
|
return await this.connectionRepository.getConnectionById(connectionId);
|
|
24
24
|
}
|
|
25
|
+
async queryConnections(query) {
|
|
26
|
+
return await this.connectionRepository.queryConnections(query);
|
|
27
|
+
}
|
|
25
28
|
async updateConnection(connectionId, data) {
|
|
26
29
|
if (!connectionId) {
|
|
27
30
|
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
|
|
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,
|