dt-common-device 1.3.0 → 2.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.
Files changed (156) hide show
  1. package/TROUBLESHOOTING.md +184 -0
  2. package/dist/config/config.d.ts +9 -2
  3. package/dist/config/config.js +97 -14
  4. package/dist/constants/Event.d.ts +75 -0
  5. package/dist/constants/Event.js +78 -0
  6. package/dist/db/db.d.ts +1 -0
  7. package/dist/db/db.js +18 -2
  8. package/dist/device/cloud/entities/CloudDevice.d.ts +1 -0
  9. package/dist/device/cloud/entities/CloudDevice.js +3 -0
  10. package/dist/device/local/entities/AlertBuilder.d.ts +87 -0
  11. package/dist/device/local/entities/AlertBuilder.example.d.ts +11 -0
  12. package/dist/device/local/entities/AlertBuilder.example.js +117 -0
  13. package/dist/device/local/entities/AlertBuilder.js +179 -0
  14. package/dist/device/local/entities/IssueBuilder.d.ts +109 -0
  15. package/dist/device/local/entities/IssueBuilder.example.d.ts +16 -0
  16. package/dist/device/local/entities/IssueBuilder.example.js +196 -0
  17. package/dist/device/local/entities/IssueBuilder.js +237 -0
  18. package/dist/device/local/entities/index.d.ts +2 -0
  19. package/dist/device/local/entities/index.js +7 -0
  20. package/dist/device/local/events/EventHandler.js +6 -6
  21. package/dist/device/local/events/Events.d.ts +33 -12
  22. package/dist/device/local/events/Events.js +33 -12
  23. package/dist/device/local/interfaces/IDevice.d.ts +10 -9
  24. package/dist/device/local/interfaces/IDevice.js +7 -0
  25. package/dist/device/local/models/Alert.model.d.ts +28 -0
  26. package/dist/device/local/models/Alert.model.js +222 -0
  27. package/dist/device/local/models/Issue.model.d.ts +28 -0
  28. package/dist/device/local/models/Issue.model.js +260 -0
  29. package/dist/device/local/repository/Alert.repository.d.ts +106 -0
  30. package/dist/device/local/repository/Alert.repository.js +374 -0
  31. package/dist/device/local/repository/Device.repository.d.ts +11 -2
  32. package/dist/device/local/repository/Device.repository.js +163 -30
  33. package/dist/device/local/repository/Hub.repository.d.ts +1 -1
  34. package/dist/device/local/repository/Hub.repository.js +60 -18
  35. package/dist/device/local/repository/Issue.repository.d.ts +113 -0
  36. package/dist/device/local/repository/Issue.repository.js +401 -0
  37. package/dist/device/local/repository/Schedule.repository.d.ts +1 -1
  38. package/dist/device/local/repository/Schedule.repository.js +14 -18
  39. package/dist/device/local/services/Alert.service.d.ts +135 -5
  40. package/dist/device/local/services/Alert.service.js +471 -7
  41. package/dist/device/local/services/AlertService.example.d.ts +55 -0
  42. package/dist/device/local/services/AlertService.example.js +148 -0
  43. package/dist/device/local/services/Device.service.d.ts +9 -6
  44. package/dist/device/local/services/Device.service.js +61 -41
  45. package/dist/device/local/services/Issue.service.d.ts +168 -0
  46. package/dist/device/local/services/Issue.service.js +642 -0
  47. package/dist/device/local/services/IssueService.example.d.ts +68 -0
  48. package/dist/device/local/services/IssueService.example.js +177 -0
  49. package/dist/device/local/services/index.d.ts +7 -5
  50. package/dist/device/local/services/index.js +21 -11
  51. package/dist/events/BaseEventHandler.d.ts +43 -0
  52. package/dist/events/BaseEventHandler.js +111 -0
  53. package/dist/events/BaseEventTransformer.d.ts +26 -0
  54. package/dist/events/BaseEventTransformer.js +72 -0
  55. package/dist/events/DeviceEventHandler.d.ts +15 -0
  56. package/dist/events/DeviceEventHandler.js +152 -0
  57. package/dist/events/DeviceEventTransformerFactory.d.ts +27 -0
  58. package/dist/events/DeviceEventTransformerFactory.js +116 -0
  59. package/dist/events/EventHandler.d.ts +11 -0
  60. package/dist/events/EventHandler.js +111 -0
  61. package/dist/events/EventHandlerOrchestrator.d.ts +35 -0
  62. package/dist/events/EventHandlerOrchestrator.js +141 -0
  63. package/dist/events/EventProcessingService.d.ts +43 -0
  64. package/dist/events/EventProcessingService.js +243 -0
  65. package/dist/events/InternalEventSubscription.d.ts +44 -0
  66. package/dist/events/InternalEventSubscription.js +152 -0
  67. package/dist/events/index.d.ts +9 -0
  68. package/dist/events/index.js +21 -0
  69. package/dist/events/interfaces/DeviceEvent.d.ts +48 -0
  70. package/dist/events/interfaces/IEventHandler.d.ts +23 -0
  71. package/dist/{device/cloud/interface.js → events/interfaces/IEventHandler.js} +0 -1
  72. package/dist/events/interfaces/IEventTransformer.d.ts +7 -0
  73. package/dist/{device/cloud/interfaces/IDeviceConnectionService.js → events/interfaces/IEventTransformer.js} +0 -1
  74. package/dist/events/interfaces/IInternalEvent.d.ts +42 -0
  75. package/dist/events/interfaces/IInternalEvent.js +2 -0
  76. package/dist/events/interfaces/index.d.ts +4 -0
  77. package/dist/{device → events/interfaces}/index.js +4 -4
  78. package/dist/index.d.ts +6 -2
  79. package/dist/index.js +9 -2
  80. package/dist/types/alert.types.d.ts +57 -0
  81. package/dist/types/alert.types.js +22 -0
  82. package/dist/types/config.types.d.ts +15 -4
  83. package/dist/types/index.d.ts +2 -0
  84. package/dist/types/index.js +2 -0
  85. package/dist/types/issue.types.d.ts +90 -0
  86. package/dist/types/issue.types.js +40 -0
  87. package/dist/utils/http-utils.d.ts +13 -0
  88. package/dist/utils/http-utils.js +117 -0
  89. package/package.json +2 -1
  90. package/src/config/config.ts +117 -14
  91. package/src/{device/local/events/Events.ts → constants/Event.ts} +34 -13
  92. package/src/db/db.ts +14 -5
  93. package/src/device/cloud/entities/CloudDevice.ts +4 -0
  94. package/src/device/local/entities/AlertBuilder.example.ts +126 -0
  95. package/src/device/local/entities/AlertBuilder.ts +202 -0
  96. package/src/device/local/entities/IssueBuilder.example.ts +210 -0
  97. package/src/device/local/entities/IssueBuilder.ts +263 -0
  98. package/src/device/local/entities/README.md +173 -0
  99. package/src/device/local/entities/index.ts +2 -0
  100. package/src/device/local/interfaces/IDevice.ts +11 -9
  101. package/src/device/local/models/Alert.model.md +319 -0
  102. package/src/device/local/models/Alert.model.ts +283 -0
  103. package/src/device/local/models/Issue.model.md +386 -0
  104. package/src/device/local/models/Issue.model.ts +350 -0
  105. package/src/device/local/models/README.md +312 -0
  106. package/src/device/local/repository/Alert.repository.ts +465 -0
  107. package/src/device/local/repository/Device.repository.ts +251 -30
  108. package/src/device/local/repository/Hub.repository.ts +74 -18
  109. package/src/device/local/repository/Issue.repository.ts +517 -0
  110. package/src/device/local/repository/Schedule.repository.ts +28 -22
  111. package/src/device/local/services/Alert.service.ts +617 -5
  112. package/src/device/local/services/AlertService.example.ts +229 -0
  113. package/src/device/local/services/Device.service.ts +74 -52
  114. package/src/device/local/services/Issue.service.ts +872 -0
  115. package/src/device/local/services/IssueService.example.ts +307 -0
  116. package/src/device/local/services/index.ts +7 -5
  117. package/src/events/BaseEventHandler.ts +145 -0
  118. package/src/events/BaseEventTransformer.ts +97 -0
  119. package/src/events/DeviceEventHandler.ts +211 -0
  120. package/src/events/DeviceEventTransformerFactory.ts +77 -0
  121. package/src/{device/local/events → events}/EventHandler.ts +24 -19
  122. package/src/events/EventHandlerOrchestrator.ts +119 -0
  123. package/src/events/EventProcessingService.ts +248 -0
  124. package/src/events/InternalEventSubscription.ts +219 -0
  125. package/src/events/index.ts +9 -0
  126. package/src/events/interfaces/DeviceEvent.ts +56 -0
  127. package/src/events/interfaces/IEventHandler.ts +28 -0
  128. package/src/events/interfaces/IEventTransformer.ts +8 -0
  129. package/src/events/interfaces/IInternalEvent.ts +47 -0
  130. package/src/events/interfaces/index.ts +4 -0
  131. package/src/index.ts +9 -2
  132. package/src/types/alert.types.ts +64 -0
  133. package/src/types/config.types.ts +17 -4
  134. package/src/types/index.ts +2 -0
  135. package/src/types/issue.types.ts +98 -0
  136. package/src/utils/http-utils.ts +143 -0
  137. package/dist/device/cloud/interface.d.ts +0 -101
  138. package/dist/device/cloud/interfaces/IDeviceConnectionService.d.ts +0 -7
  139. package/dist/device/cloud/interfaces/IDevicesService.d.ts +0 -9
  140. package/dist/device/cloud/services/Device.service.d.ts +0 -39
  141. package/dist/device/cloud/services/Device.service.js +0 -9
  142. package/dist/device/cloud/services/DeviceCloudService.d.ts +0 -42
  143. package/dist/device/cloud/services/DeviceCloudService.js +0 -59
  144. package/dist/device/cloud/services/DeviceHub.service.d.ts +0 -3
  145. package/dist/device/cloud/services/DeviceHub.service.js +0 -6
  146. package/dist/device/cloud/services/Hub.service.d.ts +0 -25
  147. package/dist/device/cloud/services/Hub.service.js +0 -9
  148. package/dist/device/cloud/services/SmartThingsDeviceService.d.ts +0 -38
  149. package/dist/device/cloud/services/SmartThingsDeviceService.js +0 -52
  150. package/dist/device/index.d.ts +0 -4
  151. package/dist/device/local/interface.d.ts +0 -0
  152. package/dist/device/local/interface.js +0 -1
  153. package/dist/device/local/services/DeviceHub.service.d.ts +0 -11
  154. package/dist/device/local/services/DeviceHub.service.js +0 -40
  155. package/src/device/local/events/index.ts +0 -2
  156. /package/dist/{device/cloud/interfaces/IDevicesService.js → events/interfaces/DeviceEvent.js} +0 -0
@@ -37,15 +37,12 @@ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, p
37
37
  if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
38
38
  return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
39
39
  };
40
- var __importDefault = (this && this.__importDefault) || function (mod) {
41
- return (mod && mod.__esModule) ? mod : { "default": mod };
42
- };
43
40
  Object.defineProperty(exports, "__esModule", { value: true });
44
41
  exports.HubRepository = void 0;
45
- const axios_1 = __importDefault(require("axios"));
46
42
  const config_1 = require("../../../config/config");
47
43
  const db_1 = require("../../../db");
48
44
  const typedi_1 = require("typedi");
45
+ const http_utils_1 = require("../../../utils/http-utils");
49
46
  let HubRepository = (() => {
50
47
  let _classDecorators = [(0, typedi_1.Service)()];
51
48
  let _classDescriptor;
@@ -53,35 +50,80 @@ let HubRepository = (() => {
53
50
  let _classThis;
54
51
  var HubRepository = _classThis = class {
55
52
  constructor() {
56
- const { DEVICE_SERVICE } = (0, config_1.getConfig)();
57
- if (!DEVICE_SERVICE) {
58
- throw new Error("DEVICE_SERVICE is not configured. Call initialize() first with DEVICE_SERVICE.");
59
- }
60
- this.baseUrl = DEVICE_SERVICE;
61
53
  this.postgres = (0, db_1.getPostgresClient)();
54
+ this.axiosInstance = (0, http_utils_1.getDeviceServiceAxiosInstance)();
62
55
  }
63
56
  async addHub(body) {
64
- return await axios_1.default.post(`${this.baseUrl}/devices/hubs`, body);
57
+ try {
58
+ const response = await this.axiosInstance.post(`/devices/hubs`, body);
59
+ return response.data;
60
+ }
61
+ catch (error) {
62
+ (0, config_1.getConfig)().LOGGER.error("Failed to add hub:", error);
63
+ throw new Error(`Failed to add hub: ${error.message || "Unknown error"}`);
64
+ }
65
65
  }
66
66
  async getHubs(hubIds) {
67
- const query = hubIds && hubIds.length ? `?ids=${hubIds.join(",")}` : "";
68
- return await axios_1.default.get(`${this.baseUrl}/devices/hubs${query}`);
67
+ try {
68
+ const query = hubIds && hubIds.length ? `?ids=${hubIds.join(",")}` : "";
69
+ const response = await this.axiosInstance.get(`/devices/hubs${query}`);
70
+ return response.data;
71
+ }
72
+ catch (error) {
73
+ (0, config_1.getConfig)().LOGGER.error("Failed to get hubs:", error);
74
+ throw new Error(`Failed to get hubs: ${error.message || "Unknown error"}`);
75
+ }
69
76
  }
70
77
  async getHub(hubId) {
71
- return await axios_1.default.get(`${this.baseUrl}/devices/hubs/${hubId}`);
78
+ try {
79
+ const response = await this.axiosInstance.get(`/devices/hubs/${hubId}`);
80
+ return response.data;
81
+ }
82
+ catch (error) {
83
+ (0, config_1.getConfig)().LOGGER.error(`Failed to get hub ${hubId}:`, error);
84
+ throw new Error(`Failed to get hub ${hubId}: ${error.message || "Unknown error"}`);
85
+ }
72
86
  }
73
87
  async updateHub(hubId, body) {
74
- return await axios_1.default.put(`${this.baseUrl}/devices/hubs/${hubId}`, body);
88
+ try {
89
+ const response = await this.axiosInstance.put(`/devices/hubs/${hubId}`, body);
90
+ return response.data;
91
+ }
92
+ catch (error) {
93
+ (0, config_1.getConfig)().LOGGER.error(`Failed to update hub ${hubId}:`, error);
94
+ throw new Error(`Failed to update hub ${hubId}: ${error.message || "Unknown error"}`);
95
+ }
75
96
  }
76
97
  async getStatus(hubId) {
77
- return await axios_1.default.get(`${this.baseUrl}/devices/hubs/${hubId}/status`);
98
+ try {
99
+ const response = await this.axiosInstance.get(`/devices/hubs/${hubId}/status`);
100
+ return response.data;
101
+ }
102
+ catch (error) {
103
+ (0, config_1.getConfig)().LOGGER.error(`Failed to get hub status ${hubId}:`, error);
104
+ throw new Error(`Failed to get hub status ${hubId}: ${error.message || "Unknown error"}`);
105
+ }
78
106
  }
79
107
  async deleteHub(hubId) {
80
- return await axios_1.default.delete(`${this.baseUrl}/devices/hubs/${hubId}`);
108
+ try {
109
+ const response = await this.axiosInstance.delete(`/devices/hubs/${hubId}`);
110
+ return response.data;
111
+ }
112
+ catch (error) {
113
+ (0, config_1.getConfig)().LOGGER.error(`Failed to delete hub ${hubId}:`, error);
114
+ throw new Error(`Failed to delete hub ${hubId}: ${error.message || "Unknown error"}`);
115
+ }
81
116
  }
82
117
  async deleteAllHubs(hubIds) {
83
- const query = hubIds.length ? `?ids=${hubIds.join(",")}` : "";
84
- return await axios_1.default.delete(`${this.baseUrl}/devices/hubs${query}`);
118
+ try {
119
+ const query = hubIds.length ? `?ids=${hubIds.join(",")}` : "";
120
+ const response = await this.axiosInstance.delete(`/devices/hubs${query}`);
121
+ return response.data;
122
+ }
123
+ catch (error) {
124
+ (0, config_1.getConfig)().LOGGER.error("Failed to delete all hubs:", error);
125
+ throw new Error(`Failed to delete all hubs: ${error.message || "Unknown error"}`);
126
+ }
85
127
  }
86
128
  };
87
129
  __setFunctionName(_classThis, "HubRepository");
@@ -0,0 +1,113 @@
1
+ import { IIssueDocument } from "../models/Issue.model";
2
+ import { CreateIssueData, UpdateIssueData, IssueStatus, IssuePriority, IssuesCategory, EntityType } from "../../../types/issue.types";
3
+ export declare class IssueRepository {
4
+ /**
5
+ * Create a new issue
6
+ */
7
+ create(issueData: CreateIssueData): Promise<IIssueDocument>;
8
+ /**
9
+ * Find issue by ID
10
+ */
11
+ findById(id: string, includeDeleted?: boolean): Promise<IIssueDocument | null>;
12
+ /**
13
+ * Find all issues with filters
14
+ */
15
+ findAll(filters?: {
16
+ propertyId?: string;
17
+ assignedTo?: string;
18
+ status?: IssueStatus;
19
+ priority?: IssuePriority;
20
+ category?: IssuesCategory;
21
+ entityType?: EntityType;
22
+ entityId?: string;
23
+ includeDeleted?: boolean;
24
+ limit?: number;
25
+ skip?: number;
26
+ sort?: {
27
+ [key: string]: 1 | -1;
28
+ };
29
+ }): Promise<IIssueDocument[]>;
30
+ /**
31
+ * Update an issue
32
+ */
33
+ update(id: string, updateData: UpdateIssueData): Promise<IIssueDocument | null>;
34
+ /**
35
+ * Soft delete an issue
36
+ */
37
+ softDelete(id: string, deletedBy: string): Promise<boolean>;
38
+ /**
39
+ * Permanently delete an issue
40
+ */
41
+ hardDelete(id: string): Promise<boolean>;
42
+ /**
43
+ * Count issues with filters
44
+ */
45
+ count(filters?: {
46
+ propertyId?: string;
47
+ assignedTo?: string;
48
+ status?: IssueStatus;
49
+ priority?: IssuePriority;
50
+ category?: IssuesCategory;
51
+ entityType?: EntityType;
52
+ entityId?: string;
53
+ includeDeleted?: boolean;
54
+ }): Promise<number>;
55
+ /**
56
+ * Find issues by property
57
+ */
58
+ findByProperty(propertyId: string, includeDeleted?: boolean): Promise<IIssueDocument[]>;
59
+ /**
60
+ * Find issues by assignee
61
+ */
62
+ findByAssignee(assignedTo: string, includeDeleted?: boolean): Promise<IIssueDocument[]>;
63
+ /**
64
+ * Find issues by entity
65
+ */
66
+ findByEntity(entityId: string, entityType: EntityType, includeDeleted?: boolean): Promise<IIssueDocument[]>;
67
+ /**
68
+ * Find issues by status
69
+ */
70
+ findByStatus(status: IssueStatus, includeDeleted?: boolean): Promise<IIssueDocument[]>;
71
+ /**
72
+ * Find issues by priority
73
+ */
74
+ findByPriority(priority: IssuePriority, includeDeleted?: boolean): Promise<IIssueDocument[]>;
75
+ /**
76
+ * Find overdue issues
77
+ */
78
+ findOverdue(includeDeleted?: boolean): Promise<IIssueDocument[]>;
79
+ /**
80
+ * Find upcoming issues
81
+ */
82
+ findUpcoming(days?: number, includeDeleted?: boolean): Promise<IIssueDocument[]>;
83
+ /**
84
+ * Search issues by text
85
+ */
86
+ search(searchTerm: string, filters?: {
87
+ propertyId?: string;
88
+ includeDeleted?: boolean;
89
+ limit?: number;
90
+ skip?: number;
91
+ }): Promise<IIssueDocument[]>;
92
+ /**
93
+ * Get issue statistics
94
+ */
95
+ getStatistics(propertyId?: string): Promise<{
96
+ total: number;
97
+ pending: number;
98
+ inProgress: number;
99
+ resolved: number;
100
+ closed: number;
101
+ overdue: number;
102
+ byPriority: Record<IssuePriority, number>;
103
+ byCategory: Record<IssuesCategory, number>;
104
+ }>;
105
+ /**
106
+ * Bulk update issues
107
+ */
108
+ bulkUpdate(ids: string[], updateData: Partial<UpdateIssueData>): Promise<number>;
109
+ /**
110
+ * Bulk soft delete issues
111
+ */
112
+ bulkSoftDelete(ids: string[], deletedBy: string): Promise<number>;
113
+ }
@@ -0,0 +1,401 @@
1
+ "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
36
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
37
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
38
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
39
+ };
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.IssueRepository = void 0;
42
+ const typedi_1 = require("typedi");
43
+ const Issue_model_1 = require("../models/Issue.model");
44
+ const issue_types_1 = require("../../../types/issue.types");
45
+ let IssueRepository = (() => {
46
+ let _classDecorators = [(0, typedi_1.Service)()];
47
+ let _classDescriptor;
48
+ let _classExtraInitializers = [];
49
+ let _classThis;
50
+ var IssueRepository = _classThis = class {
51
+ /**
52
+ * Create a new issue
53
+ */
54
+ async create(issueData) {
55
+ try {
56
+ const issue = new Issue_model_1.IssueModel({
57
+ ...issueData,
58
+ status: issue_types_1.IssueStatus.PENDING,
59
+ priority: issueData.priority || issue_types_1.IssuePriority.MEDIUM,
60
+ isDeleted: false,
61
+ });
62
+ return await issue.save();
63
+ }
64
+ catch (error) {
65
+ throw new Error(`Failed to create issue: ${error instanceof Error ? error.message : "Unknown error"}`);
66
+ }
67
+ }
68
+ /**
69
+ * Find issue by ID
70
+ */
71
+ async findById(id, includeDeleted = false) {
72
+ try {
73
+ const query = { _id: id };
74
+ if (!includeDeleted) {
75
+ query.isDeleted = false;
76
+ }
77
+ return await Issue_model_1.IssueModel.findOne(query);
78
+ }
79
+ catch (error) {
80
+ throw new Error(`Failed to find issue by ID: ${error instanceof Error ? error.message : "Unknown error"}`);
81
+ }
82
+ }
83
+ /**
84
+ * Find all issues with filters
85
+ */
86
+ async findAll(filters = {}) {
87
+ try {
88
+ const query = {};
89
+ if (filters.propertyId)
90
+ query.propertyId = filters.propertyId;
91
+ if (filters.assignedTo)
92
+ query.assignedTo = filters.assignedTo;
93
+ if (filters.status)
94
+ query.status = filters.status;
95
+ if (filters.priority)
96
+ query.priority = filters.priority;
97
+ if (filters.category)
98
+ query.category = filters.category;
99
+ if (filters.entityType)
100
+ query.entityType = filters.entityType;
101
+ if (filters.entityId)
102
+ query.entityId = filters.entityId;
103
+ if (!filters.includeDeleted)
104
+ query.isDeleted = false;
105
+ const queryBuilder = Issue_model_1.IssueModel.find(query);
106
+ if (filters.sort) {
107
+ queryBuilder.sort(filters.sort);
108
+ }
109
+ else {
110
+ queryBuilder.sort({ createdAt: -1 });
111
+ }
112
+ if (filters.skip)
113
+ queryBuilder.skip(filters.skip);
114
+ if (filters.limit)
115
+ queryBuilder.limit(filters.limit);
116
+ return await queryBuilder.exec();
117
+ }
118
+ catch (error) {
119
+ throw new Error(`Failed to find issues: ${error instanceof Error ? error.message : "Unknown error"}`);
120
+ }
121
+ }
122
+ /**
123
+ * Update an issue
124
+ */
125
+ async update(id, updateData) {
126
+ try {
127
+ return await Issue_model_1.IssueModel.findByIdAndUpdate(id, { ...updateData, updatedAt: new Date() }, { new: true, runValidators: true });
128
+ }
129
+ catch (error) {
130
+ throw new Error(`Failed to update issue: ${error instanceof Error ? error.message : "Unknown error"}`);
131
+ }
132
+ }
133
+ /**
134
+ * Soft delete an issue
135
+ */
136
+ async softDelete(id, deletedBy) {
137
+ try {
138
+ const result = await Issue_model_1.IssueModel.findByIdAndUpdate(id, {
139
+ isDeleted: true,
140
+ updatedBy: deletedBy,
141
+ updatedAt: new Date(),
142
+ });
143
+ return !!result;
144
+ }
145
+ catch (error) {
146
+ throw new Error(`Failed to soft delete issue: ${error instanceof Error ? error.message : "Unknown error"}`);
147
+ }
148
+ }
149
+ /**
150
+ * Permanently delete an issue
151
+ */
152
+ async hardDelete(id) {
153
+ try {
154
+ const result = await Issue_model_1.IssueModel.findByIdAndDelete(id);
155
+ return !!result;
156
+ }
157
+ catch (error) {
158
+ throw new Error(`Failed to permanently delete issue: ${error instanceof Error ? error.message : "Unknown error"}`);
159
+ }
160
+ }
161
+ /**
162
+ * Count issues with filters
163
+ */
164
+ async count(filters = {}) {
165
+ try {
166
+ const query = {};
167
+ if (filters.propertyId)
168
+ query.propertyId = filters.propertyId;
169
+ if (filters.assignedTo)
170
+ query.assignedTo = filters.assignedTo;
171
+ if (filters.status)
172
+ query.status = filters.status;
173
+ if (filters.priority)
174
+ query.priority = filters.priority;
175
+ if (filters.category)
176
+ query.category = filters.category;
177
+ if (filters.entityType)
178
+ query.entityType = filters.entityType;
179
+ if (filters.entityId)
180
+ query.entityId = filters.entityId;
181
+ if (!filters.includeDeleted)
182
+ query.isDeleted = false;
183
+ return await Issue_model_1.IssueModel.countDocuments(query);
184
+ }
185
+ catch (error) {
186
+ throw new Error(`Failed to count issues: ${error instanceof Error ? error.message : "Unknown error"}`);
187
+ }
188
+ }
189
+ /**
190
+ * Find issues by property
191
+ */
192
+ async findByProperty(propertyId, includeDeleted = false) {
193
+ try {
194
+ return await Issue_model_1.IssueModel.findByProperty(propertyId, includeDeleted);
195
+ }
196
+ catch (error) {
197
+ throw new Error(`Failed to find issues by property: ${error instanceof Error ? error.message : "Unknown error"}`);
198
+ }
199
+ }
200
+ /**
201
+ * Find issues by assignee
202
+ */
203
+ async findByAssignee(assignedTo, includeDeleted = false) {
204
+ try {
205
+ return await Issue_model_1.IssueModel.findByAssignee(assignedTo, includeDeleted);
206
+ }
207
+ catch (error) {
208
+ throw new Error(`Failed to find issues by assignee: ${error instanceof Error ? error.message : "Unknown error"}`);
209
+ }
210
+ }
211
+ /**
212
+ * Find issues by entity
213
+ */
214
+ async findByEntity(entityId, entityType, includeDeleted = false) {
215
+ try {
216
+ return await Issue_model_1.IssueModel.findByEntity(entityId, entityType, includeDeleted);
217
+ }
218
+ catch (error) {
219
+ throw new Error(`Failed to find issues by entity: ${error instanceof Error ? error.message : "Unknown error"}`);
220
+ }
221
+ }
222
+ /**
223
+ * Find issues by status
224
+ */
225
+ async findByStatus(status, includeDeleted = false) {
226
+ try {
227
+ return await Issue_model_1.IssueModel.findByStatus(status, includeDeleted);
228
+ }
229
+ catch (error) {
230
+ throw new Error(`Failed to find issues by status: ${error instanceof Error ? error.message : "Unknown error"}`);
231
+ }
232
+ }
233
+ /**
234
+ * Find issues by priority
235
+ */
236
+ async findByPriority(priority, includeDeleted = false) {
237
+ try {
238
+ return await Issue_model_1.IssueModel.findByPriority(priority, includeDeleted);
239
+ }
240
+ catch (error) {
241
+ throw new Error(`Failed to find issues by priority: ${error instanceof Error ? error.message : "Unknown error"}`);
242
+ }
243
+ }
244
+ /**
245
+ * Find overdue issues
246
+ */
247
+ async findOverdue(includeDeleted = false) {
248
+ try {
249
+ return await Issue_model_1.IssueModel.findOverdue(includeDeleted);
250
+ }
251
+ catch (error) {
252
+ throw new Error(`Failed to find overdue issues: ${error instanceof Error ? error.message : "Unknown error"}`);
253
+ }
254
+ }
255
+ /**
256
+ * Find upcoming issues
257
+ */
258
+ async findUpcoming(days = 7, includeDeleted = false) {
259
+ try {
260
+ return await Issue_model_1.IssueModel.findUpcoming(days, includeDeleted);
261
+ }
262
+ catch (error) {
263
+ throw new Error(`Failed to find upcoming issues: ${error instanceof Error ? error.message : "Unknown error"}`);
264
+ }
265
+ }
266
+ /**
267
+ * Search issues by text
268
+ */
269
+ async search(searchTerm, filters = {}) {
270
+ try {
271
+ const query = {
272
+ $or: [
273
+ { title: { $regex: searchTerm, $options: "i" } },
274
+ { description: { $regex: searchTerm, $options: "i" } },
275
+ ],
276
+ };
277
+ if (filters.propertyId)
278
+ query.propertyId = filters.propertyId;
279
+ if (!filters.includeDeleted)
280
+ query.isDeleted = false;
281
+ const queryBuilder = Issue_model_1.IssueModel.find(query).sort({ createdAt: -1 });
282
+ if (filters.skip)
283
+ queryBuilder.skip(filters.skip);
284
+ if (filters.limit)
285
+ queryBuilder.limit(filters.limit);
286
+ return await queryBuilder.exec();
287
+ }
288
+ catch (error) {
289
+ throw new Error(`Failed to search issues: ${error instanceof Error ? error.message : "Unknown error"}`);
290
+ }
291
+ }
292
+ /**
293
+ * Get issue statistics
294
+ */
295
+ async getStatistics(propertyId) {
296
+ try {
297
+ const query = { isDeleted: false };
298
+ if (propertyId)
299
+ query.propertyId = propertyId;
300
+ const [total, pending, inProgress, resolved, closed, overdue, priorityStats, categoryStats,] = await Promise.all([
301
+ Issue_model_1.IssueModel.countDocuments(query),
302
+ Issue_model_1.IssueModel.countDocuments({ ...query, status: issue_types_1.IssueStatus.PENDING }),
303
+ Issue_model_1.IssueModel.countDocuments({
304
+ ...query,
305
+ status: issue_types_1.IssueStatus.IN_PROGRESS,
306
+ }),
307
+ Issue_model_1.IssueModel.countDocuments({ ...query, status: issue_types_1.IssueStatus.RESOLVED }),
308
+ Issue_model_1.IssueModel.countDocuments({ ...query, status: issue_types_1.IssueStatus.CLOSED }),
309
+ Issue_model_1.IssueModel.countDocuments({
310
+ ...query,
311
+ dueDate: { $lt: new Date() },
312
+ status: {
313
+ $nin: [
314
+ issue_types_1.IssueStatus.RESOLVED,
315
+ issue_types_1.IssueStatus.CLOSED,
316
+ issue_types_1.IssueStatus.CANCELLED,
317
+ ],
318
+ },
319
+ }),
320
+ Issue_model_1.IssueModel.aggregate([
321
+ { $match: query },
322
+ { $group: { _id: "$priority", count: { $sum: 1 } } },
323
+ ]),
324
+ Issue_model_1.IssueModel.aggregate([
325
+ { $match: query },
326
+ { $group: { _id: "$category", count: { $sum: 1 } } },
327
+ ]),
328
+ ]);
329
+ const byPriority = Object.values(issue_types_1.IssuePriority).reduce((acc, priority) => {
330
+ acc[priority] = 0;
331
+ return acc;
332
+ }, {});
333
+ const byCategory = Object.values(issue_types_1.IssuesCategory).reduce((acc, category) => {
334
+ acc[category] = 0;
335
+ return acc;
336
+ }, {});
337
+ priorityStats.forEach((stat) => {
338
+ if (stat._id in byPriority) {
339
+ byPriority[stat._id] = stat.count;
340
+ }
341
+ });
342
+ categoryStats.forEach((stat) => {
343
+ if (stat._id in byCategory) {
344
+ byCategory[stat._id] = stat.count;
345
+ }
346
+ });
347
+ return {
348
+ total,
349
+ pending,
350
+ inProgress,
351
+ resolved,
352
+ closed,
353
+ overdue,
354
+ byPriority,
355
+ byCategory,
356
+ };
357
+ }
358
+ catch (error) {
359
+ throw new Error(`Failed to get issue statistics: ${error instanceof Error ? error.message : "Unknown error"}`);
360
+ }
361
+ }
362
+ /**
363
+ * Bulk update issues
364
+ */
365
+ async bulkUpdate(ids, updateData) {
366
+ try {
367
+ const result = await Issue_model_1.IssueModel.updateMany({ _id: { $in: ids } }, { ...updateData, updatedAt: new Date() });
368
+ return result.modifiedCount;
369
+ }
370
+ catch (error) {
371
+ throw new Error(`Failed to bulk update issues: ${error instanceof Error ? error.message : "Unknown error"}`);
372
+ }
373
+ }
374
+ /**
375
+ * Bulk soft delete issues
376
+ */
377
+ async bulkSoftDelete(ids, deletedBy) {
378
+ try {
379
+ const result = await Issue_model_1.IssueModel.updateMany({ _id: { $in: ids } }, {
380
+ isDeleted: true,
381
+ updatedBy: deletedBy,
382
+ updatedAt: new Date(),
383
+ });
384
+ return result.modifiedCount;
385
+ }
386
+ catch (error) {
387
+ throw new Error(`Failed to bulk soft delete issues: ${error instanceof Error ? error.message : "Unknown error"}`);
388
+ }
389
+ }
390
+ };
391
+ __setFunctionName(_classThis, "IssueRepository");
392
+ (() => {
393
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
394
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
395
+ IssueRepository = _classThis = _classDescriptor.value;
396
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
397
+ __runInitializers(_classThis, _classExtraInitializers);
398
+ })();
399
+ return IssueRepository = _classThis;
400
+ })();
401
+ exports.IssueRepository = IssueRepository;
@@ -1,6 +1,6 @@
1
1
  import { ISchedule } from "../interfaces/ISchedule";
2
2
  export declare class ScheduleRepository {
3
- private readonly baseUrl;
3
+ private readonly axiosInstance;
4
4
  constructor();
5
5
  getSchedule(scheduleId: string): Promise<any>;
6
6
  getScheduleByZone(zoneId: string): Promise<any>;