dt-common-device 3.0.9 → 3.0.11

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.
Files changed (144) hide show
  1. package/dist/config/config.d.ts +1 -2
  2. package/dist/config/config.js +4 -5
  3. package/dist/device/cloud/interface.d.ts +101 -0
  4. package/dist/device/cloud/interface.js +3 -0
  5. package/dist/device/cloud/interfaces/IDeviceConnectionService.d.ts +7 -0
  6. package/dist/device/cloud/interfaces/IDeviceConnectionService.js +3 -0
  7. package/dist/device/cloud/interfaces/IDevicesService.d.ts +9 -0
  8. package/dist/device/cloud/services/Device.service.d.ts +39 -0
  9. package/dist/device/cloud/services/Device.service.js +9 -0
  10. package/dist/device/cloud/services/DeviceCloudService.d.ts +42 -0
  11. package/dist/device/cloud/services/DeviceCloudService.js +59 -0
  12. package/dist/device/cloud/services/DeviceHub.service.d.ts +3 -0
  13. package/dist/device/cloud/services/DeviceHub.service.js +6 -0
  14. package/dist/device/cloud/services/Hub.service.d.ts +25 -0
  15. package/dist/device/cloud/services/Hub.service.js +9 -0
  16. package/dist/device/cloud/services/SmartThingsDeviceService.d.ts +38 -0
  17. package/dist/device/cloud/services/SmartThingsDeviceService.js +52 -0
  18. package/dist/device/index.d.ts +4 -0
  19. package/dist/device/index.js +20 -0
  20. package/dist/device/local/events/EventHandler.js +6 -6
  21. package/dist/device/local/events/Events.d.ts +12 -33
  22. package/dist/device/local/events/Events.js +12 -33
  23. package/dist/device/local/interface.d.ts +0 -0
  24. package/dist/device/local/interface.js +1 -0
  25. package/dist/device/local/interfaces/IDevice.d.ts +1 -0
  26. package/dist/device/local/repository/Schedule.repository.d.ts +0 -1
  27. package/dist/device/local/repository/Schedule.repository.js +6 -6
  28. package/dist/device/local/services/DeviceHub.service.d.ts +11 -0
  29. package/dist/device/local/services/DeviceHub.service.js +40 -0
  30. package/dist/queue/entities/HybridHttpQueue.d.ts +4 -14
  31. package/dist/queue/entities/HybridHttpQueue.js +31 -119
  32. package/dist/queue/interfaces/IHybridHttpQueue.d.ts +2 -12
  33. package/dist/queue/interfaces/IJobResult.d.ts +1 -8
  34. package/dist/queue/interfaces/index.d.ts +0 -1
  35. package/dist/queue/interfaces/index.js +0 -1
  36. package/dist/queue/services/QueueService.d.ts +2 -12
  37. package/dist/queue/types/queue.types.d.ts +10 -29
  38. package/dist/queue/utils/jobUtils.d.ts +0 -3
  39. package/dist/queue/utils/jobUtils.js +0 -48
  40. package/dist/queue/utils/queueUtils.d.ts +7 -0
  41. package/dist/queue/utils/queueUtils.js +113 -4
  42. package/package.json +6 -1
  43. package/.eslintrc.js +0 -44
  44. package/dist/audit/AuditProperties.d.ts +0 -16
  45. package/dist/audit/AuditUtils.d.ts +0 -2
  46. package/dist/audit/AuditUtils.js +0 -36
  47. package/src/alerts/Alert.model.ts +0 -289
  48. package/src/alerts/Alert.repository.ts +0 -487
  49. package/src/alerts/Alert.service.ts +0 -711
  50. package/src/alerts/AlertBuilder.example.ts +0 -126
  51. package/src/alerts/AlertBuilder.ts +0 -208
  52. package/src/alerts/AlertService.example.ts +0 -232
  53. package/src/alerts/alert.types.ts +0 -64
  54. package/src/alerts/index.ts +0 -3
  55. package/src/audit/AuditProperties.ts +0 -16
  56. package/src/audit/AuditUtils.ts +0 -38
  57. package/src/config/config.ts +0 -202
  58. package/src/config/config.types.ts +0 -21
  59. package/src/connection/Connection.repository.ts +0 -52
  60. package/src/connection/Connection.service.ts +0 -39
  61. package/src/connection/IConnection.ts +0 -27
  62. package/src/connection/index.ts +0 -3
  63. package/src/constants/ConnectionProviders.ts +0 -11
  64. package/src/constants/Event.ts +0 -89
  65. package/src/constants/Service.ts +0 -17
  66. package/src/constants/index.ts +0 -3
  67. package/src/db/db.ts +0 -24
  68. package/src/db/index.ts +0 -2
  69. package/src/db/redis.ts +0 -20
  70. package/src/device/cloud/entities/CloudDevice.ts +0 -40
  71. package/src/device/cloud/entities/CloudDeviceService.ts +0 -8
  72. package/src/device/cloud/entities/DeviceFactory.ts +0 -27
  73. package/src/device/cloud/entities/index.ts +0 -3
  74. package/src/device/cloud/interfaces/ICloudDevice.ts +0 -14
  75. package/src/device/cloud/interfaces/ICloudDeviceService.ts +0 -6
  76. package/src/device/cloud/interfaces/IDeviceFactory.ts +0 -5
  77. package/src/device/cloud/interfaces/IRawDataTransformer.ts +0 -5
  78. package/src/device/cloud/interfaces/IRawDevice.ts +0 -19
  79. package/src/device/cloud/interfaces/index.ts +0 -5
  80. package/src/device/local/interfaces/IDevice.ts +0 -61
  81. package/src/device/local/interfaces/IDtDevice.ts +0 -16
  82. package/src/device/local/interfaces/ISchedule.ts +0 -40
  83. package/src/device/local/interfaces/index.ts +0 -3
  84. package/src/device/local/repository/Device.repository.ts +0 -368
  85. package/src/device/local/repository/Hub.repository.ts +0 -107
  86. package/src/device/local/repository/Schedule.repository.ts +0 -72
  87. package/src/device/local/services/Device.service.ts +0 -436
  88. package/src/device/local/services/Hub.service.ts +0 -57
  89. package/src/device/local/services/Schedule.service.ts +0 -26
  90. package/src/device/local/services/index.ts +0 -3
  91. package/src/docs/Alert.model.md +0 -319
  92. package/src/docs/Alerts&IssuesModel.md +0 -312
  93. package/src/docs/Issue.model.md +0 -386
  94. package/src/docs/SECURITY.md +0 -67
  95. package/src/docs/TROUBLESHOOTING.md +0 -184
  96. package/src/events/BaseEventHandler.ts +0 -145
  97. package/src/events/BaseEventTransformer.ts +0 -97
  98. package/src/events/DeviceEventHandler.ts +0 -213
  99. package/src/events/DeviceEventTransformerFactory.ts +0 -77
  100. package/src/events/EventHandler.ts +0 -124
  101. package/src/events/EventHandlerOrchestrator.ts +0 -119
  102. package/src/events/EventProcessingService.ts +0 -248
  103. package/src/events/InternalEventSubscription.ts +0 -194
  104. package/src/events/index.ts +0 -9
  105. package/src/events/interfaces/DeviceEvent.ts +0 -56
  106. package/src/events/interfaces/IEventHandler.ts +0 -28
  107. package/src/events/interfaces/IEventTransformer.ts +0 -8
  108. package/src/events/interfaces/IInternalEvent.ts +0 -33
  109. package/src/events/interfaces/index.ts +0 -4
  110. package/src/index.ts +0 -43
  111. package/src/issues/Issue.model.ts +0 -350
  112. package/src/issues/Issue.repository.ts +0 -517
  113. package/src/issues/Issue.service.ts +0 -932
  114. package/src/issues/IssueBuilder.example.ts +0 -210
  115. package/src/issues/IssueBuilder.ts +0 -263
  116. package/src/issues/IssueService.example.ts +0 -310
  117. package/src/issues/index.ts +0 -2
  118. package/src/issues/issue.types.ts +0 -98
  119. package/src/property/IProperty.ts +0 -30
  120. package/src/property/Property.repository.ts +0 -53
  121. package/src/property/Property.service.ts +0 -38
  122. package/src/property/index.ts +0 -2
  123. package/src/queue/entities/HybridHttpQueue.ts +0 -274
  124. package/src/queue/entities/index.ts +0 -1
  125. package/src/queue/index.ts +0 -6
  126. package/src/queue/interfaces/IHttpRequestJob.ts +0 -10
  127. package/src/queue/interfaces/IHybridHttpQueue.ts +0 -25
  128. package/src/queue/interfaces/IJobResult.ts +0 -15
  129. package/src/queue/interfaces/IRateLimitConfig.ts +0 -5
  130. package/src/queue/interfaces/index.ts +0 -4
  131. package/src/queue/services/QueueService.ts +0 -40
  132. package/src/queue/services/index.ts +0 -1
  133. package/src/queue/types/http.types.ts +0 -23
  134. package/src/queue/types/index.ts +0 -2
  135. package/src/queue/types/queue.types.ts +0 -21
  136. package/src/queue/utils/index.ts +0 -3
  137. package/src/queue/utils/jobUtils.ts +0 -79
  138. package/src/queue/utils/queueUtils.ts +0 -84
  139. package/src/queue/utils/rateLimit.utils.ts +0 -131
  140. package/src/utils/http.utils.ts +0 -143
  141. package/src/utils/index.ts +0 -2
  142. package/src/utils/redis.utils.ts +0 -74
  143. package/tsconfig.json +0 -20
  144. /package/dist/{audit/AuditProperties.js → device/cloud/interfaces/IDevicesService.js} +0 -0
@@ -1,310 +0,0 @@
1
- import { Source } from "../constants";
2
- import { IssueService } from "./Issue.service";
3
- import { IssueBuilder } from "./IssueBuilder";
4
- import { IssuesCategory, IssuePriority, EntityType } from "./issue.types";
5
-
6
- /**
7
- * Example usage of the updated IssueService with IssueBuilder integration
8
- * This file demonstrates various ways to use the IssueService with the new IssueBuilder
9
- */
10
-
11
- export class IssueServiceExample {
12
- constructor(private readonly issueService: IssueService) {}
13
-
14
- /**
15
- * Example 1: Using the updated createIssue method with IssueBuilder
16
- */
17
- async createIssueWithBuilder() {
18
- const issueBuilder = new IssueBuilder()
19
- .setCategory(IssuesCategory.OPERATIONS)
20
- .setPropertyId("prop123")
21
- .setTitle("Device Maintenance Required")
22
- .setDescription("Device requires scheduled maintenance")
23
- .setEntityId("device456")
24
- .setEntityType(EntityType.DEVICE)
25
- .setPriority(IssuePriority.HIGH)
26
- .setAssignedTo("tech789")
27
- .setCreatedBy("user123")
28
- .setDueDate(new Date("2024-01-15"));
29
-
30
- // Pass the IssueBuilder directly to createIssue
31
- const issue = await this.issueService.createIssue(issueBuilder);
32
- return issue;
33
- }
34
-
35
- /**
36
- * Example 2: Using convenience methods for specific issue types
37
- */
38
- async createSpecificIssues() {
39
- // Create a readiness issue
40
- const readinessIssue = await this.issueService.createReadinessIssue(
41
- "prop123",
42
- "System Maintenance Required",
43
- "System maintenance is scheduled for tonight",
44
- "admin",
45
- "system456",
46
- EntityType.PROPERTY,
47
- "maintenance-team",
48
- new Date("2024-01-20")
49
- );
50
-
51
- // Create an operations issue
52
- const operationsIssue = await this.issueService.createOperationsIssue(
53
- "prop123",
54
- "Device Temperature High",
55
- "Device temperature exceeds normal operating range",
56
- "monitor",
57
- "device789",
58
- EntityType.DEVICE,
59
- "tech-support",
60
- new Date("2024-01-10")
61
- );
62
-
63
- // Create a security issue
64
- const securityIssue = await this.issueService.createSecurityIssue(
65
- "prop123",
66
- "Unauthorized Access Attempt",
67
- "Multiple failed login attempts detected",
68
- "security-system",
69
- "user123",
70
- EntityType.USER,
71
- "security-team",
72
- new Date("2024-01-05")
73
- );
74
-
75
- // Create an energy issue
76
- const energyIssue = await this.issueService.createEnergyIssue(
77
- "prop123",
78
- "High Energy Consumption",
79
- "Energy usage is 20% above normal levels",
80
- "energy-monitor",
81
- "zone456",
82
- EntityType.COLLECTION,
83
- "energy-manager",
84
- new Date("2024-01-25")
85
- );
86
-
87
- return { readinessIssue, operationsIssue, securityIssue, energyIssue };
88
- }
89
-
90
- /**
91
- * Example 3: Using device-specific issue methods
92
- */
93
- async createDeviceIssues() {
94
- // Create a device issue with default category and priority
95
- const deviceIssue1 = await this.issueService.createDeviceIssue(
96
- "device123",
97
- "prop456",
98
- "Device Battery Low",
99
- "Device battery level is below 20%",
100
- Source.CLOUD_EVENT,
101
- undefined, // Use default category
102
- undefined, // Use default priority
103
- "maintenance-team",
104
- new Date("2024-01-12")
105
- );
106
-
107
- // Create a device issue with custom category and priority
108
- const deviceIssue2 = await this.issueService.createDeviceIssue(
109
- "device789",
110
- "prop456",
111
- "Device Firmware Update Available",
112
- "New firmware version is available for installation",
113
- Source.CLOUD_EVENT,
114
- IssuesCategory.READINESS,
115
- IssuePriority.MEDIUM,
116
- "admin",
117
- new Date("2024-01-20")
118
- );
119
-
120
- return { deviceIssue1, deviceIssue2 };
121
- }
122
-
123
- /**
124
- * Example 4: Using hub-specific issue methods
125
- */
126
- async createHubIssues() {
127
- // Create a hub issue with default settings
128
- const hubIssue1 = await this.issueService.createHubIssue(
129
- "hub123",
130
- "prop456",
131
- "Hub Connection Lost",
132
- "Hub has lost connection to the network",
133
- "network-monitor",
134
- undefined, // Use default category
135
- undefined, // Use default priority
136
- "network-admin",
137
- new Date("2024-01-05")
138
- );
139
-
140
- // Create a hub issue with custom settings
141
- const hubIssue2 = await this.issueService.createHubIssue(
142
- "hub789",
143
- "prop456",
144
- "Hub Maintenance Required",
145
- "Hub requires scheduled maintenance",
146
- "maintenance-system",
147
- IssuesCategory.READINESS,
148
- IssuePriority.LOW,
149
- "technician",
150
- new Date("2024-01-15")
151
- );
152
-
153
- return { hubIssue1, hubIssue2 };
154
- }
155
-
156
- /**
157
- * Example 5: Using user-specific issue methods
158
- */
159
- async createUserIssues() {
160
- // Create a user issue
161
- const userIssue = await this.issueService.createUserIssue(
162
- "user456",
163
- "prop303",
164
- "User Access Review Required",
165
- "User access permissions need review",
166
- "access-control",
167
- IssuesCategory.SECURITY,
168
- IssuePriority.MEDIUM,
169
- "hr-admin",
170
- new Date("2024-01-30")
171
- );
172
-
173
- return { userIssue };
174
- }
175
-
176
- /**
177
- * Example 6: Using maintenance and urgent issue methods
178
- */
179
- async createMaintenanceAndUrgentIssues() {
180
- // Create a maintenance issue
181
- const maintenanceIssue = await this.issueService.createMaintenanceIssue(
182
- "prop505",
183
- "Scheduled Device Maintenance",
184
- "Regular maintenance is scheduled for this device",
185
- "maintenance-scheduler",
186
- "device789",
187
- EntityType.DEVICE,
188
- "technician",
189
- new Date("2024-01-12")
190
- );
191
-
192
- // Create an urgent issue
193
- const urgentIssue = await this.issueService.createUrgentIssue(
194
- "prop606",
195
- "Critical Hub Failure",
196
- "Hub is experiencing critical failures",
197
- "monitoring-system",
198
- "hub123",
199
- EntityType.HUB,
200
- "emergency-tech",
201
- new Date("2024-01-03")
202
- );
203
-
204
- return { maintenanceIssue, urgentIssue };
205
- }
206
-
207
- /**
208
- * Example 7: Using static factory methods with IssueBuilder
209
- */
210
- async createIssuesWithStaticMethods() {
211
- // Create a device issue using static factory method
212
- const deviceIssue = IssueBuilder.createDeviceIssue("device123", "prop456")
213
- .setCategory(IssuesCategory.OPERATIONS)
214
- .setTitle("Device Offline")
215
- .setDescription("Device has been offline for more than 5 minutes")
216
- .setPriority(IssuePriority.HIGH)
217
- .setAssignedTo("tech-support")
218
- .setCreatedBy("monitor")
219
- .setDueDate(new Date("2024-01-10"));
220
-
221
- const issue1 = await this.issueService.createIssue(deviceIssue);
222
-
223
- // Create a hub issue using static factory method
224
- const hubIssue = IssueBuilder.createHubIssue("hub789", "prop202")
225
- .setCategory(IssuesCategory.SECURITY)
226
- .setTitle("Hub Security Breach")
227
- .setDescription("Unauthorized access attempt detected on hub")
228
- .setPriority(IssuePriority.CRITICAL)
229
- .setAssignedTo("security-team")
230
- .setCreatedBy("security-system")
231
- .setDueDate(new Date("2024-01-05"));
232
-
233
- const issue2 = await this.issueService.createIssue(hubIssue);
234
-
235
- return { issue1, issue2 };
236
- }
237
-
238
- /**
239
- * Example 8: Creating multiple issues efficiently
240
- */
241
- async createMultipleIssues() {
242
- const issues = [];
243
-
244
- // Create multiple device issues efficiently
245
- const deviceIds = ["device1", "device2", "device3"];
246
- const propertyId = "prop123";
247
-
248
- for (const deviceId of deviceIds) {
249
- const issueBuilder = IssueBuilder.createDeviceIssue(deviceId, propertyId)
250
- .setCategory(IssuesCategory.OPERATIONS)
251
- .setTitle(`Device ${deviceId} Status`)
252
- .setDescription(`Status check for device ${deviceId}`)
253
- .setPriority(IssuePriority.MEDIUM)
254
- .setAssignedTo("batch-processor")
255
- .setCreatedBy("batch-processor")
256
- .setDueDate(new Date("2024-01-15"));
257
-
258
- const issue = await this.issueService.createIssue(issueBuilder);
259
- issues.push(issue);
260
- }
261
-
262
- return issues;
263
- }
264
-
265
- /**
266
- * Example 9: Creating issue with due date calculation
267
- */
268
- async createIssueWithDueDate() {
269
- const dueDate = new Date();
270
- dueDate.setDate(dueDate.getDate() + 7); // Due in 7 days
271
-
272
- const issueBuilder = new IssueBuilder()
273
- .setCategory(IssuesCategory.READINESS)
274
- .setPropertyId("prop808")
275
- .setTitle("System Update Required")
276
- .setDescription("System requires critical security update")
277
- .setEntityType(EntityType.PROPERTY)
278
- .setPriority(IssuePriority.HIGH)
279
- .setAssignedTo("system-admin")
280
- .setCreatedBy("update-manager")
281
- .setDueDate(dueDate);
282
-
283
- const issue = await this.issueService.createIssue(issueBuilder);
284
- return issue;
285
- }
286
-
287
- /**
288
- * Example 10: Backward compatibility - still works with CreateIssueData
289
- */
290
- async createIssueWithLegacyData() {
291
- const issueData = {
292
- category: IssuesCategory.OPERATIONS,
293
- propertyId: "prop123",
294
- title: "Legacy Issue",
295
- description:
296
- "This issue was created using the old CreateIssueData format",
297
- entityId: "device456",
298
- entityType: EntityType.DEVICE,
299
- priority: IssuePriority.MEDIUM,
300
- assignedTo: "tech-support",
301
- createdBy: "legacy-system",
302
- dueDate: new Date("2024-01-20"),
303
- source: Source.CLOUD_EVENT,
304
- };
305
-
306
- // This still works with the updated createIssue method
307
- const issue = await this.issueService.createIssue(issueData);
308
- return issue;
309
- }
310
- }
@@ -1,2 +0,0 @@
1
- export * from "./Issue.service";
2
- export * from "./issue.types";
@@ -1,98 +0,0 @@
1
- export enum IssuesCategory {
2
- READINESS = "READINESS",
3
- OPERATIONS = "OPERATIONS",
4
- SECURITY = "SECURITY",
5
- ENERGY = "ENERGY",
6
- OTHER = "OTHER",
7
- }
8
-
9
- export enum EntityType {
10
- DEVICE = "DEVICE",
11
- COLLECTION = "COLLECTION",
12
- USER = "USER",
13
- INTEGRATION = "INTEGRATION",
14
- PROPERTY = "PROPERTY",
15
- HUB = "HUB",
16
- SCHEDULE = "SCHEDULE",
17
- ALERT = "ALERT",
18
- OTHER = "OTHER",
19
- }
20
-
21
- export enum IssueStatus {
22
- PENDING = "PENDING",
23
- IN_PROGRESS = "IN_PROGRESS",
24
- RESOLVED = "RESOLVED",
25
- CLOSED = "CLOSED",
26
- CANCELLED = "CANCELLED",
27
- ON_HOLD = "ON_HOLD",
28
- }
29
-
30
- export enum IssuePriority {
31
- LOW = "LOW",
32
- MEDIUM = "MEDIUM",
33
- HIGH = "HIGH",
34
- CRITICAL = "CRITICAL",
35
- URGENT = "URGENT",
36
- }
37
-
38
- export interface IssueComment {
39
- id: string;
40
- userId: string;
41
- content: string;
42
- createdAt: Date;
43
- updatedAt?: Date;
44
- }
45
-
46
- export interface IssueDocument {
47
- _id: string;
48
- category: IssuesCategory;
49
- propertyId: string;
50
- title: string;
51
- description: string;
52
- entityId?: string;
53
- entityType: EntityType;
54
- status: IssueStatus;
55
- priority: IssuePriority;
56
- assignedTo?: string;
57
- createdBy: string;
58
- updatedBy?: string;
59
- isDeleted: boolean;
60
- createdAt: Date;
61
- updatedAt: Date;
62
- resolvedAt?: Date;
63
- dueDate?: Date;
64
- comments?: IssueComment[];
65
- }
66
-
67
- export interface CreateIssueData {
68
- category: IssuesCategory;
69
- propertyId: string;
70
- title: string;
71
- description: string;
72
- entityId?: string;
73
- entityType: EntityType;
74
- priority?: IssuePriority;
75
- assignedTo?: string;
76
- createdBy: string;
77
- dueDate?: Date;
78
- }
79
-
80
- export interface UpdateIssueData {
81
- category?: IssuesCategory;
82
- title?: string;
83
- description?: string;
84
- entityId?: string;
85
- entityType?: EntityType;
86
- status?: IssueStatus;
87
- priority?: IssuePriority;
88
- assignedTo?: string;
89
- updatedBy: string;
90
- resolvedAt?: Date;
91
- dueDate?: Date;
92
- isDeleted?: boolean;
93
- }
94
-
95
- export interface AddCommentData {
96
- userId: string;
97
- content: string;
98
- }
@@ -1,30 +0,0 @@
1
- export interface IProperty {
2
- id: string;
3
- name: string;
4
- apartment: string;
5
- city: string;
6
- country: string;
7
- state: string;
8
- street: string;
9
- zipCode: string;
10
- createdBy?: string;
11
- isDeleted: boolean;
12
- imageURL: string;
13
- timezone: string;
14
- officialName?: string;
15
- sameAsOfficialName?: boolean;
16
- phoneNumber?: string;
17
- phoneNumberCountryCode?: string;
18
- propertyKey?: string;
19
- hubNetworkId?: string;
20
- isTimeZoneOverridden: boolean;
21
- createdAt: string;
22
- updatedAt: string;
23
- propertyBillingId?: string;
24
- }
25
-
26
- export interface IPropertySettings {
27
- id: string;
28
- propertyId: string;
29
- settings: Record<string, any>;
30
- }
@@ -1,53 +0,0 @@
1
- import { getPostgresClient } from "../db";
2
- import { Service } from "typedi";
3
- import { IProperty, IPropertySettings } from "./IProperty";
4
-
5
- @Service()
6
- export class PropertyRepository {
7
- private readonly postgres;
8
- constructor() {
9
- this.postgres = getPostgresClient();
10
- }
11
-
12
- async getPropertyPreferences(
13
- propertyId: string
14
- ): Promise<IPropertySettings | null> {
15
- try {
16
- const propertyPreferences = await this.postgres.query(
17
- `SELECT * FROM dt_property_settings WHERE "propertyId" = $1`,
18
- [propertyId]
19
- );
20
- if (propertyPreferences.rows.length > 0) {
21
- return propertyPreferences.rows[0];
22
- }
23
- return null;
24
- } catch (error) {
25
- console.log(error);
26
- throw new Error("Failed to get property preferences");
27
- }
28
- }
29
-
30
- async getProperty(propertyId: string): Promise<IProperty | null> {
31
- const property = await this.postgres.query(
32
- "SELECT * FROM dt_properties WHERE id = $1",
33
- [propertyId]
34
- );
35
- if (property.rows.length > 0) {
36
- return property.rows[0];
37
- }
38
- return null;
39
- }
40
-
41
- async getAllProperties() {
42
- try {
43
- //Retrieve all the properties ids from the database
44
- const properties = await this.postgres.query(
45
- "SELECT id FROM dt_properties"
46
- );
47
- return properties.rows.map((property) => property.id);
48
- } catch (error) {
49
- console.log(error);
50
- throw new Error("Failed to get all properties");
51
- }
52
- }
53
- }
@@ -1,38 +0,0 @@
1
- import { PropertyRepository } from "./Property.repository";
2
-
3
- export class LocalPropertyService {
4
- private readonly propertyRepository: PropertyRepository;
5
- constructor() {
6
- this.propertyRepository = new PropertyRepository();
7
- }
8
-
9
- async getPropertyPreferences(propertyId: string) {
10
- if (!propertyId) {
11
- throw new Error("Property ID is required");
12
- }
13
- return await this.propertyRepository.getPropertyPreferences(propertyId);
14
- }
15
-
16
- async getProperty(propertyId: string) {
17
- if (!propertyId) {
18
- throw new Error("Property ID is required");
19
- }
20
- return await this.propertyRepository.getProperty(propertyId);
21
- }
22
-
23
- async getPropertyTimeZone(propertyId: string) {
24
- if (!propertyId) {
25
- throw new Error("Property ID is required");
26
- }
27
- const property = await this.propertyRepository.getProperty(propertyId);
28
- if (!property) {
29
- throw new Error("Property not found");
30
- }
31
- return property.timezone;
32
- }
33
-
34
- async getAllProperties() {
35
- const properties = await this.propertyRepository.getAllProperties();
36
- return properties;
37
- }
38
- }
@@ -1,2 +0,0 @@
1
- export * from "./IProperty";
2
- export * from "./Property.service";