@talkpilot/core-db 1.2.2 → 1.3.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 (100) hide show
  1. package/.cursor/rules/development.mdc +65 -65
  2. package/DEVELOPMENT.md +98 -98
  3. package/README.md +169 -139
  4. package/README_OLD.md +160 -160
  5. package/dist/municipal/tickets/index.d.ts +2 -1
  6. package/dist/municipal/tickets/index.d.ts.map +1 -1
  7. package/dist/municipal/tickets/index.js +1 -0
  8. package/dist/municipal/tickets/index.js.map +1 -1
  9. package/dist/municipal/tickets/tickets.constants.d.ts +7 -0
  10. package/dist/municipal/tickets/tickets.constants.d.ts.map +1 -0
  11. package/dist/municipal/tickets/tickets.constants.js +10 -0
  12. package/dist/municipal/tickets/tickets.constants.js.map +1 -0
  13. package/dist/municipal/tickets/tickets.deprecated.getters.d.ts +12 -0
  14. package/dist/municipal/tickets/tickets.deprecated.getters.d.ts.map +1 -0
  15. package/dist/municipal/tickets/tickets.deprecated.getters.js +131 -0
  16. package/dist/municipal/tickets/tickets.deprecated.getters.js.map +1 -0
  17. package/dist/municipal/tickets/tickets.getters.d.ts +0 -11
  18. package/dist/municipal/tickets/tickets.getters.d.ts.map +1 -1
  19. package/dist/municipal/tickets/tickets.getters.js +0 -128
  20. package/dist/municipal/tickets/tickets.getters.js.map +1 -1
  21. package/dist/municipal/tickets/tickets.statistics.aggregation.d.ts +45 -0
  22. package/dist/municipal/tickets/tickets.statistics.aggregation.d.ts.map +1 -0
  23. package/dist/municipal/tickets/tickets.statistics.aggregation.js +98 -0
  24. package/dist/municipal/tickets/tickets.statistics.aggregation.js.map +1 -0
  25. package/dist/municipal/tickets/tickets.statistics.dates.d.ts +7 -0
  26. package/dist/municipal/tickets/tickets.statistics.dates.d.ts.map +1 -0
  27. package/dist/municipal/tickets/tickets.statistics.dates.js +40 -0
  28. package/dist/municipal/tickets/tickets.statistics.dates.js.map +1 -0
  29. package/dist/municipal/tickets/tickets.statistics.getters.d.ts +9 -0
  30. package/dist/municipal/tickets/tickets.statistics.getters.d.ts.map +1 -0
  31. package/dist/municipal/tickets/tickets.statistics.getters.js +55 -0
  32. package/dist/municipal/tickets/tickets.statistics.getters.js.map +1 -0
  33. package/dist/municipal/tickets/tickets.statistics.pipeline.d.ts +53 -0
  34. package/dist/municipal/tickets/tickets.statistics.pipeline.d.ts.map +1 -0
  35. package/dist/municipal/tickets/tickets.statistics.pipeline.js +112 -0
  36. package/dist/municipal/tickets/tickets.statistics.pipeline.js.map +1 -0
  37. package/dist/municipal/tickets/tickets.statistics.utils.d.ts +7 -0
  38. package/dist/municipal/tickets/tickets.statistics.utils.d.ts.map +1 -0
  39. package/dist/municipal/tickets/tickets.statistics.utils.js +40 -0
  40. package/dist/municipal/tickets/tickets.statistics.utils.js.map +1 -0
  41. package/dist/municipal/tickets/tickets.types.d.ts +10 -5
  42. package/dist/municipal/tickets/tickets.types.d.ts.map +1 -1
  43. package/dist/talkpilot/calls/calls.constants.d.ts +17 -0
  44. package/dist/talkpilot/calls/calls.constants.d.ts.map +1 -0
  45. package/dist/talkpilot/calls/calls.constants.js +20 -0
  46. package/dist/talkpilot/calls/calls.constants.js.map +1 -0
  47. package/dist/talkpilot/calls/calls.statistics.getters.d.ts +19 -0
  48. package/dist/talkpilot/calls/calls.statistics.getters.d.ts.map +1 -0
  49. package/dist/talkpilot/calls/calls.statistics.getters.js +375 -0
  50. package/dist/talkpilot/calls/calls.statistics.getters.js.map +1 -0
  51. package/dist/talkpilot/calls/calls.statistics.ticketScope.d.ts +12 -0
  52. package/dist/talkpilot/calls/calls.statistics.ticketScope.d.ts.map +1 -0
  53. package/dist/talkpilot/calls/calls.statistics.ticketScope.js +37 -0
  54. package/dist/talkpilot/calls/calls.statistics.ticketScope.js.map +1 -0
  55. package/dist/talkpilot/calls/calls.statistics.tickets.d.ts +17 -0
  56. package/dist/talkpilot/calls/calls.statistics.tickets.d.ts.map +1 -0
  57. package/dist/talkpilot/calls/calls.statistics.tickets.js +33 -0
  58. package/dist/talkpilot/calls/calls.statistics.tickets.js.map +1 -0
  59. package/dist/talkpilot/calls/calls.statistics.types.d.ts +39 -0
  60. package/dist/talkpilot/calls/calls.statistics.types.d.ts.map +1 -0
  61. package/dist/talkpilot/calls/calls.statistics.types.js +3 -0
  62. package/dist/talkpilot/calls/calls.statistics.types.js.map +1 -0
  63. package/dist/talkpilot/calls/calls.types.d.ts +3 -3
  64. package/dist/talkpilot/calls/calls.types.d.ts.map +1 -1
  65. package/dist/talkpilot/calls/calls.types.js +0 -3
  66. package/dist/talkpilot/calls/calls.types.js.map +1 -1
  67. package/dist/talkpilot/calls/index.d.ts +3 -0
  68. package/dist/talkpilot/calls/index.d.ts.map +1 -1
  69. package/dist/talkpilot/calls/index.js +3 -0
  70. package/dist/talkpilot/calls/index.js.map +1 -1
  71. package/dist/utils/date.utils.d.ts +49 -0
  72. package/dist/utils/date.utils.d.ts.map +1 -0
  73. package/dist/utils/date.utils.js +103 -0
  74. package/dist/utils/date.utils.js.map +1 -0
  75. package/dist/utils/statistics.aggregation.d.ts +20 -0
  76. package/dist/utils/statistics.aggregation.d.ts.map +1 -0
  77. package/dist/utils/statistics.aggregation.js +43 -0
  78. package/dist/utils/statistics.aggregation.js.map +1 -0
  79. package/jest.config.js +19 -19
  80. package/package.json +46 -46
  81. package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +1 -37
  82. package/src/municipal/tickets/__tests__/tickets.statistics.spec.ts +104 -0
  83. package/src/municipal/tickets/index.ts +2 -1
  84. package/src/municipal/tickets/tickets.constants.ts +8 -0
  85. package/src/municipal/tickets/tickets.getters.ts +0 -140
  86. package/src/municipal/tickets/tickets.statistics.aggregation.ts +113 -0
  87. package/src/municipal/tickets/tickets.statistics.getters.ts +93 -0
  88. package/src/municipal/tickets/tickets.types.ts +14 -9
  89. package/src/talkpilot/calls/__tests__/calls.statistics.spec.ts +281 -0
  90. package/src/talkpilot/calls/calls.constants.ts +20 -0
  91. package/src/talkpilot/calls/calls.statistics.getters.ts +525 -0
  92. package/src/talkpilot/calls/calls.statistics.types.ts +44 -0
  93. package/src/talkpilot/calls/calls.types.ts +6 -3
  94. package/src/talkpilot/calls/index.ts +3 -0
  95. package/src/utils/date.utils.ts +116 -0
  96. package/tsconfig.json +23 -23
  97. package/dist/talkpilot/calls/calls.dashboard.d.ts +0 -3
  98. package/dist/talkpilot/calls/calls.dashboard.d.ts.map +0 -1
  99. package/dist/talkpilot/calls/calls.dashboard.js +0 -191
  100. package/dist/talkpilot/calls/calls.dashboard.js.map +0 -1
package/README_OLD.md CHANGED
@@ -1,160 +1,160 @@
1
- # @talkpilot/core-db
2
-
3
- [NPM Version](https://www.npmjs.com/package/@talkpilot/core-db)
4
-
5
- A TypeScript-based core database management package designed to provide centralized database connections, ORM integrations, and client utilities for other projects. This package manages connections to both **TalkPilot** and **Municipal** MongoDB databases.
6
-
7
- ## Features
8
-
9
- - 🚀 **Multi-Domain Database Management**: Centralized handlers for both TalkPilot and Municipal Data domains.
10
- - 📦 **Reusable Getters**: Standardized functions for fetching data from various collections (calls, agents, leads, cities, etc.).
11
- - 🏗️ **Type-safe**: Built with TypeScript for full type safety across all your database interactions.
12
- - 🛠️ **Environment Aware**: Configurable via environment variables or explicit parameters.
13
-
14
- ## Installation
15
-
16
- This package is intended to be used as a dependency in other projects. If you're working locally, you can install it using a file path:
17
-
18
- ```bash
19
- # In your other project:
20
- npm install /path/to/core-db
21
- # or if published to a registry:
22
- npm install @talkpilot/core-db
23
- # or via GitHub
24
- npm install github:talkpilot/core-db
25
- ```
26
-
27
- ## Quick Start
28
-
29
- ### 1. Initialize Database Connections
30
-
31
- You must initialize the database clients before using any of the getters.
32
-
33
- ```typescript
34
- import { mongodbClient, municipalDataMongodbClient } from '@talkpilot/core-db';
35
-
36
- async function bootstrap() {
37
- // Initialize TalkPilot DB
38
- await mongodbClient.connect(process.env.TALKPILOT_MONGO_URI);
39
-
40
- // Initialize Municipal Data DB (optional)
41
- await municipalDataMongodbClient.connect(process.env.MUNICIPAL_MONGO_URI);
42
- }
43
-
44
- bootstrap().catch(console.error);
45
- ```
46
-
47
- ### 2. Using Getters
48
-
49
- Once initialized, you can import and use any of the exported database getters.
50
-
51
- ```typescript
52
- import { findAgents, findCities } from '@talkpilot/core-db';
53
-
54
- async function getSummary() {
55
- // Get all agents from TalkPilot DB
56
- const agents = await findAgents();
57
- console.log('Total Agents:', agents.length);
58
-
59
- // Get all cities from Municipal Data DB
60
- const cities = await findCities();
61
- console.log('Total Cities:', cities.length);
62
- }
63
- ```
64
-
65
- ## Available Domains
66
-
67
- The package exports two main sets of tools:
68
-
69
- ### TalkPilot Domain
70
-
71
- Includes access to:
72
-
73
- - `agents`, `calls`, `clients`, `flows`, `leads`, `phone_numbers`, `plans`, `results`, `sessions`, `subscriptions`, etc.
74
- - Exported as root level functions or via `mongodbClient`.
75
-
76
- ### Municipal Domain
77
-
78
- Includes access to:
79
-
80
- - `cities`, `streets`, `departmentsSubjects`, `tickets`.
81
- - Functions are prefixed where necessary or accessible via `getMunicipalDataDb`.
82
-
83
- ## Environment Variables
84
-
85
- The clients will automatically attempt to use the following environment variables if no URI is provided to the `connect()` method:
86
-
87
- - `MONGO_URI` or `MONGODB_URI`: Primary MongoDB connection string.
88
- - `MONGODB_DB_NAME`: Database name (defaults to 'municipal-data' for the municipal client if not specified).
89
-
90
- ## Development
91
-
92
- ### Setup
93
-
94
- 1. Clone the repository and install dependencies:
95
- ```bash
96
- git clone https://github.com/talkpilot/core-db.git
97
- cd core-db
98
- npm install
99
- ```
100
- 2. Build the project:
101
- ```bash
102
- npm run build
103
- ```
104
-
105
- This will generate the `dist/` directory with the compiled JavaScript and type definitions.
106
-
107
- ### Publishing New Versions
108
-
109
- To publish a new version of the package:
110
-
111
- 1. **Test your changes**:
112
- ```bash
113
- npm test
114
- ```
115
- 2. **Update the version**:
116
- ```bash
117
- # Bumps patch version (0.1.0 -> 0.1.1)
118
- npm version patch
119
- # Or for minor changes (0.1.0 -> 0.2.0)
120
- # npm version minor
121
- # Or for major changes (0.1.0 -> 1.0.0)
122
- # npm version major
123
- ```
124
- 3. **Publish to npm**:
125
- Ensure you have the shared team token in your `~/.npmrc` (see [Development Guide](./DEVELOPMENT.md#team-access--authentication)).
126
- 4. **Update in other repos**:
127
- ```bash
128
- npm update @talkpilot/core-db
129
- ```
130
-
131
- ## License
132
-
133
- MIT
134
-
135
- ---
136
-
137
- **Interested in contributing?** Check out our [Development Guide](./DEVELOPMENT.md) for standards and setup instructions.
138
-
139
- ## Release Notes
140
-
141
- ### 1.1.9
142
-
143
- - `getPhoneNumbersForFlows(clientId)` — lists each phone number linked to a flow for that client (newest first), with `flowId`, `phoneNumber`, and `isPrimary`.
144
- ### 1.1.5
145
-
146
- - `createPurchasedPhoneNumber` for API-bought numbers (Twilio/Telnyx metadata); optional `flowId` until linked to a flow. Types/schema updated accordingly.
147
-
148
- ### 1.0.16
149
-
150
- - Fixed critical issues present in version 1.0.15.
151
- - **Warning**: Version 1.0.15 is bugged and should not be used. Please use at least version 1.0.16.
152
-
153
- ### 1.0.20
154
-
155
- - Added to Moked106Config this param: withNeedAttentionCalls
156
- - withNeedAttentionCalls?: boolean
157
-
158
- ### 1.0.27
159
- - Added an optional `language` field to `ClientConfig` (e.g. Hebrew/English/Russian/French/Spanish) and updated tests.
160
-
1
+ # @talkpilot/core-db
2
+
3
+ [NPM Version](https://www.npmjs.com/package/@talkpilot/core-db)
4
+
5
+ A TypeScript-based core database management package designed to provide centralized database connections, ORM integrations, and client utilities for other projects. This package manages connections to both **TalkPilot** and **Municipal** MongoDB databases.
6
+
7
+ ## Features
8
+
9
+ - 🚀 **Multi-Domain Database Management**: Centralized handlers for both TalkPilot and Municipal Data domains.
10
+ - 📦 **Reusable Getters**: Standardized functions for fetching data from various collections (calls, agents, leads, cities, etc.).
11
+ - 🏗️ **Type-safe**: Built with TypeScript for full type safety across all your database interactions.
12
+ - 🛠️ **Environment Aware**: Configurable via environment variables or explicit parameters.
13
+
14
+ ## Installation
15
+
16
+ This package is intended to be used as a dependency in other projects. If you're working locally, you can install it using a file path:
17
+
18
+ ```bash
19
+ # In your other project:
20
+ npm install /path/to/core-db
21
+ # or if published to a registry:
22
+ npm install @talkpilot/core-db
23
+ # or via GitHub
24
+ npm install github:talkpilot/core-db
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ### 1. Initialize Database Connections
30
+
31
+ You must initialize the database clients before using any of the getters.
32
+
33
+ ```typescript
34
+ import { mongodbClient, municipalDataMongodbClient } from '@talkpilot/core-db';
35
+
36
+ async function bootstrap() {
37
+ // Initialize TalkPilot DB
38
+ await mongodbClient.connect(process.env.TALKPILOT_MONGO_URI);
39
+
40
+ // Initialize Municipal Data DB (optional)
41
+ await municipalDataMongodbClient.connect(process.env.MUNICIPAL_MONGO_URI);
42
+ }
43
+
44
+ bootstrap().catch(console.error);
45
+ ```
46
+
47
+ ### 2. Using Getters
48
+
49
+ Once initialized, you can import and use any of the exported database getters.
50
+
51
+ ```typescript
52
+ import { findAgents, findCities } from '@talkpilot/core-db';
53
+
54
+ async function getSummary() {
55
+ // Get all agents from TalkPilot DB
56
+ const agents = await findAgents();
57
+ console.log('Total Agents:', agents.length);
58
+
59
+ // Get all cities from Municipal Data DB
60
+ const cities = await findCities();
61
+ console.log('Total Cities:', cities.length);
62
+ }
63
+ ```
64
+
65
+ ## Available Domains
66
+
67
+ The package exports two main sets of tools:
68
+
69
+ ### TalkPilot Domain
70
+
71
+ Includes access to:
72
+
73
+ - `agents`, `calls`, `clients`, `flows`, `leads`, `phone_numbers`, `plans`, `results`, `sessions`, `subscriptions`, etc.
74
+ - Exported as root level functions or via `mongodbClient`.
75
+
76
+ ### Municipal Domain
77
+
78
+ Includes access to:
79
+
80
+ - `cities`, `streets`, `departmentsSubjects`, `tickets`.
81
+ - Functions are prefixed where necessary or accessible via `getMunicipalDataDb`.
82
+
83
+ ## Environment Variables
84
+
85
+ The clients will automatically attempt to use the following environment variables if no URI is provided to the `connect()` method:
86
+
87
+ - `MONGO_URI` or `MONGODB_URI`: Primary MongoDB connection string.
88
+ - `MONGODB_DB_NAME`: Database name (defaults to 'municipal-data' for the municipal client if not specified).
89
+
90
+ ## Development
91
+
92
+ ### Setup
93
+
94
+ 1. Clone the repository and install dependencies:
95
+ ```bash
96
+ git clone https://github.com/talkpilot/core-db.git
97
+ cd core-db
98
+ npm install
99
+ ```
100
+ 2. Build the project:
101
+ ```bash
102
+ npm run build
103
+ ```
104
+
105
+ This will generate the `dist/` directory with the compiled JavaScript and type definitions.
106
+
107
+ ### Publishing New Versions
108
+
109
+ To publish a new version of the package:
110
+
111
+ 1. **Test your changes**:
112
+ ```bash
113
+ npm test
114
+ ```
115
+ 2. **Update the version**:
116
+ ```bash
117
+ # Bumps patch version (0.1.0 -> 0.1.1)
118
+ npm version patch
119
+ # Or for minor changes (0.1.0 -> 0.2.0)
120
+ # npm version minor
121
+ # Or for major changes (0.1.0 -> 1.0.0)
122
+ # npm version major
123
+ ```
124
+ 3. **Publish to npm**:
125
+ Ensure you have the shared team token in your `~/.npmrc` (see [Development Guide](./DEVELOPMENT.md#team-access--authentication)).
126
+ 4. **Update in other repos**:
127
+ ```bash
128
+ npm update @talkpilot/core-db
129
+ ```
130
+
131
+ ## License
132
+
133
+ MIT
134
+
135
+ ---
136
+
137
+ **Interested in contributing?** Check out our [Development Guide](./DEVELOPMENT.md) for standards and setup instructions.
138
+
139
+ ## Release Notes
140
+
141
+ ### 1.1.9
142
+
143
+ - `getPhoneNumbersForFlows(clientId)` — lists each phone number linked to a flow for that client (newest first), with `flowId`, `phoneNumber`, and `isPrimary`.
144
+ ### 1.1.5
145
+
146
+ - `createPurchasedPhoneNumber` for API-bought numbers (Twilio/Telnyx metadata); optional `flowId` until linked to a flow. Types/schema updated accordingly.
147
+
148
+ ### 1.0.16
149
+
150
+ - Fixed critical issues present in version 1.0.15.
151
+ - **Warning**: Version 1.0.15 is bugged and should not be used. Please use at least version 1.0.16.
152
+
153
+ ### 1.0.20
154
+
155
+ - Added to Moked106Config this param: withNeedAttentionCalls
156
+ - withNeedAttentionCalls?: boolean
157
+
158
+ ### 1.0.27
159
+ - Added an optional `language` field to `ClientConfig` (e.g. Hebrew/English/Russian/French/Spanish) and updated tests.
160
+
@@ -1,3 +1,4 @@
1
1
  export * from "./tickets.getters";
2
- export type { Ticket, TicketDoc, SubjectStatsItem } from "./tickets.types";
2
+ export * from "./tickets.statistics.getters";
3
+ export type { Ticket, TicketDoc, SubjectItem, TicketStatsDateScope } from "./tickets.types";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/municipal/tickets/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/municipal/tickets/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./tickets.getters"), exports);
18
+ __exportStar(require("./tickets.statistics.getters"), exports);
18
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/municipal/tickets/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/municipal/tickets/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,+DAA6C"}
@@ -0,0 +1,7 @@
1
+ /** Label used when a ticket has no resolvable department/subject. */
2
+ export declare const UNCLASSIFIED = "\u05DC\u05DC\u05D0 \u05DE\u05D7\u05DC\u05E7\u05D4";
3
+ /** Max execution time (ms) for ticket statistics aggregations. */
4
+ export declare const STATS_MAX_TIME_MS = 30000;
5
+ /** Default look-back window (days) for ticket statistics date ranges. */
6
+ export declare const DEFAULT_LOOKBACK_DAYS = 30;
7
+ //# sourceMappingURL=tickets.constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tickets.constants.d.ts","sourceRoot":"","sources":["../../../src/municipal/tickets/tickets.constants.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,eAAO,MAAM,YAAY,sDAAc,CAAC;AAExC,kEAAkE;AAClE,eAAO,MAAM,iBAAiB,QAAS,CAAC;AAExC,yEAAyE;AACzE,eAAO,MAAM,qBAAqB,KAAK,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_LOOKBACK_DAYS = exports.STATS_MAX_TIME_MS = exports.UNCLASSIFIED = void 0;
4
+ /** Label used when a ticket has no resolvable department/subject. */
5
+ exports.UNCLASSIFIED = "ללא מחלקה";
6
+ /** Max execution time (ms) for ticket statistics aggregations. */
7
+ exports.STATS_MAX_TIME_MS = 30_000;
8
+ /** Default look-back window (days) for ticket statistics date ranges. */
9
+ exports.DEFAULT_LOOKBACK_DAYS = 30;
10
+ //# sourceMappingURL=tickets.constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tickets.constants.js","sourceRoot":"","sources":["../../../src/municipal/tickets/tickets.constants.ts"],"names":[],"mappings":";;;AAAA,qEAAqE;AACxD,QAAA,YAAY,GAAG,WAAW,CAAC;AAExC,kEAAkE;AACrD,QAAA,iBAAiB,GAAG,MAAM,CAAC;AAExC,yEAAyE;AAC5D,QAAA,qBAAqB,GAAG,EAAE,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { SubjectStatsItem } from "./tickets.types";
2
+ /**
3
+ * @deprecated Use `findCallSidsWithTicketsByCity` with `ticketStatsDateScopeFromYmd` instead.
4
+ * Will be removed in 3.0.0.
5
+ */
6
+ export declare function getTicketsCountByCityAndDateRange(cityName: string, startStr: string, endStr: string, timezone: string): Promise<number>;
7
+ /**
8
+ * @deprecated Use `findFilteredCallSids` + `findSubjectsByCallSids` instead.
9
+ * Will be removed in 3.0.0.
10
+ */
11
+ export declare function getTicketsSubjectStats(cityName: string, startStr: string, endStr: string, timezone: string): Promise<SubjectStatsItem[]>;
12
+ //# sourceMappingURL=tickets.deprecated.getters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tickets.deprecated.getters.d.ts","sourceRoot":"","sources":["../../../src/municipal/tickets/tickets.deprecated.getters.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD;;;GAGG;AACH,wBAAsB,iCAAiC,CACrD,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAgBjB;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAoG7B"}
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTicketsCountByCityAndDateRange = getTicketsCountByCityAndDateRange;
4
+ exports.getTicketsSubjectStats = getTicketsSubjectStats;
5
+ const tickets_getters_1 = require("./tickets.getters");
6
+ /**
7
+ * @deprecated Use `findCallSidsWithTicketsByCity` with `ticketStatsDateScopeFromYmd` instead.
8
+ * Will be removed in 3.0.0.
9
+ */
10
+ async function getTicketsCountByCityAndDateRange(cityName, startStr, endStr, timezone) {
11
+ const doc = await (0, tickets_getters_1.getTicketsCollection)()
12
+ .aggregate([
13
+ { $match: { cityName, callSid: { $exists: true, $nin: [null, ""] } } },
14
+ {
15
+ $addFields: {
16
+ dateLocal: {
17
+ $dateToString: { format: "%Y-%m-%d", date: "$createdAt", timezone },
18
+ },
19
+ },
20
+ },
21
+ { $match: { dateLocal: { $gte: startStr, $lte: endStr } } },
22
+ { $count: "n" },
23
+ ])
24
+ .next();
25
+ return doc?.n ?? 0;
26
+ }
27
+ /**
28
+ * @deprecated Use `findFilteredCallSids` + `findSubjectsByCallSids` instead.
29
+ * Will be removed in 3.0.0.
30
+ */
31
+ async function getTicketsSubjectStats(cityName, startStr, endStr, timezone) {
32
+ const rows = await (0, tickets_getters_1.getTicketsCollection)()
33
+ .aggregate([
34
+ { $match: { cityName } },
35
+ {
36
+ $addFields: {
37
+ dateLocal: {
38
+ $dateToString: { format: "%Y-%m-%d", date: "$createdAt", timezone },
39
+ },
40
+ },
41
+ },
42
+ { $match: { dateLocal: { $gte: startStr, $lte: endStr } } },
43
+ {
44
+ $addFields: {
45
+ effectiveSubjectId: {
46
+ $ifNull: [
47
+ "$externalCallFields.event_subject_id",
48
+ {
49
+ $ifNull: [
50
+ "$externalCallFields.event_sub_subject_id",
51
+ "$externalCallFields.event_sub_subject_id2",
52
+ ],
53
+ },
54
+ ],
55
+ },
56
+ },
57
+ },
58
+ {
59
+ $lookup: {
60
+ from: "departmentsSubjects",
61
+ let: { sid: "$effectiveSubjectId", c: cityName },
62
+ pipeline: [
63
+ {
64
+ $match: {
65
+ $expr: {
66
+ $and: [
67
+ { $eq: ["$cityName", "$$c"] },
68
+ {
69
+ $or: [
70
+ { $eq: ["$subject_id", { $ifNull: ["$$sid", ""] }] },
71
+ {
72
+ $eq: ["$sub_subject_id", { $ifNull: ["$$sid", ""] }],
73
+ },
74
+ {
75
+ $eq: ["$sub_subject_id2", { $ifNull: ["$$sid", ""] }],
76
+ },
77
+ ],
78
+ },
79
+ ],
80
+ },
81
+ },
82
+ },
83
+ { $limit: 1 },
84
+ ],
85
+ as: "subj",
86
+ },
87
+ },
88
+ {
89
+ $addFields: {
90
+ subject_id: {
91
+ $cond: {
92
+ if: { $gt: [{ $size: "$subj" }, 0] },
93
+ then: {
94
+ $ifNull: [{ $arrayElemAt: ["$subj.subject_id", 0] }, ""],
95
+ },
96
+ else: "",
97
+ },
98
+ },
99
+ subject: {
100
+ $cond: {
101
+ if: { $gt: [{ $size: "$subj" }, 0] },
102
+ then: {
103
+ $ifNull: [
104
+ { $arrayElemAt: ["$subj.subjectName", 0] },
105
+ "Unclassified",
106
+ ],
107
+ },
108
+ else: "Unclassified",
109
+ },
110
+ },
111
+ },
112
+ },
113
+ {
114
+ $group: {
115
+ _id: "$subject_id",
116
+ subject: { $first: "$subject" },
117
+ count: { $sum: 1 },
118
+ },
119
+ },
120
+ { $sort: { count: -1 } },
121
+ ])
122
+ .toArray();
123
+ const total = rows.reduce((sum, row) => sum + row.count, 0);
124
+ return rows.map((row) => ({
125
+ subject_name: row.subject,
126
+ subject_id: row._id,
127
+ count: row.count,
128
+ percentage: total > 0 ? Math.round((row.count / total) * 100) : 0,
129
+ }));
130
+ }
131
+ //# sourceMappingURL=tickets.deprecated.getters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tickets.deprecated.getters.js","sourceRoot":"","sources":["../../../src/municipal/tickets/tickets.deprecated.getters.ts"],"names":[],"mappings":";;AAOA,8EAqBC;AAMD,wDAyGC;AA3ID,uDAAyD;AAGzD;;;GAGG;AACI,KAAK,UAAU,iCAAiC,CACrD,QAAgB,EAChB,QAAgB,EAChB,MAAc,EACd,QAAgB;IAEhB,MAAM,GAAG,GAAG,MAAM,IAAA,sCAAoB,GAAE;SACrC,SAAS,CAAgB;QACxB,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAA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,EAAE,MAAM,EAAE,UAAU,EAAE;gBAC/B,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;aACnB;SACF;QACD,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE;KACzB,CAAC;SACD,OAAO,EAAE,CAAC;IAEb,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC5D,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QACxB,YAAY,EAAE,GAAG,CAAC,OAAO;QACzB,UAAU,EAAE,GAAG,CAAC,GAAG;QACnB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,UAAU,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;KAClE,CAAC,CAAC,CAAC;AACN,CAAC"}
@@ -1,5 +1,4 @@
1
1
  import { CityName, Ticket } from "../index";
2
- import type { SubjectStatsItem } from "./tickets.types";
3
2
  import { Collection, Filter, ObjectId as MongoObjectId } from "mongodb";
4
3
  /**
5
4
  * Generate a new ticket ID as a string
@@ -13,16 +12,6 @@ export declare const getTicketById: (ticketId: string) => Promise<Ticket | null>
13
12
  export declare const createTicket: (ticketData: Omit<Ticket, "_id" | "createdAt" | "updatedAt">, ticketId?: string) => Promise<MongoObjectId>;
14
13
  export declare const updateTicket: (ticketId: string, data: Partial<Omit<Ticket, "_id" | "createdAt" | "updatedAt">>) => Promise<Ticket | null>;
15
14
  export declare const deleteTicket: (ticketId: string) => Promise<boolean>;
16
- /**
17
- * Count tickets by city and date range (createdAt converted to given timezone).
18
- * Used as "open" tickets count when status is not available.
19
- */
20
- export declare function getTicketsCountByCityAndDateRange(cityName: string, startStr: string, endStr: string, timezone: string): Promise<number>;
21
- /**
22
- * Count of tickets by department (subject) from departmentsSubjects. Different departments (subject_id) are grouped, and sub-subjects are unified under their department.
23
- * Date filter: createdAt in [startStr, endStr] (in the given timezone). Fallback to "Unclassified" when no match is found in the lookup.
24
- */
25
- export declare function getTicketsSubjectStats(cityName: string, startStr: string, endStr: string, timezone: string): Promise<SubjectStatsItem[]>;
26
15
  export declare const findTicketByQuery: (query: Partial<Ticket>) => Promise<import("mongodb").WithId<Ticket> | null>;
27
16
  /**
28
17
  * Update ticket files by external call number
@@ -1 +1 @@
1
- {"version":3,"file":"tickets.getters.d.ts","sourceRoot":"","sources":["../../../src/municipal/tickets/tickets.getters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAmB,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,SAAS,CAAC;AAExE;;;GAGG;AACH,eAAO,MAAM,gBAAgB,QAAO,MAEnC,CAAC;AAEF,eAAO,MAAM,oBAAoB,QAAO,UAAU,CAAC,MAAM,CAExD,CAAC;AAEF,eAAO,MAAM,WAAW,GACtB,SAAQ,MAAM,CAAC,MAAM,CAAM,KAC1B,OAAO,CAAC,MAAM,EAAE,CAElB,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,SAAS,MAAM,KACd,OAAO,CAAC,MAAM,EAAE,CAElB,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,UAAU,MAAM,KACf,OAAO,CAAC,MAAM,GAAG,IAAI,CAKvB,CAAC;AAEF,eAAO,MAAM,YAAY,GACvB,YAAY,IAAI,CAAC,MAAM,EAAE,KAAK,GAAG,WAAW,GAAG,WAAW,CAAC,EAC3D,WAAW,MAAM,KAChB,OAAO,CAAC,aAAa,CASvB,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