dt-common-device 3.0.9 → 3.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/config.d.ts +1 -2
- package/dist/config/config.js +4 -5
- package/dist/device/cloud/interface.d.ts +101 -0
- package/dist/device/cloud/interface.js +3 -0
- package/dist/device/cloud/interfaces/IDeviceConnectionService.d.ts +7 -0
- package/dist/device/cloud/interfaces/IDeviceConnectionService.js +3 -0
- package/dist/device/cloud/interfaces/IDevicesService.d.ts +9 -0
- package/dist/device/cloud/services/Device.service.d.ts +39 -0
- package/dist/device/cloud/services/Device.service.js +9 -0
- package/dist/device/cloud/services/DeviceCloudService.d.ts +42 -0
- package/dist/device/cloud/services/DeviceCloudService.js +59 -0
- package/dist/device/cloud/services/DeviceHub.service.d.ts +3 -0
- package/dist/device/cloud/services/DeviceHub.service.js +6 -0
- package/dist/device/cloud/services/Hub.service.d.ts +25 -0
- package/dist/device/cloud/services/Hub.service.js +9 -0
- package/dist/device/cloud/services/SmartThingsDeviceService.d.ts +38 -0
- package/dist/device/cloud/services/SmartThingsDeviceService.js +52 -0
- package/dist/device/index.d.ts +4 -0
- package/dist/device/index.js +20 -0
- package/dist/device/local/events/EventHandler.js +6 -6
- package/dist/device/local/events/Events.d.ts +12 -33
- package/dist/device/local/events/Events.js +12 -33
- package/dist/device/local/interface.d.ts +0 -0
- package/dist/device/local/interface.js +1 -0
- package/dist/device/local/interfaces/IDevice.d.ts +1 -0
- package/dist/device/local/repository/Schedule.repository.d.ts +0 -1
- package/dist/device/local/repository/Schedule.repository.js +6 -6
- package/dist/device/local/services/DeviceHub.service.d.ts +11 -0
- package/dist/device/local/services/DeviceHub.service.js +40 -0
- package/dist/queue/entities/HybridHttpQueue.d.ts +4 -14
- package/dist/queue/entities/HybridHttpQueue.js +31 -119
- package/dist/queue/interfaces/IHybridHttpQueue.d.ts +2 -12
- package/dist/queue/interfaces/IJobResult.d.ts +1 -8
- package/dist/queue/interfaces/index.d.ts +0 -1
- package/dist/queue/interfaces/index.js +0 -1
- package/dist/queue/services/QueueService.d.ts +2 -12
- package/dist/queue/types/queue.types.d.ts +10 -29
- package/dist/queue/utils/jobUtils.d.ts +0 -3
- package/dist/queue/utils/jobUtils.js +0 -48
- package/dist/queue/utils/queueUtils.d.ts +7 -0
- package/dist/queue/utils/queueUtils.js +113 -4
- package/package.json +6 -1
- package/.eslintrc.js +0 -44
- package/dist/audit/AuditProperties.d.ts +0 -16
- package/dist/audit/AuditUtils.d.ts +0 -2
- package/dist/audit/AuditUtils.js +0 -36
- package/src/alerts/Alert.model.ts +0 -289
- package/src/alerts/Alert.repository.ts +0 -487
- package/src/alerts/Alert.service.ts +0 -711
- package/src/alerts/AlertBuilder.example.ts +0 -126
- package/src/alerts/AlertBuilder.ts +0 -208
- package/src/alerts/AlertService.example.ts +0 -232
- package/src/alerts/alert.types.ts +0 -64
- package/src/alerts/index.ts +0 -3
- package/src/audit/AuditProperties.ts +0 -16
- package/src/audit/AuditUtils.ts +0 -38
- package/src/config/config.ts +0 -202
- package/src/config/config.types.ts +0 -21
- package/src/connection/Connection.repository.ts +0 -52
- package/src/connection/Connection.service.ts +0 -39
- package/src/connection/IConnection.ts +0 -27
- package/src/connection/index.ts +0 -3
- package/src/constants/ConnectionProviders.ts +0 -11
- package/src/constants/Event.ts +0 -89
- package/src/constants/Service.ts +0 -17
- package/src/constants/index.ts +0 -3
- package/src/db/db.ts +0 -24
- package/src/db/index.ts +0 -2
- package/src/db/redis.ts +0 -20
- package/src/device/cloud/entities/CloudDevice.ts +0 -40
- package/src/device/cloud/entities/CloudDeviceService.ts +0 -8
- package/src/device/cloud/entities/DeviceFactory.ts +0 -27
- package/src/device/cloud/entities/index.ts +0 -3
- package/src/device/cloud/interfaces/ICloudDevice.ts +0 -14
- package/src/device/cloud/interfaces/ICloudDeviceService.ts +0 -6
- package/src/device/cloud/interfaces/IDeviceFactory.ts +0 -5
- package/src/device/cloud/interfaces/IRawDataTransformer.ts +0 -5
- package/src/device/cloud/interfaces/IRawDevice.ts +0 -19
- package/src/device/cloud/interfaces/index.ts +0 -5
- package/src/device/local/interfaces/IDevice.ts +0 -61
- package/src/device/local/interfaces/IDtDevice.ts +0 -16
- package/src/device/local/interfaces/ISchedule.ts +0 -40
- package/src/device/local/interfaces/index.ts +0 -3
- package/src/device/local/repository/Device.repository.ts +0 -368
- package/src/device/local/repository/Hub.repository.ts +0 -107
- package/src/device/local/repository/Schedule.repository.ts +0 -72
- package/src/device/local/services/Device.service.ts +0 -436
- package/src/device/local/services/Hub.service.ts +0 -57
- package/src/device/local/services/Schedule.service.ts +0 -26
- package/src/device/local/services/index.ts +0 -3
- package/src/docs/Alert.model.md +0 -319
- package/src/docs/Alerts&IssuesModel.md +0 -312
- package/src/docs/Issue.model.md +0 -386
- package/src/docs/SECURITY.md +0 -67
- package/src/docs/TROUBLESHOOTING.md +0 -184
- package/src/events/BaseEventHandler.ts +0 -145
- package/src/events/BaseEventTransformer.ts +0 -97
- package/src/events/DeviceEventHandler.ts +0 -213
- package/src/events/DeviceEventTransformerFactory.ts +0 -77
- package/src/events/EventHandler.ts +0 -124
- package/src/events/EventHandlerOrchestrator.ts +0 -119
- package/src/events/EventProcessingService.ts +0 -248
- package/src/events/InternalEventSubscription.ts +0 -194
- package/src/events/index.ts +0 -9
- package/src/events/interfaces/DeviceEvent.ts +0 -56
- package/src/events/interfaces/IEventHandler.ts +0 -28
- package/src/events/interfaces/IEventTransformer.ts +0 -8
- package/src/events/interfaces/IInternalEvent.ts +0 -33
- package/src/events/interfaces/index.ts +0 -4
- package/src/index.ts +0 -43
- package/src/issues/Issue.model.ts +0 -350
- package/src/issues/Issue.repository.ts +0 -517
- package/src/issues/Issue.service.ts +0 -932
- package/src/issues/IssueBuilder.example.ts +0 -210
- package/src/issues/IssueBuilder.ts +0 -263
- package/src/issues/IssueService.example.ts +0 -310
- package/src/issues/index.ts +0 -2
- package/src/issues/issue.types.ts +0 -98
- package/src/property/IProperty.ts +0 -30
- package/src/property/Property.repository.ts +0 -53
- package/src/property/Property.service.ts +0 -38
- package/src/property/index.ts +0 -2
- package/src/queue/entities/HybridHttpQueue.ts +0 -274
- package/src/queue/entities/index.ts +0 -1
- package/src/queue/index.ts +0 -6
- package/src/queue/interfaces/IHttpRequestJob.ts +0 -10
- package/src/queue/interfaces/IHybridHttpQueue.ts +0 -25
- package/src/queue/interfaces/IJobResult.ts +0 -15
- package/src/queue/interfaces/IRateLimitConfig.ts +0 -5
- package/src/queue/interfaces/index.ts +0 -4
- package/src/queue/services/QueueService.ts +0 -40
- package/src/queue/services/index.ts +0 -1
- package/src/queue/types/http.types.ts +0 -23
- package/src/queue/types/index.ts +0 -2
- package/src/queue/types/queue.types.ts +0 -21
- package/src/queue/utils/index.ts +0 -3
- package/src/queue/utils/jobUtils.ts +0 -79
- package/src/queue/utils/queueUtils.ts +0 -84
- package/src/queue/utils/rateLimit.utils.ts +0 -131
- package/src/utils/http.utils.ts +0 -143
- package/src/utils/index.ts +0 -2
- package/src/utils/redis.utils.ts +0 -74
- package/tsconfig.json +0 -20
- /package/dist/{audit/AuditProperties.js → device/cloud/interfaces/IDevicesService.js} +0 -0
package/src/index.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// Main entry point for dt-common-device
|
|
2
|
-
|
|
3
|
-
// CONSTANTS EXPORTS
|
|
4
|
-
export * from "./constants";
|
|
5
|
-
|
|
6
|
-
// DEVICE EXPORTS
|
|
7
|
-
export {
|
|
8
|
-
CloudDevice,
|
|
9
|
-
CloudDeviceService,
|
|
10
|
-
DeviceFactory,
|
|
11
|
-
} from "./device/cloud/entities";
|
|
12
|
-
export {
|
|
13
|
-
LocalDeviceService,
|
|
14
|
-
LocalHubService,
|
|
15
|
-
LocalScheduleService,
|
|
16
|
-
} from "./device/local/services";
|
|
17
|
-
export * from "./device/local/interfaces";
|
|
18
|
-
export * from "./device/cloud/interfaces";
|
|
19
|
-
|
|
20
|
-
// CONNECTION EXPORTS
|
|
21
|
-
export * from "./connection";
|
|
22
|
-
|
|
23
|
-
// PROPERTY EXPORTS
|
|
24
|
-
export * from "./property";
|
|
25
|
-
|
|
26
|
-
// EVENTS EXPORTS
|
|
27
|
-
export * from "./events";
|
|
28
|
-
export * from "./events/interfaces";
|
|
29
|
-
|
|
30
|
-
// ALERTS EXPORTS
|
|
31
|
-
export * from "./alerts";
|
|
32
|
-
|
|
33
|
-
// ISSUES EXPORTS
|
|
34
|
-
export * from "./issues";
|
|
35
|
-
|
|
36
|
-
// REDIS EXPORTS
|
|
37
|
-
export * from "./utils";
|
|
38
|
-
|
|
39
|
-
// QUEUE EXPORTS
|
|
40
|
-
export * from "./queue";
|
|
41
|
-
|
|
42
|
-
// CONFIG EXPORTS
|
|
43
|
-
export { initialize, getConfig, shutdown } from "./config/config";
|
|
@@ -1,350 +0,0 @@
|
|
|
1
|
-
import mongoose, { Schema, Model } from "mongoose";
|
|
2
|
-
import {
|
|
3
|
-
IssuesCategory,
|
|
4
|
-
EntityType,
|
|
5
|
-
IssueStatus,
|
|
6
|
-
IssuePriority,
|
|
7
|
-
IssueComment,
|
|
8
|
-
IssueDocument as IIssueDocument,
|
|
9
|
-
CreateIssueData,
|
|
10
|
-
UpdateIssueData,
|
|
11
|
-
AddCommentData,
|
|
12
|
-
} from "./issue.types";
|
|
13
|
-
|
|
14
|
-
// Comment sub-schema
|
|
15
|
-
const CommentSchema = new Schema<IssueComment>(
|
|
16
|
-
{
|
|
17
|
-
id: { type: String, required: true },
|
|
18
|
-
userId: { type: String, required: true },
|
|
19
|
-
content: { type: String, required: true },
|
|
20
|
-
createdAt: { type: Date, default: Date.now },
|
|
21
|
-
updatedAt: { type: Date },
|
|
22
|
-
},
|
|
23
|
-
{ _id: false }
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
// Interface for instance methods
|
|
27
|
-
interface IIssueMethods {
|
|
28
|
-
addComment(commentData: AddCommentData): void;
|
|
29
|
-
updateComment(commentId: string, content: string, userId: string): boolean;
|
|
30
|
-
removeComment(commentId: string): boolean;
|
|
31
|
-
resolve(resolvedBy: string): void;
|
|
32
|
-
reopen(updatedBy: string): void;
|
|
33
|
-
assign(userId: string, assignedBy: string): void;
|
|
34
|
-
unassign(unassignedBy: string): void;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Interface for static methods
|
|
38
|
-
interface IIssueModel extends Model<IIssueDocument, {}, IIssueMethods> {
|
|
39
|
-
findByProperty(
|
|
40
|
-
propertyId: string,
|
|
41
|
-
includeDeleted?: boolean
|
|
42
|
-
): Promise<IIssueDocument[]>;
|
|
43
|
-
findByAssignee(
|
|
44
|
-
assignedTo: string,
|
|
45
|
-
includeDeleted?: boolean
|
|
46
|
-
): Promise<IIssueDocument[]>;
|
|
47
|
-
findByEntity(
|
|
48
|
-
entityId: string,
|
|
49
|
-
entityType: EntityType,
|
|
50
|
-
includeDeleted?: boolean
|
|
51
|
-
): Promise<IIssueDocument[]>;
|
|
52
|
-
findByStatus(
|
|
53
|
-
status: IssueStatus,
|
|
54
|
-
includeDeleted?: boolean
|
|
55
|
-
): Promise<IIssueDocument[]>;
|
|
56
|
-
findByPriority(
|
|
57
|
-
priority: IssuePriority,
|
|
58
|
-
includeDeleted?: boolean
|
|
59
|
-
): Promise<IIssueDocument[]>;
|
|
60
|
-
findOverdue(includeDeleted?: boolean): Promise<IIssueDocument[]>;
|
|
61
|
-
findUpcoming(
|
|
62
|
-
days?: number,
|
|
63
|
-
includeDeleted?: boolean
|
|
64
|
-
): Promise<IIssueDocument[]>;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Main Issue schema
|
|
68
|
-
const IssueSchema = new Schema<IIssueDocument, IIssueModel, IIssueMethods>(
|
|
69
|
-
{
|
|
70
|
-
category: {
|
|
71
|
-
type: String,
|
|
72
|
-
enum: Object.values(IssuesCategory),
|
|
73
|
-
required: true,
|
|
74
|
-
},
|
|
75
|
-
propertyId: {
|
|
76
|
-
type: String,
|
|
77
|
-
required: true,
|
|
78
|
-
index: true,
|
|
79
|
-
},
|
|
80
|
-
title: {
|
|
81
|
-
type: String,
|
|
82
|
-
required: true,
|
|
83
|
-
trim: true,
|
|
84
|
-
},
|
|
85
|
-
description: {
|
|
86
|
-
type: String,
|
|
87
|
-
required: true,
|
|
88
|
-
trim: true,
|
|
89
|
-
},
|
|
90
|
-
entityId: {
|
|
91
|
-
type: String,
|
|
92
|
-
index: true,
|
|
93
|
-
},
|
|
94
|
-
entityType: {
|
|
95
|
-
type: String,
|
|
96
|
-
enum: Object.values(EntityType),
|
|
97
|
-
required: true,
|
|
98
|
-
index: true,
|
|
99
|
-
},
|
|
100
|
-
status: {
|
|
101
|
-
type: String,
|
|
102
|
-
enum: Object.values(IssueStatus),
|
|
103
|
-
default: IssueStatus.PENDING,
|
|
104
|
-
index: true,
|
|
105
|
-
},
|
|
106
|
-
priority: {
|
|
107
|
-
type: String,
|
|
108
|
-
enum: Object.values(IssuePriority),
|
|
109
|
-
default: IssuePriority.MEDIUM,
|
|
110
|
-
},
|
|
111
|
-
assignedTo: {
|
|
112
|
-
type: String,
|
|
113
|
-
index: true,
|
|
114
|
-
},
|
|
115
|
-
createdBy: {
|
|
116
|
-
type: String,
|
|
117
|
-
required: true,
|
|
118
|
-
},
|
|
119
|
-
updatedBy: {
|
|
120
|
-
type: String,
|
|
121
|
-
},
|
|
122
|
-
isDeleted: {
|
|
123
|
-
type: Boolean,
|
|
124
|
-
default: false,
|
|
125
|
-
},
|
|
126
|
-
createdAt: {
|
|
127
|
-
type: Date,
|
|
128
|
-
default: Date.now,
|
|
129
|
-
},
|
|
130
|
-
updatedAt: {
|
|
131
|
-
type: Date,
|
|
132
|
-
default: Date.now,
|
|
133
|
-
},
|
|
134
|
-
resolvedAt: {
|
|
135
|
-
type: Date,
|
|
136
|
-
},
|
|
137
|
-
dueDate: {
|
|
138
|
-
type: Date,
|
|
139
|
-
},
|
|
140
|
-
comments: {
|
|
141
|
-
type: [CommentSchema],
|
|
142
|
-
default: [],
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
timestamps: true,
|
|
147
|
-
collection: "dt_issues",
|
|
148
|
-
}
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
IssueSchema.index({ propertyId: 1, status: 1 });
|
|
152
|
-
IssueSchema.index({ assignedTo: 1, status: 1 });
|
|
153
|
-
IssueSchema.index({ entityId: 1, entityType: 1 });
|
|
154
|
-
|
|
155
|
-
// Pre-save middleware to update the updatedAt field
|
|
156
|
-
IssueSchema.pre("save", function (next) {
|
|
157
|
-
this.updatedAt = new Date();
|
|
158
|
-
next();
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
// Pre-update middleware to update the updatedAt field
|
|
162
|
-
IssueSchema.pre(
|
|
163
|
-
["updateOne", "findOneAndUpdate", "updateMany"],
|
|
164
|
-
function (next) {
|
|
165
|
-
this.set({ updatedAt: new Date() });
|
|
166
|
-
next();
|
|
167
|
-
}
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
// Instance methods
|
|
171
|
-
IssueSchema.methods.addComment = function (commentData: AddCommentData): void {
|
|
172
|
-
const comment: IssueComment = {
|
|
173
|
-
id: new mongoose.Types.ObjectId().toString(),
|
|
174
|
-
userId: commentData.userId,
|
|
175
|
-
content: commentData.content,
|
|
176
|
-
createdAt: new Date(),
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
if (!this.comments) {
|
|
180
|
-
this.comments = [];
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
this.comments.push(comment);
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
IssueSchema.methods.updateComment = function (
|
|
187
|
-
commentId: string,
|
|
188
|
-
content: string,
|
|
189
|
-
userId: string
|
|
190
|
-
): boolean {
|
|
191
|
-
if (!this.comments) return false;
|
|
192
|
-
|
|
193
|
-
const comment = this.comments.find((c: IssueComment) => c.id === commentId);
|
|
194
|
-
if (comment) {
|
|
195
|
-
comment.content = content;
|
|
196
|
-
comment.updatedAt = new Date();
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
199
|
-
return false;
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
IssueSchema.methods.removeComment = function (commentId: string): boolean {
|
|
203
|
-
if (!this.comments) return false;
|
|
204
|
-
|
|
205
|
-
const initialLength = this.comments.length;
|
|
206
|
-
this.comments = this.comments.filter((c: IssueComment) => c.id !== commentId);
|
|
207
|
-
return this.comments.length < initialLength;
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
IssueSchema.methods.resolve = function (resolvedBy: string): void {
|
|
211
|
-
this.status = IssueStatus.RESOLVED;
|
|
212
|
-
this.resolvedAt = new Date();
|
|
213
|
-
this.updatedBy = resolvedBy;
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
IssueSchema.methods.reopen = function (updatedBy: string): void {
|
|
217
|
-
this.status = IssueStatus.PENDING;
|
|
218
|
-
this.resolvedAt = undefined;
|
|
219
|
-
this.updatedBy = updatedBy;
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
IssueSchema.methods.assign = function (
|
|
223
|
-
userId: string,
|
|
224
|
-
assignedBy: string
|
|
225
|
-
): void {
|
|
226
|
-
this.assignedTo = userId;
|
|
227
|
-
this.updatedBy = assignedBy;
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
IssueSchema.methods.unassign = function (unassignedBy: string): void {
|
|
231
|
-
this.assignedTo = undefined;
|
|
232
|
-
this.updatedBy = unassignedBy;
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
// Static methods
|
|
236
|
-
IssueSchema.statics.findByProperty = function (
|
|
237
|
-
propertyId: string,
|
|
238
|
-
includeDeleted = false
|
|
239
|
-
) {
|
|
240
|
-
const query: any = { propertyId };
|
|
241
|
-
if (!includeDeleted) {
|
|
242
|
-
query.isDeleted = false;
|
|
243
|
-
}
|
|
244
|
-
return this.find(query).sort({ createdAt: -1 });
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
IssueSchema.statics.findByAssignee = function (
|
|
248
|
-
assignedTo: string,
|
|
249
|
-
includeDeleted = false
|
|
250
|
-
) {
|
|
251
|
-
const query: any = { assignedTo };
|
|
252
|
-
if (!includeDeleted) {
|
|
253
|
-
query.isDeleted = false;
|
|
254
|
-
}
|
|
255
|
-
return this.find(query).sort({ priority: -1, createdAt: -1 });
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
IssueSchema.statics.findByEntity = function (
|
|
259
|
-
entityId: string,
|
|
260
|
-
entityType: EntityType,
|
|
261
|
-
includeDeleted = false
|
|
262
|
-
) {
|
|
263
|
-
const query: any = { entityId, entityType };
|
|
264
|
-
if (!includeDeleted) {
|
|
265
|
-
query.isDeleted = false;
|
|
266
|
-
}
|
|
267
|
-
return this.find(query).sort({ createdAt: -1 });
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
IssueSchema.statics.findByStatus = function (
|
|
271
|
-
status: IssueStatus,
|
|
272
|
-
includeDeleted = false
|
|
273
|
-
) {
|
|
274
|
-
const query: any = { status };
|
|
275
|
-
if (!includeDeleted) {
|
|
276
|
-
query.isDeleted = false;
|
|
277
|
-
}
|
|
278
|
-
return this.find(query).sort({ priority: -1, createdAt: -1 });
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
IssueSchema.statics.findByPriority = function (
|
|
282
|
-
priority: IssuePriority,
|
|
283
|
-
includeDeleted = false
|
|
284
|
-
) {
|
|
285
|
-
const query: any = { priority };
|
|
286
|
-
if (!includeDeleted) {
|
|
287
|
-
query.isDeleted = false;
|
|
288
|
-
}
|
|
289
|
-
return this.find(query).sort({ createdAt: -1 });
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
IssueSchema.statics.findOverdue = function (includeDeleted = false) {
|
|
293
|
-
const query: any = {
|
|
294
|
-
dueDate: { $lt: new Date() },
|
|
295
|
-
status: {
|
|
296
|
-
$nin: [IssueStatus.RESOLVED, IssueStatus.CLOSED, IssueStatus.CANCELLED],
|
|
297
|
-
},
|
|
298
|
-
};
|
|
299
|
-
if (!includeDeleted) {
|
|
300
|
-
query.isDeleted = false;
|
|
301
|
-
}
|
|
302
|
-
return this.find(query).sort({ dueDate: 1 });
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
IssueSchema.statics.findUpcoming = function (
|
|
306
|
-
days: number = 7,
|
|
307
|
-
includeDeleted = false
|
|
308
|
-
) {
|
|
309
|
-
const futureDate = new Date();
|
|
310
|
-
futureDate.setDate(futureDate.getDate() + days);
|
|
311
|
-
|
|
312
|
-
const query: any = {
|
|
313
|
-
dueDate: { $gte: new Date(), $lte: futureDate },
|
|
314
|
-
status: {
|
|
315
|
-
$nin: [IssueStatus.RESOLVED, IssueStatus.CLOSED, IssueStatus.CANCELLED],
|
|
316
|
-
},
|
|
317
|
-
};
|
|
318
|
-
if (!includeDeleted) {
|
|
319
|
-
query.isDeleted = false;
|
|
320
|
-
}
|
|
321
|
-
return this.find(query).sort({ dueDate: 1 });
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
// Virtual for soft delete
|
|
325
|
-
IssueSchema.virtual("isActive").get(function () {
|
|
326
|
-
return !this.isDeleted;
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
// Ensure virtuals are serialized
|
|
330
|
-
IssueSchema.set("toJSON", { virtuals: true });
|
|
331
|
-
IssueSchema.set("toObject", { virtuals: true });
|
|
332
|
-
|
|
333
|
-
// Create and export the model
|
|
334
|
-
export const IssueModel = mongoose.model<IIssueDocument, IIssueModel>(
|
|
335
|
-
"Issue",
|
|
336
|
-
IssueSchema
|
|
337
|
-
);
|
|
338
|
-
|
|
339
|
-
// Export the schema for potential reuse
|
|
340
|
-
export { IssueSchema };
|
|
341
|
-
|
|
342
|
-
// Export types for external use
|
|
343
|
-
export type {
|
|
344
|
-
IIssueDocument,
|
|
345
|
-
CreateIssueData,
|
|
346
|
-
UpdateIssueData,
|
|
347
|
-
AddCommentData,
|
|
348
|
-
IIssueMethods,
|
|
349
|
-
IIssueModel,
|
|
350
|
-
};
|