dt-common-device 2.0.6 → 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.d.ts +2 -0
- package/dist/device/local/repository/Device.repository.js +22 -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 +3 -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 +29 -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 +5 -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
package/dist/index.js
CHANGED
|
@@ -15,8 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.shutdown = exports.getConfig = exports.initialize = exports.LocalScheduleService = exports.
|
|
19
|
-
//
|
|
18
|
+
exports.shutdown = exports.getConfig = exports.initialize = exports.LocalScheduleService = exports.LocalHubService = exports.LocalDeviceService = exports.DeviceFactory = exports.CloudDeviceService = exports.CloudDevice = void 0;
|
|
19
|
+
// DEVICE EXPORTS
|
|
20
20
|
var entities_1 = require("./device/cloud/entities");
|
|
21
21
|
Object.defineProperty(exports, "CloudDevice", { enumerable: true, get: function () { return entities_1.CloudDevice; } });
|
|
22
22
|
Object.defineProperty(exports, "CloudDeviceService", { enumerable: true, get: function () { return entities_1.CloudDeviceService; } });
|
|
@@ -24,22 +24,25 @@ Object.defineProperty(exports, "DeviceFactory", { enumerable: true, get: functio
|
|
|
24
24
|
var services_1 = require("./device/local/services");
|
|
25
25
|
Object.defineProperty(exports, "LocalDeviceService", { enumerable: true, get: function () { return services_1.LocalDeviceService; } });
|
|
26
26
|
Object.defineProperty(exports, "LocalHubService", { enumerable: true, get: function () { return services_1.LocalHubService; } });
|
|
27
|
-
Object.defineProperty(exports, "LocalConnectionService", { enumerable: true, get: function () { return services_1.LocalConnectionService; } });
|
|
28
|
-
Object.defineProperty(exports, "LocalPropertyService", { enumerable: true, get: function () { return services_1.LocalPropertyService; } });
|
|
29
27
|
Object.defineProperty(exports, "LocalScheduleService", { enumerable: true, get: function () { return services_1.LocalScheduleService; } });
|
|
30
|
-
// Events exports
|
|
31
|
-
__exportStar(require("./events"), exports);
|
|
32
|
-
__exportStar(require("./events/interfaces"), exports);
|
|
33
|
-
__exportStar(require("./device/cloud/interfaces"), exports);
|
|
34
|
-
// Local exports
|
|
35
28
|
__exportStar(require("./device/local/interfaces"), exports);
|
|
29
|
+
__exportStar(require("./device/cloud/interfaces"), exports);
|
|
30
|
+
// CONNECTION EXPORTS
|
|
31
|
+
__exportStar(require("./connection"), exports);
|
|
32
|
+
// PROPERTY EXPORTS
|
|
33
|
+
__exportStar(require("./property"), exports);
|
|
34
|
+
// EVENTS EXPORTS
|
|
36
35
|
__exportStar(require("./events"), exports);
|
|
37
36
|
__exportStar(require("./events/interfaces"), exports);
|
|
38
|
-
//
|
|
39
|
-
__exportStar(require("./
|
|
40
|
-
//
|
|
37
|
+
// ALERTS EXPORTS
|
|
38
|
+
__exportStar(require("./alerts"), exports);
|
|
39
|
+
// ISSUES EXPORTS
|
|
40
|
+
__exportStar(require("./issues"), exports);
|
|
41
|
+
// REDIS EXPORTS
|
|
41
42
|
__exportStar(require("./utils"), exports);
|
|
42
|
-
//
|
|
43
|
+
// QUEUE EXPORTS
|
|
44
|
+
__exportStar(require("./queue"), exports);
|
|
45
|
+
// CONFIG EXPORTS
|
|
43
46
|
var config_1 = require("./config/config");
|
|
44
47
|
Object.defineProperty(exports, "initialize", { enumerable: true, get: function () { return config_1.initialize; } });
|
|
45
48
|
Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return config_1.getConfig; } });
|
|
@@ -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
|
+
}
|