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.
Files changed (186) hide show
  1. package/README.md +321 -99
  2. package/dist/alerts/Alert.model.d.ts +28 -0
  3. package/dist/alerts/Alert.model.js +222 -0
  4. package/dist/alerts/Alert.repository.d.ts +106 -0
  5. package/dist/alerts/Alert.repository.js +374 -0
  6. package/dist/alerts/Alert.service.d.ts +137 -0
  7. package/dist/alerts/Alert.service.js +476 -0
  8. package/dist/alerts/AlertBuilder.d.ts +87 -0
  9. package/dist/alerts/AlertBuilder.example.d.ts +11 -0
  10. package/dist/alerts/AlertBuilder.example.js +117 -0
  11. package/dist/alerts/AlertBuilder.js +185 -0
  12. package/dist/alerts/AlertService.example.d.ts +55 -0
  13. package/dist/alerts/AlertService.example.js +148 -0
  14. package/dist/alerts/alert.types.d.ts +57 -0
  15. package/dist/alerts/alert.types.js +22 -0
  16. package/dist/alerts/index.d.ts +3 -0
  17. package/dist/alerts/index.js +19 -0
  18. package/dist/config/config.d.ts +4 -4
  19. package/dist/config/config.js +3 -3
  20. package/dist/config/config.types.d.ts +19 -0
  21. package/dist/config/config.types.js +2 -0
  22. package/dist/connection/Connection.repository.d.ts +8 -0
  23. package/dist/connection/Connection.repository.js +92 -0
  24. package/dist/connection/Connection.service.d.ts +8 -0
  25. package/dist/connection/Connection.service.js +32 -0
  26. package/dist/connection/IConnection.d.ts +26 -0
  27. package/dist/connection/IConnection.js +14 -0
  28. package/dist/connection/index.d.ts +2 -0
  29. package/dist/connection/index.js +18 -0
  30. package/dist/device/cloud/entities/CloudDevice.d.ts +2 -2
  31. package/dist/device/cloud/entities/CloudDeviceService.d.ts +1 -1
  32. package/dist/device/cloud/entities/DeviceFactory.d.ts +1 -1
  33. package/dist/device/cloud/entities/DeviceFactory.js +1 -1
  34. package/dist/device/cloud/interfaces/ICloudDeviceService.d.ts +1 -1
  35. package/dist/device/cloud/interfaces/IRawDevice.d.ts +1 -1
  36. package/dist/device/local/interfaces/index.d.ts +2 -3
  37. package/dist/device/local/interfaces/index.js +2 -3
  38. package/dist/device/local/repository/Device.repository.js +3 -3
  39. package/dist/device/local/repository/Hub.repository.js +4 -4
  40. package/dist/device/local/repository/Schedule.repository.js +2 -2
  41. package/dist/device/local/services/Device.service.d.ts +2 -2
  42. package/dist/device/local/services/Device.service.js +1 -1
  43. package/dist/device/local/services/index.d.ts +0 -4
  44. package/dist/device/local/services/index.js +0 -4
  45. package/dist/events/BaseEventHandler.d.ts +2 -2
  46. package/dist/events/BaseEventHandler.js +2 -2
  47. package/dist/events/BaseEventTransformer.d.ts +1 -1
  48. package/dist/events/BaseEventTransformer.js +1 -1
  49. package/dist/events/DeviceEventHandler.d.ts +1 -1
  50. package/dist/events/DeviceEventHandler.js +2 -2
  51. package/dist/events/EventHandler.js +1 -1
  52. package/dist/events/EventHandlerOrchestrator.js +1 -1
  53. package/dist/events/EventProcessingService.js +1 -1
  54. package/dist/events/InternalEventSubscription.js +1 -1
  55. package/dist/index.d.ts +7 -5
  56. package/dist/index.js +16 -13
  57. package/dist/issues/Issue.model.d.ts +28 -0
  58. package/dist/issues/Issue.model.js +260 -0
  59. package/dist/issues/Issue.repository.d.ts +113 -0
  60. package/dist/issues/Issue.repository.js +401 -0
  61. package/dist/issues/Issue.service.d.ts +168 -0
  62. package/dist/issues/Issue.service.js +642 -0
  63. package/dist/issues/IssueBuilder.d.ts +109 -0
  64. package/dist/issues/IssueBuilder.example.d.ts +16 -0
  65. package/dist/issues/IssueBuilder.example.js +196 -0
  66. package/dist/issues/IssueBuilder.js +237 -0
  67. package/dist/issues/IssueService.example.d.ts +68 -0
  68. package/dist/issues/IssueService.example.js +177 -0
  69. package/dist/issues/index.d.ts +2 -0
  70. package/dist/issues/index.js +18 -0
  71. package/dist/issues/issue.types.d.ts +90 -0
  72. package/dist/issues/issue.types.js +40 -0
  73. package/dist/property/IProperty.d.ts +29 -0
  74. package/dist/property/IProperty.js +2 -0
  75. package/dist/property/Property.repository.d.ts +8 -0
  76. package/dist/property/Property.repository.js +95 -0
  77. package/dist/property/Property.service.d.ts +8 -0
  78. package/dist/property/Property.service.js +36 -0
  79. package/dist/property/index.d.ts +2 -0
  80. package/dist/property/index.js +18 -0
  81. package/dist/queue/entities/HybridHttpQueue.d.ts +23 -0
  82. package/dist/queue/entities/HybridHttpQueue.js +189 -0
  83. package/dist/queue/entities/index.d.ts +1 -0
  84. package/dist/queue/entities/index.js +17 -0
  85. package/dist/queue/index.d.ts +5 -0
  86. package/dist/queue/index.js +22 -0
  87. package/dist/queue/interfaces/IHttpRequestJob.d.ts +9 -0
  88. package/dist/queue/interfaces/IHttpRequestJob.js +2 -0
  89. package/dist/queue/interfaces/IHybridHttpQueue.d.ts +16 -0
  90. package/dist/queue/interfaces/IHybridHttpQueue.js +2 -0
  91. package/dist/queue/interfaces/IJobResult.d.ts +6 -0
  92. package/dist/queue/interfaces/IJobResult.js +2 -0
  93. package/dist/queue/interfaces/IRateLimitConfig.d.ts +5 -0
  94. package/dist/queue/interfaces/IRateLimitConfig.js +2 -0
  95. package/dist/queue/interfaces/index.d.ts +4 -0
  96. package/dist/queue/interfaces/index.js +20 -0
  97. package/dist/queue/services/QueueService.d.ts +19 -0
  98. package/dist/queue/services/QueueService.js +73 -0
  99. package/dist/queue/services/index.d.ts +1 -0
  100. package/dist/queue/services/index.js +17 -0
  101. package/dist/queue/types/http.types.d.ts +21 -0
  102. package/dist/queue/types/http.types.js +2 -0
  103. package/dist/queue/types/index.d.ts +2 -0
  104. package/dist/queue/types/index.js +18 -0
  105. package/dist/queue/types/queue.types.d.ts +35 -0
  106. package/dist/queue/types/queue.types.js +2 -0
  107. package/dist/queue/utils/index.d.ts +3 -0
  108. package/dist/queue/utils/index.js +19 -0
  109. package/dist/queue/utils/jobUtils.d.ts +10 -0
  110. package/dist/queue/utils/jobUtils.js +64 -0
  111. package/dist/queue/utils/queueUtils.d.ts +5 -0
  112. package/dist/queue/utils/queueUtils.js +59 -0
  113. package/dist/queue/utils/rateLimit.utils.d.ts +6 -0
  114. package/dist/queue/utils/rateLimit.utils.js +44 -0
  115. package/package.json +2 -1
  116. package/src/{device/local/models → alerts}/Alert.model.ts +1 -1
  117. package/src/{device/local/repository → alerts}/Alert.repository.ts +2 -2
  118. package/src/{device/local/services → alerts}/Alert.service.ts +14 -7
  119. package/src/{device/local/entities → alerts}/AlertBuilder.example.ts +2 -2
  120. package/src/{device/local/entities → alerts}/AlertBuilder.ts +14 -8
  121. package/src/{device/local/services → alerts}/AlertService.example.ts +6 -5
  122. package/src/{types → alerts}/alert.types.ts +2 -2
  123. package/src/alerts/index.ts +3 -0
  124. package/src/config/config.ts +7 -7
  125. package/src/{types → config}/config.types.ts +1 -1
  126. package/src/{device/local/repository → connection}/Connection.repository.ts +2 -2
  127. package/src/{device/local/services → connection}/Connection.service.ts +2 -2
  128. package/src/connection/index.ts +3 -0
  129. package/src/device/cloud/entities/CloudDevice.ts +2 -2
  130. package/src/device/cloud/entities/CloudDeviceService.ts +1 -1
  131. package/src/device/cloud/entities/DeviceFactory.ts +2 -2
  132. package/src/device/cloud/interfaces/ICloudDeviceService.ts +1 -1
  133. package/src/device/cloud/interfaces/IRawDevice.ts +1 -1
  134. package/src/device/local/interfaces/index.ts +2 -3
  135. package/src/device/local/repository/Device.repository.ts +3 -3
  136. package/src/device/local/repository/Hub.repository.ts +4 -4
  137. package/src/device/local/repository/Schedule.repository.ts +2 -2
  138. package/src/device/local/services/Device.service.ts +1 -1
  139. package/src/device/local/services/index.ts +0 -4
  140. package/{TROUBLESHOOTING.md → src/docs/TROUBLESHOOTING.md} +2 -2
  141. package/src/events/BaseEventHandler.ts +3 -3
  142. package/src/events/BaseEventTransformer.ts +2 -2
  143. package/src/events/DeviceEventHandler.ts +3 -3
  144. package/src/events/EventHandler.ts +1 -1
  145. package/src/events/EventHandlerOrchestrator.ts +2 -2
  146. package/src/events/EventProcessingService.ts +2 -2
  147. package/src/events/InternalEventSubscription.ts +2 -2
  148. package/src/index.ts +19 -13
  149. package/src/{device/local/models → issues}/Issue.model.ts +1 -1
  150. package/src/{device/local/repository → issues}/Issue.repository.ts +2 -2
  151. package/src/{device/local/services → issues}/Issue.service.ts +4 -4
  152. package/src/{device/local/entities → issues}/IssueBuilder.example.ts +1 -1
  153. package/src/{device/local/entities → issues}/IssueBuilder.ts +1 -1
  154. package/src/{device/local/services → issues}/IssueService.example.ts +6 -5
  155. package/src/issues/index.ts +2 -0
  156. package/src/{device/local/repository → property}/Property.repository.ts +2 -2
  157. package/src/{device/local/services → property}/Property.service.ts +1 -1
  158. package/src/property/index.ts +2 -0
  159. package/src/queue/entities/HybridHttpQueue.ts +196 -0
  160. package/src/queue/entities/index.ts +1 -0
  161. package/src/queue/index.ts +6 -0
  162. package/src/queue/interfaces/IHttpRequestJob.ts +10 -0
  163. package/src/queue/interfaces/IHybridHttpQueue.ts +23 -0
  164. package/src/queue/interfaces/IJobResult.ts +6 -0
  165. package/src/queue/interfaces/IRateLimitConfig.ts +5 -0
  166. package/src/queue/interfaces/index.ts +4 -0
  167. package/src/queue/services/QueueService.ts +39 -0
  168. package/src/queue/services/index.ts +1 -0
  169. package/src/queue/types/http.types.ts +22 -0
  170. package/src/queue/types/index.ts +2 -0
  171. package/src/queue/types/queue.types.ts +22 -0
  172. package/src/queue/utils/index.ts +3 -0
  173. package/src/queue/utils/jobUtils.ts +80 -0
  174. package/src/queue/utils/queueUtils.ts +90 -0
  175. package/src/queue/utils/rateLimit.utils.ts +58 -0
  176. package/tsconfig.json +4 -0
  177. package/src/device/local/entities/README.md +0 -173
  178. package/src/device/local/entities/index.ts +0 -2
  179. package/src/types/index.ts +0 -3
  180. /package/src/{device/local/interfaces → connection}/IConnection.ts +0 -0
  181. /package/src/{device/local/models → docs}/Alert.model.md +0 -0
  182. /package/src/{device/local/models/README.md → docs/Alerts&IssuesModel.md} +0 -0
  183. /package/src/{device/local/models → docs}/Issue.model.md +0 -0
  184. /package/{SECURITY.md → src/docs/SECURITY.md} +0 -0
  185. /package/src/{types → issues}/issue.types.ts +0 -0
  186. /package/src/{device/local/interfaces → property}/IProperty.ts +0 -0
@@ -0,0 +1,28 @@
1
+ import mongoose, { Model } from "mongoose";
2
+ import { EntityType, IssueStatus, IssuePriority, IssueDocument as IIssueDocument, CreateIssueData, UpdateIssueData, AddCommentData } from "./issue.types";
3
+ interface IIssueMethods {
4
+ addComment(commentData: AddCommentData): void;
5
+ updateComment(commentId: string, content: string, userId: string): boolean;
6
+ removeComment(commentId: string): boolean;
7
+ resolve(resolvedBy: string): void;
8
+ reopen(updatedBy: string): void;
9
+ assign(userId: string, assignedBy: string): void;
10
+ unassign(unassignedBy: string): void;
11
+ }
12
+ interface IIssueModel extends Model<IIssueDocument, {}, IIssueMethods> {
13
+ findByProperty(propertyId: string, includeDeleted?: boolean): Promise<IIssueDocument[]>;
14
+ findByAssignee(assignedTo: string, includeDeleted?: boolean): Promise<IIssueDocument[]>;
15
+ findByEntity(entityId: string, entityType: EntityType, includeDeleted?: boolean): Promise<IIssueDocument[]>;
16
+ findByStatus(status: IssueStatus, includeDeleted?: boolean): Promise<IIssueDocument[]>;
17
+ findByPriority(priority: IssuePriority, includeDeleted?: boolean): Promise<IIssueDocument[]>;
18
+ findOverdue(includeDeleted?: boolean): Promise<IIssueDocument[]>;
19
+ findUpcoming(days?: number, includeDeleted?: boolean): Promise<IIssueDocument[]>;
20
+ }
21
+ declare const IssueSchema: mongoose.Schema<IIssueDocument, IIssueModel, IIssueMethods, {}, {}, {}, mongoose.DefaultSchemaOptions, IIssueDocument, mongoose.Document<unknown, {}, mongoose.FlatRecord<IIssueDocument>, {}> & Omit<mongoose.FlatRecord<IIssueDocument> & Required<{
22
+ _id: string;
23
+ }> & {
24
+ __v: number;
25
+ }, keyof IIssueMethods> & IIssueMethods>;
26
+ export declare const IssueModel: IIssueModel;
27
+ export { IssueSchema };
28
+ export type { IIssueDocument, CreateIssueData, UpdateIssueData, AddCommentData, IIssueMethods, IIssueModel, };
@@ -0,0 +1,260 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.IssueSchema = exports.IssueModel = void 0;
37
+ const mongoose_1 = __importStar(require("mongoose"));
38
+ const issue_types_1 = require("./issue.types");
39
+ // Comment sub-schema
40
+ const CommentSchema = new mongoose_1.Schema({
41
+ id: { type: String, required: true },
42
+ userId: { type: String, required: true },
43
+ content: { type: String, required: true },
44
+ createdAt: { type: Date, default: Date.now },
45
+ updatedAt: { type: Date },
46
+ }, { _id: false });
47
+ // Main Issue schema
48
+ const IssueSchema = new mongoose_1.Schema({
49
+ category: {
50
+ type: String,
51
+ enum: Object.values(issue_types_1.IssuesCategory),
52
+ required: true,
53
+ },
54
+ propertyId: {
55
+ type: String,
56
+ required: true,
57
+ index: true,
58
+ },
59
+ title: {
60
+ type: String,
61
+ required: true,
62
+ trim: true,
63
+ },
64
+ description: {
65
+ type: String,
66
+ required: true,
67
+ trim: true,
68
+ },
69
+ entityId: {
70
+ type: String,
71
+ index: true,
72
+ },
73
+ entityType: {
74
+ type: String,
75
+ enum: Object.values(issue_types_1.EntityType),
76
+ required: true,
77
+ index: true,
78
+ },
79
+ status: {
80
+ type: String,
81
+ enum: Object.values(issue_types_1.IssueStatus),
82
+ default: issue_types_1.IssueStatus.PENDING,
83
+ index: true,
84
+ },
85
+ priority: {
86
+ type: String,
87
+ enum: Object.values(issue_types_1.IssuePriority),
88
+ default: issue_types_1.IssuePriority.MEDIUM,
89
+ },
90
+ assignedTo: {
91
+ type: String,
92
+ index: true,
93
+ },
94
+ createdBy: {
95
+ type: String,
96
+ required: true,
97
+ },
98
+ updatedBy: {
99
+ type: String,
100
+ },
101
+ isDeleted: {
102
+ type: Boolean,
103
+ default: false,
104
+ },
105
+ createdAt: {
106
+ type: Date,
107
+ default: Date.now,
108
+ },
109
+ updatedAt: {
110
+ type: Date,
111
+ default: Date.now,
112
+ },
113
+ resolvedAt: {
114
+ type: Date,
115
+ },
116
+ dueDate: {
117
+ type: Date,
118
+ },
119
+ comments: {
120
+ type: [CommentSchema],
121
+ default: [],
122
+ },
123
+ }, {
124
+ timestamps: true,
125
+ collection: "dt_issues",
126
+ });
127
+ exports.IssueSchema = IssueSchema;
128
+ IssueSchema.index({ propertyId: 1, status: 1 });
129
+ IssueSchema.index({ assignedTo: 1, status: 1 });
130
+ IssueSchema.index({ entityId: 1, entityType: 1 });
131
+ // Pre-save middleware to update the updatedAt field
132
+ IssueSchema.pre("save", function (next) {
133
+ this.updatedAt = new Date();
134
+ next();
135
+ });
136
+ // Pre-update middleware to update the updatedAt field
137
+ IssueSchema.pre(["updateOne", "findOneAndUpdate", "updateMany"], function (next) {
138
+ this.set({ updatedAt: new Date() });
139
+ next();
140
+ });
141
+ // Instance methods
142
+ IssueSchema.methods.addComment = function (commentData) {
143
+ const comment = {
144
+ id: new mongoose_1.default.Types.ObjectId().toString(),
145
+ userId: commentData.userId,
146
+ content: commentData.content,
147
+ createdAt: new Date(),
148
+ };
149
+ if (!this.comments) {
150
+ this.comments = [];
151
+ }
152
+ this.comments.push(comment);
153
+ };
154
+ IssueSchema.methods.updateComment = function (commentId, content, userId) {
155
+ if (!this.comments)
156
+ return false;
157
+ const comment = this.comments.find((c) => c.id === commentId);
158
+ if (comment) {
159
+ comment.content = content;
160
+ comment.updatedAt = new Date();
161
+ return true;
162
+ }
163
+ return false;
164
+ };
165
+ IssueSchema.methods.removeComment = function (commentId) {
166
+ if (!this.comments)
167
+ return false;
168
+ const initialLength = this.comments.length;
169
+ this.comments = this.comments.filter((c) => c.id !== commentId);
170
+ return this.comments.length < initialLength;
171
+ };
172
+ IssueSchema.methods.resolve = function (resolvedBy) {
173
+ this.status = issue_types_1.IssueStatus.RESOLVED;
174
+ this.resolvedAt = new Date();
175
+ this.updatedBy = resolvedBy;
176
+ };
177
+ IssueSchema.methods.reopen = function (updatedBy) {
178
+ this.status = issue_types_1.IssueStatus.PENDING;
179
+ this.resolvedAt = undefined;
180
+ this.updatedBy = updatedBy;
181
+ };
182
+ IssueSchema.methods.assign = function (userId, assignedBy) {
183
+ this.assignedTo = userId;
184
+ this.updatedBy = assignedBy;
185
+ };
186
+ IssueSchema.methods.unassign = function (unassignedBy) {
187
+ this.assignedTo = undefined;
188
+ this.updatedBy = unassignedBy;
189
+ };
190
+ // Static methods
191
+ IssueSchema.statics.findByProperty = function (propertyId, includeDeleted = false) {
192
+ const query = { propertyId };
193
+ if (!includeDeleted) {
194
+ query.isDeleted = false;
195
+ }
196
+ return this.find(query).sort({ createdAt: -1 });
197
+ };
198
+ IssueSchema.statics.findByAssignee = function (assignedTo, includeDeleted = false) {
199
+ const query = { assignedTo };
200
+ if (!includeDeleted) {
201
+ query.isDeleted = false;
202
+ }
203
+ return this.find(query).sort({ priority: -1, createdAt: -1 });
204
+ };
205
+ IssueSchema.statics.findByEntity = function (entityId, entityType, includeDeleted = false) {
206
+ const query = { entityId, entityType };
207
+ if (!includeDeleted) {
208
+ query.isDeleted = false;
209
+ }
210
+ return this.find(query).sort({ createdAt: -1 });
211
+ };
212
+ IssueSchema.statics.findByStatus = function (status, includeDeleted = false) {
213
+ const query = { status };
214
+ if (!includeDeleted) {
215
+ query.isDeleted = false;
216
+ }
217
+ return this.find(query).sort({ priority: -1, createdAt: -1 });
218
+ };
219
+ IssueSchema.statics.findByPriority = function (priority, includeDeleted = false) {
220
+ const query = { priority };
221
+ if (!includeDeleted) {
222
+ query.isDeleted = false;
223
+ }
224
+ return this.find(query).sort({ createdAt: -1 });
225
+ };
226
+ IssueSchema.statics.findOverdue = function (includeDeleted = false) {
227
+ const query = {
228
+ dueDate: { $lt: new Date() },
229
+ status: {
230
+ $nin: [issue_types_1.IssueStatus.RESOLVED, issue_types_1.IssueStatus.CLOSED, issue_types_1.IssueStatus.CANCELLED],
231
+ },
232
+ };
233
+ if (!includeDeleted) {
234
+ query.isDeleted = false;
235
+ }
236
+ return this.find(query).sort({ dueDate: 1 });
237
+ };
238
+ IssueSchema.statics.findUpcoming = function (days = 7, includeDeleted = false) {
239
+ const futureDate = new Date();
240
+ futureDate.setDate(futureDate.getDate() + days);
241
+ const query = {
242
+ dueDate: { $gte: new Date(), $lte: futureDate },
243
+ status: {
244
+ $nin: [issue_types_1.IssueStatus.RESOLVED, issue_types_1.IssueStatus.CLOSED, issue_types_1.IssueStatus.CANCELLED],
245
+ },
246
+ };
247
+ if (!includeDeleted) {
248
+ query.isDeleted = false;
249
+ }
250
+ return this.find(query).sort({ dueDate: 1 });
251
+ };
252
+ // Virtual for soft delete
253
+ IssueSchema.virtual("isActive").get(function () {
254
+ return !this.isDeleted;
255
+ });
256
+ // Ensure virtuals are serialized
257
+ IssueSchema.set("toJSON", { virtuals: true });
258
+ IssueSchema.set("toObject", { virtuals: true });
259
+ // Create and export the model
260
+ exports.IssueModel = mongoose_1.default.model("Issue", IssueSchema);
@@ -0,0 +1,113 @@
1
+ import { IIssueDocument } from "./Issue.model";
2
+ import { CreateIssueData, UpdateIssueData, IssueStatus, IssuePriority, IssuesCategory, EntityType } from "./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
+ }