dt-common-device 5.1.7 → 6.1.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 (49) hide show
  1. package/dist/alerts/Alert.model.d.ts +1 -6
  2. package/dist/alerts/Alert.model.js +1 -35
  3. package/dist/alerts/Alert.repository.d.ts +4 -46
  4. package/dist/alerts/Alert.repository.js +29 -102
  5. package/dist/alerts/Alert.service.d.ts +3 -35
  6. package/dist/alerts/Alert.service.js +39 -54
  7. package/dist/alerts/AlertBuilder.d.ts +10 -10
  8. package/dist/alerts/AlertBuilder.js +1 -0
  9. package/dist/alerts/alert.types.d.ts +15 -0
  10. package/dist/audit/AuditUtils.js +7 -10
  11. package/dist/config/config.js +5 -0
  12. package/dist/config/config.types.d.ts +1 -1
  13. package/dist/config/constants.d.ts +9 -0
  14. package/dist/config/constants.js +9 -0
  15. package/dist/constants/Event.d.ts +12 -0
  16. package/dist/constants/Event.js +12 -0
  17. package/dist/entities/admin/Admin.repository.d.ts +4 -0
  18. package/dist/entities/admin/Admin.repository.js +31 -0
  19. package/dist/entities/admin/Admin.service.d.ts +4 -0
  20. package/dist/entities/admin/Admin.service.js +124 -14
  21. package/dist/entities/admin/IAdmin.d.ts +39 -0
  22. package/dist/entities/admin/IAdmin.js +2 -0
  23. package/dist/entities/admin/index.d.ts +1 -0
  24. package/dist/entities/admin/index.js +1 -0
  25. package/dist/entities/device/local/interfaces/IDevice.d.ts +12 -0
  26. package/dist/entities/device/local/services/Device.service.d.ts +3 -4
  27. package/dist/entities/device/local/services/Device.service.js +59 -9
  28. package/dist/entities/pms/IPms.d.ts +26 -0
  29. package/dist/entities/pms/index.d.ts +1 -0
  30. package/dist/entities/pms/index.js +1 -0
  31. package/dist/entities/pms/pms.repository.d.ts +8 -0
  32. package/dist/entities/pms/pms.repository.js +98 -0
  33. package/dist/entities/pms/pms.service.d.ts +8 -0
  34. package/dist/entities/pms/pms.service.js +124 -0
  35. package/dist/events/BaseEventHandler.d.ts +2 -2
  36. package/dist/events/BaseEventHandler.js +21 -10
  37. package/dist/issues/Issue.model.d.ts +1 -5
  38. package/dist/issues/Issue.model.js +0 -28
  39. package/dist/issues/Issue.repository.d.ts +4 -42
  40. package/dist/issues/Issue.repository.js +29 -79
  41. package/dist/issues/Issue.service.d.ts +12 -40
  42. package/dist/issues/Issue.service.js +179 -145
  43. package/dist/issues/IssueBuilder.d.ts +11 -11
  44. package/dist/issues/IssueBuilder.js +10 -2
  45. package/dist/issues/IssueService.example.js +128 -15
  46. package/dist/issues/index.d.ts +1 -0
  47. package/dist/issues/index.js +1 -0
  48. package/dist/issues/issue.types.d.ts +17 -2
  49. package/package.json +1 -1
@@ -0,0 +1,98 @@
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.PmsRepository = void 0;
42
+ const typedi_1 = require("typedi");
43
+ const db_1 = require("../../db");
44
+ let PmsRepository = (() => {
45
+ let _classDecorators = [(0, typedi_1.Service)()];
46
+ let _classDescriptor;
47
+ let _classExtraInitializers = [];
48
+ let _classThis;
49
+ var PmsRepository = _classThis = class {
50
+ constructor() {
51
+ this.pmsPostgres = (0, db_1.getPmsPostgresClient)();
52
+ }
53
+ async getSchedule(scheduleId) {
54
+ try {
55
+ const schedule = await this.pmsPostgres.query(`SELECT * FROM dt_schedule WHERE "id" = $1`, [scheduleId]);
56
+ if (schedule.rows.length > 0) {
57
+ return schedule.rows[0];
58
+ }
59
+ return null;
60
+ }
61
+ catch (error) {
62
+ console.error("Error in getSchedule:", error);
63
+ throw new Error("Failed to get schedule");
64
+ }
65
+ }
66
+ async getGuest(guestId) {
67
+ try {
68
+ const guest = await this.pmsPostgres.query(`SELECT * FROM dt_guest WHERE "id" = $1`, [guestId]);
69
+ if (guest.rows.length > 0) {
70
+ return guest.rows[0];
71
+ }
72
+ return null;
73
+ }
74
+ catch (error) {
75
+ console.error("Error in getGuest:", error);
76
+ throw new Error("Failed to get guest");
77
+ }
78
+ }
79
+ // Get Guest Id from dt_schedule_guest_map using scheduleId
80
+ async getGuestId(scheduleId) {
81
+ const guestId = await this.pmsPostgres.query(`SELECT "guestId" FROM dt_schedule_guest_map WHERE "scheduleId" = $1`, [scheduleId]);
82
+ if (guestId.rows.length > 0) {
83
+ return guestId.rows[0].guestId;
84
+ }
85
+ return null;
86
+ }
87
+ };
88
+ __setFunctionName(_classThis, "PmsRepository");
89
+ (() => {
90
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
91
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
92
+ PmsRepository = _classThis = _classDescriptor.value;
93
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
94
+ __runInitializers(_classThis, _classExtraInitializers);
95
+ })();
96
+ return PmsRepository = _classThis;
97
+ })();
98
+ exports.PmsRepository = PmsRepository;
@@ -0,0 +1,8 @@
1
+ import { IGuest, IPmsSchedule } from "./IPms";
2
+ export declare class PmsService {
3
+ private readonly pmsRepository;
4
+ constructor();
5
+ getSchedule(scheduleId: string): Promise<IPmsSchedule | null>;
6
+ getGuest(guestId: string): Promise<IGuest | null>;
7
+ getGuestId(scheduleId: string): Promise<string | null>;
8
+ }
@@ -0,0 +1,124 @@
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 __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
19
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
20
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
21
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
22
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
23
+ var _, done = false;
24
+ for (var i = decorators.length - 1; i >= 0; i--) {
25
+ var context = {};
26
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
27
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
28
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
29
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
30
+ if (kind === "accessor") {
31
+ if (result === void 0) continue;
32
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
33
+ if (_ = accept(result.get)) descriptor.get = _;
34
+ if (_ = accept(result.set)) descriptor.set = _;
35
+ if (_ = accept(result.init)) initializers.unshift(_);
36
+ }
37
+ else if (_ = accept(result)) {
38
+ if (kind === "field") initializers.unshift(_);
39
+ else descriptor[key] = _;
40
+ }
41
+ }
42
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
43
+ done = true;
44
+ };
45
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
46
+ var useValue = arguments.length > 2;
47
+ for (var i = 0; i < initializers.length; i++) {
48
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
49
+ }
50
+ return useValue ? value : void 0;
51
+ };
52
+ var __importStar = (this && this.__importStar) || (function () {
53
+ var ownKeys = function(o) {
54
+ ownKeys = Object.getOwnPropertyNames || function (o) {
55
+ var ar = [];
56
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
57
+ return ar;
58
+ };
59
+ return ownKeys(o);
60
+ };
61
+ return function (mod) {
62
+ if (mod && mod.__esModule) return mod;
63
+ var result = {};
64
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
65
+ __setModuleDefault(result, mod);
66
+ return result;
67
+ };
68
+ })();
69
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
70
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
71
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
72
+ };
73
+ Object.defineProperty(exports, "__esModule", { value: true });
74
+ exports.PmsService = void 0;
75
+ const typedi_1 = __importStar(require("typedi"));
76
+ const pms_repository_1 = require("./pms.repository");
77
+ let PmsService = (() => {
78
+ let _classDecorators = [(0, typedi_1.Service)()];
79
+ let _classDescriptor;
80
+ let _classExtraInitializers = [];
81
+ let _classThis;
82
+ var PmsService = _classThis = class {
83
+ constructor() {
84
+ this.pmsRepository = typedi_1.default.get(pms_repository_1.PmsRepository);
85
+ }
86
+ async getSchedule(scheduleId) {
87
+ if (!scheduleId) {
88
+ throw new Error("Schedule ID is required");
89
+ }
90
+ const schedule = await this.pmsRepository.getSchedule(scheduleId);
91
+ if (!schedule)
92
+ return null;
93
+ return schedule;
94
+ }
95
+ async getGuest(guestId) {
96
+ if (!guestId) {
97
+ throw new Error("Guest ID is required");
98
+ }
99
+ const guest = await this.pmsRepository.getGuest(guestId);
100
+ if (!guest)
101
+ return null;
102
+ return guest;
103
+ }
104
+ async getGuestId(scheduleId) {
105
+ if (!scheduleId) {
106
+ throw new Error("Schedule ID is required");
107
+ }
108
+ const guestId = await this.pmsRepository.getGuestId(scheduleId);
109
+ if (!guestId)
110
+ return null;
111
+ return guestId;
112
+ }
113
+ };
114
+ __setFunctionName(_classThis, "PmsService");
115
+ (() => {
116
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
117
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
118
+ PmsService = _classThis = _classDescriptor.value;
119
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
120
+ __runInitializers(_classThis, _classExtraInitializers);
121
+ })();
122
+ return PmsService = _classThis;
123
+ })();
124
+ exports.PmsService = PmsService;
@@ -15,12 +15,12 @@ export declare abstract class BaseEventHandler implements IEventHandler {
15
15
  handleEvent(event: DeviceEvent): Promise<void>;
16
16
  beforeEvent(event: DeviceEvent): Promise<void>;
17
17
  abstract onEvent(event: DeviceEvent): Promise<void>;
18
- afterEvent(event: DeviceEvent): Promise<void>;
18
+ afterEvent(deviceId: string, event: DeviceEvent, auditBody: IAuditProperties, actionPayload: any, eventType?: string): Promise<void>;
19
19
  /**
20
20
  * Handle multiple events - default implementation processes them sequentially
21
21
  */
22
22
  handleEvents(events: DeviceEvent[]): Promise<void>;
23
- onStateChange(deviceId: string, state: Record<string, any>, event: DeviceEvent, auditProperties: IAuditProperties, eventType?: string): Promise<void>;
23
+ onStateChange(deviceId: string, state: Record<string, any>, auditProperties: IAuditProperties, eventType?: string): Promise<void>;
24
24
  /**
25
25
  * Check if this handler can process the given event type
26
26
  */
@@ -7,6 +7,9 @@ exports.BaseEventHandler = void 0;
7
7
  const config_1 = require("../config/config");
8
8
  const Device_service_1 = require("../entities/device/local/services/Device.service");
9
9
  const typedi_1 = __importDefault(require("typedi"));
10
+ const IAuditProperties_1 = require("../audit/IAuditProperties");
11
+ const audit_1 = require("../audit");
12
+ const constants_1 = require("../constants");
10
13
  class BaseEventHandler {
11
14
  constructor(supportedEventTypes, priority = 100) {
12
15
  this.supportedEventTypes = supportedEventTypes;
@@ -32,19 +35,29 @@ class BaseEventHandler {
32
35
  throw error;
33
36
  }
34
37
  finally {
35
- await this.afterEvent(event);
38
+ await this.afterEvent(event.deviceId, event, {
39
+ resource: IAuditProperties_1.Resource.DEVICE,
40
+ source: constants_1.Source.CLOUD_EVENT,
41
+ propertyId: event.data.propertyId || "",
42
+ deviceId: event.deviceId,
43
+ }, {}, event.eventName);
36
44
  }
37
45
  }
38
46
  async beforeEvent(event) {
39
47
  this.logger.info("[DT | CDL]:[BaseEventHandler]: Before event - Handle Before Event");
40
48
  }
41
- async afterEvent(event) {
42
- this.logger.info("[DT | CDL]:[BaseEventHandler]: After event - Event processing completed", {
43
- eventName: event.eventName,
44
- deviceId: event.deviceId,
45
- handler: this.constructor.name,
49
+ async afterEvent(deviceId, event, auditBody, actionPayload, eventType) {
50
+ await (0, audit_1.pushAudit)({
51
+ auditType: eventType || constants_1.DT_EVENT_TYPES.DEVICE.STATE.CHANGED,
52
+ auditData: {
53
+ ...event.data,
54
+ ...auditBody,
55
+ deviceId,
56
+ actionPayload,
57
+ connectionProvider: event.connectionProvider,
58
+ },
46
59
  });
47
- //TODO: Implement AUDIT Here!
60
+ this.logger.info("[DT | CDL]:[BaseEventHandler]: After event - Event processing completed");
48
61
  }
49
62
  /**
50
63
  * Handle multiple events - default implementation processes them sequentially
@@ -65,11 +78,9 @@ class BaseEventHandler {
65
78
  this.logger.error(`${this.constructor.name}: handleEvents Error`, error);
66
79
  }
67
80
  }
68
- // TODO: Check AuditBody for this function
69
- async onStateChange(deviceId, state, event, auditProperties, eventType) {
81
+ async onStateChange(deviceId, state, auditProperties, eventType) {
70
82
  try {
71
83
  await this.localDeviceService.setState(deviceId, state, auditProperties, eventType);
72
- await this.afterEvent(event);
73
84
  }
74
85
  catch (error) {
75
86
  this.logger.error(`[DT | CDL]:[BaseEventHandler]: Error during state change: ${error.message || error.toString()}`);
@@ -1,5 +1,5 @@
1
1
  import mongoose, { Model } from "mongoose";
2
- import { EntityType, IssueStatus, IssuePriority, IssueDocument as IIssueDocument, CreateIssueData, UpdateIssueData, AddCommentData } from "./issue.types";
2
+ import { IssueDocument as IIssueDocument, CreateIssueData, UpdateIssueData, AddCommentData } from "./issue.types";
3
3
  interface IIssueMethods {
4
4
  addComment(commentData: AddCommentData): void;
5
5
  updateComment(commentId: string, content: string, userId: string): boolean;
@@ -10,11 +10,7 @@ interface IIssueMethods {
10
10
  unassign(unassignedBy: string): void;
11
11
  }
12
12
  interface IIssueModel extends Model<IIssueDocument, {}, IIssueMethods> {
13
- findByProperty(propertyId: string, includeDeleted?: boolean): Promise<IIssueDocument[]>;
14
13
  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
14
  findOverdue(includeDeleted?: boolean): Promise<IIssueDocument[]>;
19
15
  findUpcoming(days?: number, includeDeleted?: boolean): Promise<IIssueDocument[]>;
20
16
  }
@@ -188,13 +188,6 @@ IssueSchema.methods.unassign = function (unassignedBy) {
188
188
  this.updatedBy = unassignedBy;
189
189
  };
190
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
191
  IssueSchema.statics.findByAssignee = function (assignedTo, includeDeleted = false) {
199
192
  const query = { assignedTo };
200
193
  if (!includeDeleted) {
@@ -202,27 +195,6 @@ IssueSchema.statics.findByAssignee = function (assignedTo, includeDeleted = fals
202
195
  }
203
196
  return this.find(query).sort({ priority: -1, createdAt: -1 });
204
197
  };
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
198
  IssueSchema.statics.findOverdue = function (includeDeleted = false) {
227
199
  const query = {
228
200
  dueDate: { $lt: new Date() },
@@ -1,6 +1,7 @@
1
1
  import { IIssueDocument } from "./Issue.model";
2
- import { CreateIssueData, UpdateIssueData, IssueStatus, IssuePriority, IssuesCategory, EntityType } from "./issue.types";
2
+ import { CreateIssueData, UpdateIssueData, IssuePriority, IssuesCategory, IIssueQuery } from "./issue.types";
3
3
  export declare class IssueRepository {
4
+ private buildQuery;
4
5
  /**
5
6
  * Create a new issue
6
7
  */
@@ -12,21 +13,7 @@ export declare class IssueRepository {
12
13
  /**
13
14
  * Find all issues with filters
14
15
  */
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[]>;
16
+ query(filters?: IIssueQuery): Promise<IIssueDocument[]>;
30
17
  /**
31
18
  * Update an issue
32
19
  */
@@ -42,36 +29,11 @@ export declare class IssueRepository {
42
29
  /**
43
30
  * Count issues with filters
44
31
  */
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[]>;
32
+ count(filters?: IIssueQuery): Promise<number>;
59
33
  /**
60
34
  * Find issues by assignee
61
35
  */
62
36
  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
37
  /**
76
38
  * Find overdue issues
77
39
  */
@@ -48,6 +48,32 @@ let IssueRepository = (() => {
48
48
  let _classExtraInitializers = [];
49
49
  let _classThis;
50
50
  var IssueRepository = _classThis = class {
51
+ async buildQuery(filters) {
52
+ const query = {};
53
+ if (filters.propertyId)
54
+ query.propertyId = filters.propertyId;
55
+ if (filters.assignedTo)
56
+ query.assignedTo = filters.assignedTo;
57
+ if (filters.status)
58
+ query.status = filters.status;
59
+ if (filters.priority)
60
+ query.priority = filters.priority;
61
+ if (filters.category)
62
+ query.category = filters.category;
63
+ if (filters.entityType)
64
+ query.entityType = filters.entityType;
65
+ if (filters.entityId)
66
+ query.entityId = filters.entityId;
67
+ if (!filters.includeDeleted)
68
+ query.isDeleted = false;
69
+ if (filters.sort)
70
+ query.sort = filters.sort;
71
+ if (filters.limit)
72
+ query.limit = filters.limit;
73
+ if (filters.skip)
74
+ query.skip = filters.skip;
75
+ return query;
76
+ }
51
77
  /**
52
78
  * Create a new issue
53
79
  */
@@ -83,25 +109,9 @@ let IssueRepository = (() => {
83
109
  /**
84
110
  * Find all issues with filters
85
111
  */
86
- async findAll(filters = {}) {
112
+ async query(filters = {}) {
87
113
  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;
114
+ const query = await this.buildQuery(filters);
105
115
  const queryBuilder = Issue_model_1.IssueModel.find(query);
106
116
  if (filters.sort) {
107
117
  queryBuilder.sort(filters.sort);
@@ -163,40 +173,13 @@ let IssueRepository = (() => {
163
173
  */
164
174
  async count(filters = {}) {
165
175
  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;
176
+ const query = await this.buildQuery(filters);
183
177
  return await Issue_model_1.IssueModel.countDocuments(query);
184
178
  }
185
179
  catch (error) {
186
180
  throw new Error(`Failed to count issues: ${error instanceof Error ? error.message : "Unknown error"}`);
187
181
  }
188
182
  }
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
183
  /**
201
184
  * Find issues by assignee
202
185
  */
@@ -208,39 +191,6 @@ let IssueRepository = (() => {
208
191
  throw new Error(`Failed to find issues by assignee: ${error instanceof Error ? error.message : "Unknown error"}`);
209
192
  }
210
193
  }
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
194
  /**
245
195
  * Find overdue issues
246
196
  */