dt-common-device 2.0.7 → 3.0.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.
- package/README.md +321 -99
- package/dist/alerts/Alert.model.d.ts +28 -0
- package/dist/alerts/Alert.model.js +222 -0
- package/dist/alerts/Alert.repository.d.ts +106 -0
- package/dist/alerts/Alert.repository.js +374 -0
- package/dist/alerts/Alert.service.d.ts +137 -0
- package/dist/alerts/Alert.service.js +476 -0
- package/dist/alerts/AlertBuilder.d.ts +87 -0
- package/dist/alerts/AlertBuilder.example.d.ts +11 -0
- package/dist/alerts/AlertBuilder.example.js +117 -0
- package/dist/alerts/AlertBuilder.js +185 -0
- package/dist/alerts/AlertService.example.d.ts +55 -0
- package/dist/alerts/AlertService.example.js +148 -0
- package/dist/alerts/alert.types.d.ts +57 -0
- package/dist/alerts/alert.types.js +22 -0
- package/dist/alerts/index.d.ts +3 -0
- package/dist/alerts/index.js +19 -0
- package/dist/config/config.d.ts +4 -4
- package/dist/config/config.js +3 -3
- package/dist/config/config.types.d.ts +19 -0
- package/dist/config/config.types.js +2 -0
- package/dist/connection/Connection.repository.d.ts +8 -0
- package/dist/connection/Connection.repository.js +92 -0
- package/dist/connection/Connection.service.d.ts +8 -0
- package/dist/connection/Connection.service.js +32 -0
- package/dist/connection/IConnection.d.ts +26 -0
- package/dist/connection/IConnection.js +14 -0
- package/dist/connection/index.d.ts +2 -0
- package/dist/connection/index.js +18 -0
- package/dist/device/cloud/entities/CloudDevice.d.ts +2 -2
- package/dist/device/cloud/entities/CloudDeviceService.d.ts +1 -1
- package/dist/device/cloud/entities/DeviceFactory.d.ts +1 -1
- package/dist/device/cloud/entities/DeviceFactory.js +1 -1
- package/dist/device/cloud/interfaces/ICloudDeviceService.d.ts +1 -1
- package/dist/device/cloud/interfaces/IRawDevice.d.ts +1 -1
- package/dist/device/local/interfaces/index.d.ts +2 -3
- package/dist/device/local/interfaces/index.js +2 -3
- package/dist/device/local/repository/Device.repository.js +3 -3
- package/dist/device/local/repository/Hub.repository.js +4 -4
- package/dist/device/local/repository/Schedule.repository.js +2 -2
- package/dist/device/local/services/Device.service.d.ts +2 -2
- package/dist/device/local/services/Device.service.js +1 -1
- package/dist/device/local/services/index.d.ts +0 -4
- package/dist/device/local/services/index.js +0 -4
- package/dist/events/BaseEventHandler.d.ts +2 -2
- package/dist/events/BaseEventHandler.js +2 -2
- package/dist/events/BaseEventTransformer.d.ts +1 -1
- package/dist/events/BaseEventTransformer.js +1 -1
- package/dist/events/DeviceEventHandler.d.ts +1 -1
- package/dist/events/DeviceEventHandler.js +2 -2
- package/dist/events/EventHandler.js +1 -1
- package/dist/events/EventHandlerOrchestrator.js +1 -1
- package/dist/events/EventProcessingService.js +1 -1
- package/dist/events/InternalEventSubscription.js +1 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.js +16 -13
- package/dist/issues/Issue.model.d.ts +28 -0
- package/dist/issues/Issue.model.js +260 -0
- package/dist/issues/Issue.repository.d.ts +113 -0
- package/dist/issues/Issue.repository.js +401 -0
- package/dist/issues/Issue.service.d.ts +168 -0
- package/dist/issues/Issue.service.js +642 -0
- package/dist/issues/IssueBuilder.d.ts +109 -0
- package/dist/issues/IssueBuilder.example.d.ts +16 -0
- package/dist/issues/IssueBuilder.example.js +196 -0
- package/dist/issues/IssueBuilder.js +237 -0
- package/dist/issues/IssueService.example.d.ts +68 -0
- package/dist/issues/IssueService.example.js +177 -0
- package/dist/issues/index.d.ts +2 -0
- package/dist/issues/index.js +18 -0
- package/dist/issues/issue.types.d.ts +90 -0
- package/dist/issues/issue.types.js +40 -0
- package/dist/property/IProperty.d.ts +29 -0
- package/dist/property/IProperty.js +2 -0
- package/dist/property/Property.repository.d.ts +8 -0
- package/dist/property/Property.repository.js +95 -0
- package/dist/property/Property.service.d.ts +8 -0
- package/dist/property/Property.service.js +36 -0
- package/dist/property/index.d.ts +2 -0
- package/dist/property/index.js +18 -0
- package/dist/queue/entities/HybridHttpQueue.d.ts +23 -0
- package/dist/queue/entities/HybridHttpQueue.js +189 -0
- package/dist/queue/entities/index.d.ts +1 -0
- package/dist/queue/entities/index.js +17 -0
- package/dist/queue/index.d.ts +5 -0
- package/dist/queue/index.js +22 -0
- package/dist/queue/interfaces/IHttpRequestJob.d.ts +9 -0
- package/dist/queue/interfaces/IHttpRequestJob.js +2 -0
- package/dist/queue/interfaces/IHybridHttpQueue.d.ts +16 -0
- package/dist/queue/interfaces/IHybridHttpQueue.js +2 -0
- package/dist/queue/interfaces/IJobResult.d.ts +6 -0
- package/dist/queue/interfaces/IJobResult.js +2 -0
- package/dist/queue/interfaces/IRateLimitConfig.d.ts +5 -0
- package/dist/queue/interfaces/IRateLimitConfig.js +2 -0
- package/dist/queue/interfaces/index.d.ts +4 -0
- package/dist/queue/interfaces/index.js +20 -0
- package/dist/queue/services/QueueService.d.ts +19 -0
- package/dist/queue/services/QueueService.js +73 -0
- package/dist/queue/services/index.d.ts +1 -0
- package/dist/queue/services/index.js +17 -0
- package/dist/queue/types/http.types.d.ts +21 -0
- package/dist/queue/types/http.types.js +2 -0
- package/dist/queue/types/index.d.ts +2 -0
- package/dist/queue/types/index.js +18 -0
- package/dist/queue/types/queue.types.d.ts +35 -0
- package/dist/queue/types/queue.types.js +2 -0
- package/dist/queue/utils/index.d.ts +3 -0
- package/dist/queue/utils/index.js +19 -0
- package/dist/queue/utils/jobUtils.d.ts +10 -0
- package/dist/queue/utils/jobUtils.js +64 -0
- package/dist/queue/utils/queueUtils.d.ts +5 -0
- package/dist/queue/utils/queueUtils.js +59 -0
- package/dist/queue/utils/rateLimit.utils.d.ts +6 -0
- package/dist/queue/utils/rateLimit.utils.js +44 -0
- package/package.json +2 -1
- package/src/{device/local/models → alerts}/Alert.model.ts +1 -1
- package/src/{device/local/repository → alerts}/Alert.repository.ts +2 -2
- package/src/{device/local/services → alerts}/Alert.service.ts +14 -7
- package/src/{device/local/entities → alerts}/AlertBuilder.example.ts +2 -2
- package/src/{device/local/entities → alerts}/AlertBuilder.ts +14 -8
- package/src/{device/local/services → alerts}/AlertService.example.ts +6 -5
- package/src/{types → alerts}/alert.types.ts +2 -2
- package/src/alerts/index.ts +3 -0
- package/src/config/config.ts +7 -7
- package/src/{types → config}/config.types.ts +1 -1
- package/src/{device/local/repository → connection}/Connection.repository.ts +2 -2
- package/src/{device/local/services → connection}/Connection.service.ts +2 -2
- package/src/connection/index.ts +3 -0
- package/src/device/cloud/entities/CloudDevice.ts +2 -2
- package/src/device/cloud/entities/CloudDeviceService.ts +1 -1
- package/src/device/cloud/entities/DeviceFactory.ts +2 -2
- package/src/device/cloud/interfaces/ICloudDeviceService.ts +1 -1
- package/src/device/cloud/interfaces/IRawDevice.ts +1 -1
- package/src/device/local/interfaces/index.ts +2 -3
- package/src/device/local/repository/Device.repository.ts +3 -3
- package/src/device/local/repository/Hub.repository.ts +4 -4
- package/src/device/local/repository/Schedule.repository.ts +2 -2
- package/src/device/local/services/Device.service.ts +1 -1
- package/src/device/local/services/index.ts +0 -4
- package/{TROUBLESHOOTING.md → src/docs/TROUBLESHOOTING.md} +2 -2
- package/src/events/BaseEventHandler.ts +3 -3
- package/src/events/BaseEventTransformer.ts +2 -2
- package/src/events/DeviceEventHandler.ts +3 -3
- package/src/events/EventHandler.ts +1 -1
- package/src/events/EventHandlerOrchestrator.ts +2 -2
- package/src/events/EventProcessingService.ts +2 -2
- package/src/events/InternalEventSubscription.ts +2 -2
- package/src/index.ts +19 -13
- package/src/{device/local/models → issues}/Issue.model.ts +1 -1
- package/src/{device/local/repository → issues}/Issue.repository.ts +2 -2
- package/src/{device/local/services → issues}/Issue.service.ts +4 -4
- package/src/{device/local/entities → issues}/IssueBuilder.example.ts +1 -1
- package/src/{device/local/entities → issues}/IssueBuilder.ts +1 -1
- package/src/{device/local/services → issues}/IssueService.example.ts +6 -5
- package/src/issues/index.ts +2 -0
- package/src/{device/local/repository → property}/Property.repository.ts +2 -2
- package/src/{device/local/services → property}/Property.service.ts +1 -1
- package/src/property/index.ts +2 -0
- package/src/queue/entities/HybridHttpQueue.ts +196 -0
- package/src/queue/entities/index.ts +1 -0
- package/src/queue/index.ts +6 -0
- package/src/queue/interfaces/IHttpRequestJob.ts +10 -0
- package/src/queue/interfaces/IHybridHttpQueue.ts +23 -0
- package/src/queue/interfaces/IJobResult.ts +6 -0
- package/src/queue/interfaces/IRateLimitConfig.ts +5 -0
- package/src/queue/interfaces/index.ts +4 -0
- package/src/queue/services/QueueService.ts +39 -0
- package/src/queue/services/index.ts +1 -0
- package/src/queue/types/http.types.ts +22 -0
- package/src/queue/types/index.ts +2 -0
- package/src/queue/types/queue.types.ts +22 -0
- package/src/queue/utils/index.ts +3 -0
- package/src/queue/utils/jobUtils.ts +80 -0
- package/src/queue/utils/queueUtils.ts +90 -0
- package/src/queue/utils/rateLimit.utils.ts +58 -0
- package/tsconfig.json +4 -0
- package/src/device/local/entities/README.md +0 -173
- package/src/device/local/entities/index.ts +0 -2
- package/src/types/index.ts +0 -3
- /package/src/{device/local/interfaces → connection}/IConnection.ts +0 -0
- /package/src/{device/local/models → docs}/Alert.model.md +0 -0
- /package/src/{device/local/models/README.md → docs/Alerts&IssuesModel.md} +0 -0
- /package/src/{device/local/models → docs}/Issue.model.md +0 -0
- /package/{SECURITY.md → src/docs/SECURITY.md} +0 -0
- /package/src/{types → issues}/issue.types.ts +0 -0
- /package/src/{device/local/interfaces → property}/IProperty.ts +0 -0
|
@@ -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("./Issue.model");
|
|
44
|
+
const issue_types_1 = require("./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;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { IssueRepository } from "./Issue.repository";
|
|
2
|
+
import { IIssueDocument } from "./Issue.model";
|
|
3
|
+
import { CreateIssueData, UpdateIssueData, AddCommentData, IssueStatus, IssuePriority, IssuesCategory, EntityType } from "./issue.types";
|
|
4
|
+
import { IssueBuilder } from "./IssueBuilder";
|
|
5
|
+
export declare class IssueService {
|
|
6
|
+
private readonly issueRepository;
|
|
7
|
+
constructor(issueRepository: IssueRepository);
|
|
8
|
+
/**
|
|
9
|
+
* Create a readiness issue using IssueBuilder
|
|
10
|
+
*/
|
|
11
|
+
createReadinessIssue(propertyId: string, title: string, description: string, createdBy: string, entityId?: string, entityType?: EntityType, assignedTo?: string, dueDate?: Date): Promise<IIssueDocument>;
|
|
12
|
+
/**
|
|
13
|
+
* Create an operations issue using IssueBuilder
|
|
14
|
+
*/
|
|
15
|
+
createOperationsIssue(propertyId: string, title: string, description: string, createdBy: string, entityId?: string, entityType?: EntityType, assignedTo?: string, dueDate?: Date): Promise<IIssueDocument>;
|
|
16
|
+
/**
|
|
17
|
+
* Create a security issue using IssueBuilder
|
|
18
|
+
*/
|
|
19
|
+
createSecurityIssue(propertyId: string, title: string, description: string, createdBy: string, entityId?: string, entityType?: EntityType, assignedTo?: string, dueDate?: Date): Promise<IIssueDocument>;
|
|
20
|
+
/**
|
|
21
|
+
* Create an energy issue using IssueBuilder
|
|
22
|
+
*/
|
|
23
|
+
createEnergyIssue(propertyId: string, title: string, description: string, createdBy: string, entityId?: string, entityType?: EntityType, assignedTo?: string, dueDate?: Date): Promise<IIssueDocument>;
|
|
24
|
+
/**
|
|
25
|
+
* Create a device-specific issue using IssueBuilder
|
|
26
|
+
*/
|
|
27
|
+
createDeviceIssue(deviceId: string, propertyId: string, title: string, description: string, createdBy: string, category?: IssuesCategory, priority?: IssuePriority, assignedTo?: string, dueDate?: Date): Promise<IIssueDocument>;
|
|
28
|
+
/**
|
|
29
|
+
* Create a hub-specific issue using IssueBuilder
|
|
30
|
+
*/
|
|
31
|
+
createHubIssue(hubId: string, propertyId: string, title: string, description: string, createdBy: string, category?: IssuesCategory, priority?: IssuePriority, assignedTo?: string, dueDate?: Date): Promise<IIssueDocument>;
|
|
32
|
+
/**
|
|
33
|
+
* Create a user-specific issue using IssueBuilder
|
|
34
|
+
*/
|
|
35
|
+
createUserIssue(userId: string, propertyId: string, title: string, description: string, createdBy: string, category?: IssuesCategory, priority?: IssuePriority, assignedTo?: string, dueDate?: Date): Promise<IIssueDocument>;
|
|
36
|
+
/**
|
|
37
|
+
* Create a maintenance issue using IssueBuilder
|
|
38
|
+
*/
|
|
39
|
+
createMaintenanceIssue(propertyId: string, title: string, description: string, createdBy: string, entityId?: string, entityType?: EntityType, assignedTo?: string, dueDate?: Date): Promise<IIssueDocument>;
|
|
40
|
+
/**
|
|
41
|
+
* Create an urgent issue using IssueBuilder
|
|
42
|
+
*/
|
|
43
|
+
createUrgentIssue(propertyId: string, title: string, description: string, createdBy: string, entityId?: string, entityType?: EntityType, assignedTo?: string, dueDate?: Date): Promise<IIssueDocument>;
|
|
44
|
+
/**
|
|
45
|
+
* Create a new issue with business logic validation
|
|
46
|
+
* Accepts either a CreateIssueData object or an IssueBuilder instance
|
|
47
|
+
*/
|
|
48
|
+
createIssue(issueData: CreateIssueData | IssueBuilder): Promise<IIssueDocument>;
|
|
49
|
+
/**
|
|
50
|
+
* Get issue by ID with business logic
|
|
51
|
+
*/
|
|
52
|
+
getIssueById(id: string, includeDeleted?: boolean): Promise<IIssueDocument | null>;
|
|
53
|
+
/**
|
|
54
|
+
* Get all issues with business logic filtering
|
|
55
|
+
*/
|
|
56
|
+
getIssues(filters?: {
|
|
57
|
+
propertyId?: string;
|
|
58
|
+
assignedTo?: string;
|
|
59
|
+
status?: IssueStatus;
|
|
60
|
+
priority?: IssuePriority;
|
|
61
|
+
category?: IssuesCategory;
|
|
62
|
+
entityType?: EntityType;
|
|
63
|
+
entityId?: string;
|
|
64
|
+
includeDeleted?: boolean;
|
|
65
|
+
limit?: number;
|
|
66
|
+
skip?: number;
|
|
67
|
+
}): Promise<IIssueDocument[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Update an issue with business logic validation
|
|
70
|
+
*/
|
|
71
|
+
updateIssue(id: string, updateData: UpdateIssueData): Promise<IIssueDocument | null>;
|
|
72
|
+
/**
|
|
73
|
+
* Soft delete an issue with business logic
|
|
74
|
+
*/
|
|
75
|
+
deleteIssue(id: string, deletedBy: string): Promise<boolean>;
|
|
76
|
+
/**
|
|
77
|
+
* Permanently delete an issue
|
|
78
|
+
*/
|
|
79
|
+
permanentlyDeleteIssue(id: string): Promise<boolean>;
|
|
80
|
+
/**
|
|
81
|
+
* Add a comment with business logic
|
|
82
|
+
*/
|
|
83
|
+
addComment(issueId: string, commentData: AddCommentData): Promise<IIssueDocument | null>;
|
|
84
|
+
/**
|
|
85
|
+
* Update a comment on an issue
|
|
86
|
+
*/
|
|
87
|
+
updateComment(issueId: string, commentId: string, content: string, userId: string): Promise<boolean>;
|
|
88
|
+
/**
|
|
89
|
+
* Remove a comment from an issue
|
|
90
|
+
*/
|
|
91
|
+
removeComment(issueId: string, commentId: string): Promise<boolean>;
|
|
92
|
+
/**
|
|
93
|
+
* Resolve an issue with business logic
|
|
94
|
+
*/
|
|
95
|
+
resolveIssue(id: string, resolvedBy: string): Promise<IIssueDocument | null>;
|
|
96
|
+
/**
|
|
97
|
+
* Reopen a resolved issue
|
|
98
|
+
*/
|
|
99
|
+
reopenIssue(id: string, reopenedBy: string): Promise<IIssueDocument | null>;
|
|
100
|
+
/**
|
|
101
|
+
* Assign an issue with business logic
|
|
102
|
+
*/
|
|
103
|
+
assignIssue(id: string, userId: string, assignedBy: string): Promise<IIssueDocument | null>;
|
|
104
|
+
/**
|
|
105
|
+
* Unassign an issue
|
|
106
|
+
*/
|
|
107
|
+
unassignIssue(id: string, unassignedBy: string): Promise<IIssueDocument | null>;
|
|
108
|
+
/**
|
|
109
|
+
* Get issues by property with business logic
|
|
110
|
+
*/
|
|
111
|
+
getIssuesByProperty(propertyId: string, includeDeleted?: boolean): Promise<IIssueDocument[]>;
|
|
112
|
+
/**
|
|
113
|
+
* Get issues assigned to a user with business logic
|
|
114
|
+
*/
|
|
115
|
+
getIssuesByAssignee(assignedTo: string, includeDeleted?: boolean): Promise<IIssueDocument[]>;
|
|
116
|
+
/**
|
|
117
|
+
* Get issues by entity
|
|
118
|
+
*/
|
|
119
|
+
getIssuesByEntity(entityId: string, entityType: EntityType, includeDeleted?: boolean): Promise<IIssueDocument[]>;
|
|
120
|
+
/**
|
|
121
|
+
* Get issues by status
|
|
122
|
+
*/
|
|
123
|
+
getIssuesByStatus(status: IssueStatus, includeDeleted?: boolean): Promise<IIssueDocument[]>;
|
|
124
|
+
/**
|
|
125
|
+
* Get issues by priority
|
|
126
|
+
*/
|
|
127
|
+
getIssuesByPriority(priority: IssuePriority, includeDeleted?: boolean): Promise<IIssueDocument[]>;
|
|
128
|
+
/**
|
|
129
|
+
* Get overdue issues with business logic
|
|
130
|
+
*/
|
|
131
|
+
getOverdueIssues(includeDeleted?: boolean): Promise<IIssueDocument[]>;
|
|
132
|
+
/**
|
|
133
|
+
* Get upcoming issues (due within specified days)
|
|
134
|
+
*/
|
|
135
|
+
getUpcomingIssues(days?: number, includeDeleted?: boolean): Promise<IIssueDocument[]>;
|
|
136
|
+
/**
|
|
137
|
+
* Get issue statistics with business logic
|
|
138
|
+
*/
|
|
139
|
+
getIssueStatistics(propertyId?: string): Promise<{
|
|
140
|
+
total: number;
|
|
141
|
+
pending: number;
|
|
142
|
+
inProgress: number;
|
|
143
|
+
resolved: number;
|
|
144
|
+
closed: number;
|
|
145
|
+
overdue: number;
|
|
146
|
+
byPriority: Record<IssuePriority, number>;
|
|
147
|
+
byCategory: Record<IssuesCategory, number>;
|
|
148
|
+
}>;
|
|
149
|
+
/**
|
|
150
|
+
* Search issues with business logic
|
|
151
|
+
*/
|
|
152
|
+
searchIssues(searchTerm: string, filters?: {
|
|
153
|
+
propertyId?: string;
|
|
154
|
+
includeDeleted?: boolean;
|
|
155
|
+
limit?: number;
|
|
156
|
+
skip?: number;
|
|
157
|
+
}): Promise<IIssueDocument[]>;
|
|
158
|
+
private validateIssueData;
|
|
159
|
+
private validateFilters;
|
|
160
|
+
private validateUpdateData;
|
|
161
|
+
private validateStatusTransition;
|
|
162
|
+
private validatePriorityChange;
|
|
163
|
+
private determineDefaultPriority;
|
|
164
|
+
private applyBusinessRules;
|
|
165
|
+
private shouldUpdateStatusOnComment;
|
|
166
|
+
private calculateAverageResponseTime;
|
|
167
|
+
private calculateResolutionRate;
|
|
168
|
+
}
|