dt-common-device 11.1.10 → 11.2.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.
@@ -3,8 +3,9 @@ export declare class AdminRepository {
3
3
  private readonly deviceRepository;
4
4
  private readonly postgres;
5
5
  private readonly localDeviceService;
6
+ private readonly redisUtils;
6
7
  constructor();
7
- getZonesByAccessGroupIds(accessGroupIds: string[]): Promise<any[]>;
8
+ getZonesByAccessGroupIds(accessGroupIds: string[], propertyId: string): Promise<any[]>;
8
9
  getZonesByAccessGroups(accessGroupIds: string[]): Promise<any[]>;
9
10
  getAccessGroup(accessGroupId: string, propertyId?: string): Promise<IAccessGroup | null>;
10
11
  getZoneAccessGroupByZoneId(zoneId: string): Promise<IZoneAccessGroup[] | null>;
@@ -78,6 +78,7 @@ 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");
81
82
  let AdminRepository = (() => {
82
83
  let _classDecorators = [(0, typedi_1.Service)()];
83
84
  let _classDescriptor;
@@ -88,25 +89,9 @@ let AdminRepository = (() => {
88
89
  this.deviceRepository = typedi_1.default.get(Device_repository_1.DeviceRepository);
89
90
  this.postgres = (0, db_1.getPostgresClient)();
90
91
  this.localDeviceService = typedi_1.default.get(services_1.LocalDeviceService);
92
+ this.redisUtils = typedi_1.default.get(utils_1.RedisUtils);
91
93
  }
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
- // }
94
+ async getZonesByAccessGroupIds(accessGroupIds, propertyId) {
110
95
  // If not cached, get the result from the database
111
96
  const result = await this.postgres.query(`SELECT
112
97
  "zc"."id" AS "zoneCollectionMapId",
@@ -140,7 +125,18 @@ let AdminRepository = (() => {
140
125
  const collectionZone = [];
141
126
  for (let zone of response) {
142
127
  let zoneIds = [];
143
- const zones = (await (0, utils_1.getAdminServiceAxiosInstance)().get(`/zones/child?zoneId=${zone.zoneId}`))?.data?.data;
128
+ let zones = null;
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
+ }
144
140
  zoneIds.push(zone.zoneId);
145
141
  if (zones.childZones?.length > 0) {
146
142
  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[]): Promise<any[] | undefined>;
6
+ getZonesByAccessGroupIds(accessGroupIds: string[], propertyId: 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, propertyId) {
89
89
  try {
90
- return await this.adminRepository.getZonesByAccessGroupIds(accessGroupIds);
90
+ return await this.adminRepository.getZonesByAccessGroupIds(accessGroupIds, propertyId);
91
91
  }
92
92
  catch (error) {
93
93
  console.log(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "11.1.10",
3
+ "version": "11.2.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [