dt-common-device 7.0.0 → 7.1.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.
@@ -1,10 +1,11 @@
1
- import { IAccessGroup, IUser, IZone } from "./IAdmin";
1
+ import { IAccessGroup, IUser, IZone, IZoneAccessGroup } from "./IAdmin";
2
2
  export declare class AdminRepository {
3
3
  private readonly deviceRepository;
4
4
  private readonly postgres;
5
5
  constructor();
6
6
  getZonesByAccessGroupIds(accessGroupIds: string[]): Promise<any[]>;
7
7
  getAccessGroup(accessGroupId: string): Promise<IAccessGroup | null>;
8
+ getZoneAccessGroupByZoneId(zoneId: string): Promise<IZoneAccessGroup | null>;
8
9
  getZone(zoneId: string): Promise<IZone | null>;
9
10
  getUser(userId: string): Promise<IUser | null>;
10
11
  }
@@ -176,6 +176,17 @@ let AdminRepository = (() => {
176
176
  }
177
177
  return null;
178
178
  }
179
+ async getZoneAccessGroupByZoneId(zoneId) {
180
+ const query = `
181
+ SELECT * FROM dt_zones_collection_map
182
+ WHERE "zoneId" = $1
183
+ `;
184
+ const result = await this.postgres.query(query, [zoneId]);
185
+ if (result.rows.length > 0) {
186
+ return result.rows[0];
187
+ }
188
+ return null;
189
+ }
179
190
  async getZone(zoneId) {
180
191
  try {
181
192
  const zone = await this.postgres.query(`SELECT * FROM dt_zones WHERE "id" = $1`, [zoneId]);
@@ -4,6 +4,7 @@ export declare class AdminService {
4
4
  constructor();
5
5
  getZonesByAccessGroupIds(accessGroupIds: string[]): Promise<any[] | undefined>;
6
6
  getAccessGroup(accessGroupId: string): Promise<IAccessGroup | null>;
7
+ getAccessGroupByZoneId(zoneId: string): Promise<IAccessGroup | null>;
7
8
  getZone(zoneId: string): Promise<IZone | null>;
8
9
  getUser(userId: string): Promise<IUser | null>;
9
10
  }
@@ -100,6 +100,18 @@ let AdminService = (() => {
100
100
  return null;
101
101
  return accessGroup;
102
102
  }
103
+ async getAccessGroupByZoneId(zoneId) {
104
+ if (!zoneId) {
105
+ throw new Error("Zone ID is required");
106
+ }
107
+ const zoneAccessGroup = await this.adminRepository.getZoneAccessGroupByZoneId(zoneId);
108
+ if (!zoneAccessGroup)
109
+ return null;
110
+ const accessGroup = await this.adminRepository.getAccessGroup(zoneAccessGroup.collectionId);
111
+ if (!accessGroup)
112
+ return null;
113
+ return accessGroup;
114
+ }
103
115
  async getZone(zoneId) {
104
116
  if (!zoneId) {
105
117
  throw new Error("Zone ID is required");
@@ -12,6 +12,11 @@ export interface IAccessGroup {
12
12
  updatedAt: Date;
13
13
  accessibleBy: string[];
14
14
  }
15
+ export interface IZoneAccessGroup {
16
+ id: string;
17
+ zoneId: string;
18
+ collectionId: string;
19
+ }
15
20
  export interface IZone {
16
21
  id: string;
17
22
  name: string;
@@ -3,6 +3,7 @@ export declare class PmsRepository {
3
3
  private readonly pmsPostgres;
4
4
  constructor();
5
5
  getSchedule(scheduleId: string): Promise<IPmsSchedule | null>;
6
+ getScheduleIdByAccessGroupId(accessGroupId: string, status: string): Promise<string | null>;
6
7
  getGuest(guestId: string): Promise<IGuest | null>;
7
8
  getGuestId(scheduleId: string): Promise<string | null>;
8
9
  }
@@ -63,6 +63,14 @@ let PmsRepository = (() => {
63
63
  throw new Error("Failed to get schedule");
64
64
  }
65
65
  }
66
+ async getScheduleIdByAccessGroupId(accessGroupId, status) {
67
+ const scheduleId = await this.pmsPostgres.query(`SELECT "scheduleId" FROM dt_schedule_accessgroup_map WHERE "accessGroupId" = $1 AND "status" = $2`, [accessGroupId, status]);
68
+ //TODO: Need to Check if only one Schedule is there for the given Access Group in checked-in state!
69
+ if (scheduleId.rows.length > 0) {
70
+ return scheduleId.rows[0].scheduleId;
71
+ }
72
+ return null;
73
+ }
66
74
  async getGuest(guestId) {
67
75
  try {
68
76
  const guest = await this.pmsPostgres.query(`SELECT * FROM dt_guest WHERE "id" = $1`, [guestId]);
@@ -3,6 +3,7 @@ export declare class PmsService {
3
3
  private readonly pmsRepository;
4
4
  constructor();
5
5
  getSchedule(scheduleId: string): Promise<IPmsSchedule | null>;
6
+ getScheduleIdByAccessGroupId(accessGroupId: string, status: string): Promise<string | null>;
6
7
  getGuest(guestId: string): Promise<IGuest | null>;
7
8
  getGuestId(scheduleId: string): Promise<string | null>;
8
9
  }
@@ -92,6 +92,15 @@ let PmsService = (() => {
92
92
  return null;
93
93
  return schedule;
94
94
  }
95
+ async getScheduleIdByAccessGroupId(accessGroupId, status) {
96
+ if (!accessGroupId) {
97
+ throw new Error("Access Group ID is required");
98
+ }
99
+ const scheduleId = await this.pmsRepository.getScheduleIdByAccessGroupId(accessGroupId, status);
100
+ if (!scheduleId)
101
+ return null;
102
+ return scheduleId;
103
+ }
95
104
  async getGuest(guestId) {
96
105
  if (!guestId) {
97
106
  throw new Error("Guest ID is required");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "7.0.0",
3
+ "version": "7.1.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [