@talkpilot/core-db 1.3.7 → 1.3.9

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 (199) hide show
  1. package/.claude/settings.local.json +11 -0
  2. package/.cursor/rules/development.mdc +65 -65
  3. package/DEVELOPMENT.md +141 -141
  4. package/README.md +257 -190
  5. package/README_OLD.md +160 -160
  6. package/dist/municipal/tickets/tickets.deprecated.getters.d.ts +12 -0
  7. package/dist/municipal/tickets/tickets.deprecated.getters.d.ts.map +1 -0
  8. package/dist/municipal/tickets/tickets.deprecated.getters.js +131 -0
  9. package/dist/municipal/tickets/tickets.deprecated.getters.js.map +1 -0
  10. package/dist/municipal/tickets/tickets.statistics.dates.d.ts +7 -0
  11. package/dist/municipal/tickets/tickets.statistics.dates.d.ts.map +1 -0
  12. package/dist/municipal/tickets/tickets.statistics.dates.js +40 -0
  13. package/dist/municipal/tickets/tickets.statistics.dates.js.map +1 -0
  14. package/dist/municipal/tickets/tickets.statistics.getters.d.ts +4 -0
  15. package/dist/municipal/tickets/tickets.statistics.getters.d.ts.map +1 -1
  16. package/dist/municipal/tickets/tickets.statistics.getters.js +30 -3
  17. package/dist/municipal/tickets/tickets.statistics.getters.js.map +1 -1
  18. package/dist/municipal/tickets/tickets.statistics.pipeline.d.ts +53 -0
  19. package/dist/municipal/tickets/tickets.statistics.pipeline.d.ts.map +1 -0
  20. package/dist/municipal/tickets/tickets.statistics.pipeline.js +112 -0
  21. package/dist/municipal/tickets/tickets.statistics.pipeline.js.map +1 -0
  22. package/dist/municipal/tickets/tickets.statistics.utils.d.ts +7 -0
  23. package/dist/municipal/tickets/tickets.statistics.utils.d.ts.map +1 -0
  24. package/dist/municipal/tickets/tickets.statistics.utils.js +40 -0
  25. package/dist/municipal/tickets/tickets.statistics.utils.js.map +1 -0
  26. package/dist/talkpilot/calls/calls.statistics.getters.d.ts.map +1 -1
  27. package/dist/talkpilot/calls/calls.statistics.getters.js +18 -18
  28. package/dist/talkpilot/calls/calls.statistics.getters.js.map +1 -1
  29. package/dist/talkpilot/calls/calls.statistics.ticketScope.d.ts +12 -0
  30. package/dist/talkpilot/calls/calls.statistics.ticketScope.d.ts.map +1 -0
  31. package/dist/talkpilot/calls/calls.statistics.ticketScope.js +37 -0
  32. package/dist/talkpilot/calls/calls.statistics.ticketScope.js.map +1 -0
  33. package/dist/talkpilot/calls/calls.statistics.tickets.d.ts +17 -0
  34. package/dist/talkpilot/calls/calls.statistics.tickets.d.ts.map +1 -0
  35. package/dist/talkpilot/calls/calls.statistics.tickets.js +33 -0
  36. package/dist/talkpilot/calls/calls.statistics.tickets.js.map +1 -0
  37. package/dist/talkpilot/calls/calls.statistics.types.d.ts +4 -1
  38. package/dist/talkpilot/calls/calls.statistics.types.d.ts.map +1 -1
  39. package/dist/utils/statistics.aggregation.d.ts +20 -0
  40. package/dist/utils/statistics.aggregation.d.ts.map +1 -0
  41. package/dist/utils/statistics.aggregation.js +43 -0
  42. package/dist/utils/statistics.aggregation.js.map +1 -0
  43. package/jest.config.js +20 -20
  44. package/package.json +46 -46
  45. package/src/__tests__/setup.ts +20 -20
  46. package/src/connection.ts +54 -54
  47. package/src/index.ts +26 -26
  48. package/src/municipal/__tests__/validation.spec.ts +62 -62
  49. package/src/municipal/cities/cities.getters.ts +50 -50
  50. package/src/municipal/cities/cities.types.ts +11 -11
  51. package/src/municipal/cities/index.ts +2 -2
  52. package/src/municipal/departmentsSubjects/departmentsSubjects.getters.ts +282 -282
  53. package/src/municipal/departmentsSubjects/departmentsSubjects.types.ts +72 -72
  54. package/src/municipal/departmentsSubjects/index.ts +9 -9
  55. package/src/municipal/index.ts +22 -22
  56. package/src/municipal/mongodb-client.ts +61 -61
  57. package/src/municipal/muniIssues/__tests__/muniIssues.setters.spec.ts +92 -92
  58. package/src/municipal/muniIssues/__tests__/muniIssues.setup.spec.ts +92 -92
  59. package/src/municipal/muniIssues/index.ts +17 -17
  60. package/src/municipal/muniIssues/muniIssues.constants.ts +18 -18
  61. package/src/municipal/muniIssues/muniIssues.getters.ts +24 -24
  62. package/src/municipal/muniIssues/muniIssues.schema.ts +66 -66
  63. package/src/municipal/muniIssues/muniIssues.setters.ts +24 -24
  64. package/src/municipal/muniIssues/muniIssues.setup.ts +65 -65
  65. package/src/municipal/muniIssues/muniIssues.types.ts +37 -37
  66. package/src/municipal/streets/index.ts +2 -2
  67. package/src/municipal/streets/streets.getters.ts +125 -125
  68. package/src/municipal/streets/streets.types.ts +18 -18
  69. package/src/municipal/systemInstructions/__tests__/getters.spec.ts +113 -113
  70. package/src/municipal/systemInstructions/__tests__/setters.spec.ts +274 -274
  71. package/src/municipal/systemInstructions/index.ts +7 -7
  72. package/src/municipal/systemInstructions/instructions.getters.ts +57 -57
  73. package/src/municipal/systemInstructions/instructions.setters.ts +119 -119
  74. package/src/municipal/systemInstructions/instructions.types.ts +30 -30
  75. package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +30 -30
  76. package/src/municipal/tickets/__tests__/tickets.statistics.spec.ts +68 -51
  77. package/src/municipal/tickets/index.ts +3 -3
  78. package/src/municipal/tickets/tickets.constants.ts +8 -8
  79. package/src/municipal/tickets/tickets.getters.ts +121 -121
  80. package/src/municipal/tickets/tickets.statistics.aggregation.ts +96 -96
  81. package/src/municipal/tickets/tickets.statistics.getters.ts +109 -71
  82. package/src/municipal/tickets/tickets.types.ts +53 -53
  83. package/src/municipal/utils/types.ts +11 -11
  84. package/src/talkpilot/__tests__/db.spec.ts +38 -38
  85. package/src/talkpilot/__tests__/mongodb-client.spec.ts +18 -18
  86. package/src/talkpilot/__tests__/validation.spec.ts +68 -68
  87. package/src/talkpilot/agents/__tests__/agents.getters.spec.ts +29 -29
  88. package/src/talkpilot/agents/agents.getters.ts +34 -34
  89. package/src/talkpilot/agents/agents.types.ts +14 -14
  90. package/src/talkpilot/agents/index.ts +2 -2
  91. package/src/talkpilot/backgroundToolResults/__tests__/backgroundToolResults.getters.spec.ts +147 -147
  92. package/src/talkpilot/backgroundToolResults/backgroundToolResults.getters.ts +65 -65
  93. package/src/talkpilot/backgroundToolResults/backgroundToolResults.types.ts +23 -23
  94. package/src/talkpilot/backgroundToolResults/index.ts +2 -2
  95. package/src/talkpilot/calls/__tests__/callStats.utils.spec.ts +128 -128
  96. package/src/talkpilot/calls/__tests__/calls.dashboard.spec.ts +149 -149
  97. package/src/talkpilot/calls/__tests__/calls.spec.ts +270 -270
  98. package/src/talkpilot/calls/__tests__/calls.statistics.spec.ts +375 -344
  99. package/src/talkpilot/calls/calls.constants.ts +20 -20
  100. package/src/talkpilot/calls/calls.getters.ts +248 -248
  101. package/src/talkpilot/calls/calls.statistics.getters.ts +590 -587
  102. package/src/talkpilot/calls/calls.statistics.types.ts +47 -44
  103. package/src/talkpilot/calls/calls.types.ts +119 -119
  104. package/src/talkpilot/calls/dashboard/calls.dashboard.ts +292 -292
  105. package/src/talkpilot/calls/dashboard/calls.dashboard.types.ts +57 -57
  106. package/src/talkpilot/calls/index.ts +6 -6
  107. package/src/talkpilot/clientAudioBuffers/__tests__/clientAudioBuffer.getters.spec.ts +160 -160
  108. package/src/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.ts +117 -117
  109. package/src/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.ts +25 -25
  110. package/src/talkpilot/clientAudioBuffers/index.ts +2 -2
  111. package/src/talkpilot/clients/clients.getters.ts +16 -16
  112. package/src/talkpilot/clients/clients.types.ts +14 -14
  113. package/src/talkpilot/clients/index.ts +2 -2
  114. package/src/talkpilot/clientsConfig/__tests__/clientsConfig.getters.spec.ts +53 -53
  115. package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +190 -190
  116. package/src/talkpilot/clientsConfig/clientsConfig.getters.ts +55 -55
  117. package/src/talkpilot/clientsConfig/clientsConfig.types.ts +127 -127
  118. package/src/talkpilot/clientsConfig/index.ts +2 -2
  119. package/src/talkpilot/contextNotes/__tests__/contextNotes.getters.spec.ts +176 -176
  120. package/src/talkpilot/contextNotes/contextNotes.getters.ts +86 -86
  121. package/src/talkpilot/contextNotes/contextNotes.types.ts +20 -20
  122. package/src/talkpilot/contextNotes/index.ts +2 -2
  123. package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +96 -96
  124. package/src/talkpilot/flows/flows.getter.ts +14 -14
  125. package/src/talkpilot/flows/flows.schema.ts +154 -154
  126. package/src/talkpilot/flows/flows.types.ts +187 -187
  127. package/src/talkpilot/flows/index.ts +2 -2
  128. package/src/talkpilot/groups/__tests__/groups.spec.ts +90 -90
  129. package/src/talkpilot/groups/__tests__/phone.utils.spec.ts +32 -32
  130. package/src/talkpilot/groups/groups.getters.ts +30 -30
  131. package/src/talkpilot/groups/groups.types.ts +29 -29
  132. package/src/talkpilot/groups/index.ts +3 -3
  133. package/src/talkpilot/groups/phone.utils.ts +46 -46
  134. package/src/talkpilot/index.ts +31 -31
  135. package/src/talkpilot/leads/index.ts +2 -2
  136. package/src/talkpilot/leads/leads.getter.ts +6 -6
  137. package/src/talkpilot/leads/leads.schema.ts +33 -33
  138. package/src/talkpilot/leads/leads.types.ts +20 -20
  139. package/src/talkpilot/mongodb-client.ts +78 -78
  140. package/src/talkpilot/phone_numbers/__tests__/phone_numbers.spec.ts +252 -252
  141. package/src/talkpilot/phone_numbers/index.ts +2 -2
  142. package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +158 -158
  143. package/src/talkpilot/phone_numbers/phone_numbers.schema.ts +17 -17
  144. package/src/talkpilot/phone_numbers/phone_numbers.types.ts +30 -30
  145. package/src/talkpilot/plans/__tests__/plans.spec.ts +70 -70
  146. package/src/talkpilot/plans/index.ts +2 -2
  147. package/src/talkpilot/plans/plans.getters.ts +132 -132
  148. package/src/talkpilot/plans/plans.types.ts +89 -89
  149. package/src/talkpilot/products/__tests__/products.getters.spec.ts +45 -45
  150. package/src/talkpilot/products/index.ts +2 -2
  151. package/src/talkpilot/products/products.getters.ts +12 -12
  152. package/src/talkpilot/products/products.types.ts +9 -9
  153. package/src/talkpilot/results/index.ts +7 -7
  154. package/src/talkpilot/results/results.getter.ts +39 -39
  155. package/src/talkpilot/results/results.schema.ts +25 -25
  156. package/src/talkpilot/results/results.types.ts +34 -34
  157. package/src/talkpilot/retry_analyze/__tests__/retryAnalyze.getters.spec.ts +156 -156
  158. package/src/talkpilot/retry_analyze/index.ts +2 -2
  159. package/src/talkpilot/retry_analyze/retryAnalyze.getters.ts +84 -84
  160. package/src/talkpilot/retry_analyze/retryAnalyze.types.ts +13 -13
  161. package/src/talkpilot/sessions/__tests__/sessions.spec.ts +147 -147
  162. package/src/talkpilot/sessions/index.ts +2 -2
  163. package/src/talkpilot/sessions/sessions.getter.ts +92 -92
  164. package/src/talkpilot/sessions/sessions.schema.ts +34 -34
  165. package/src/talkpilot/sessions/sessions.types.ts +30 -30
  166. package/src/talkpilot/subscriptions/__tests__/subscriptions.getters.utils.spec.ts +45 -45
  167. package/src/talkpilot/subscriptions/index.ts +3 -3
  168. package/src/talkpilot/subscriptions/subscriptions.getters.ts +146 -146
  169. package/src/talkpilot/subscriptions/subscriptions.getters.utils.ts +33 -33
  170. package/src/talkpilot/subscriptions/subscriptions.types.ts +66 -66
  171. package/src/talkpilot/utils/__tests__/query.utils.spec.ts +49 -49
  172. package/src/talkpilot/utils/query.utils.ts +21 -21
  173. package/src/test-utils/db-utils.ts +26 -26
  174. package/src/test-utils/factories/index.ts +15 -15
  175. package/src/test-utils/factories/municipal/cities.ts +16 -16
  176. package/src/test-utils/factories/municipal/departmentsSubjects.ts +37 -37
  177. package/src/test-utils/factories/municipal/muniIssues.ts +32 -32
  178. package/src/test-utils/factories/municipal/streets.ts +22 -22
  179. package/src/test-utils/factories/municipal/tickets.ts +39 -39
  180. package/src/test-utils/factories/talkpilot/agents.ts +19 -19
  181. package/src/test-utils/factories/talkpilot/calls.ts +37 -37
  182. package/src/test-utils/factories/talkpilot/clientAudioBuffers.ts +20 -20
  183. package/src/test-utils/factories/talkpilot/clientsConfig.ts +18 -18
  184. package/src/test-utils/factories/talkpilot/contextNotes.ts +33 -33
  185. package/src/test-utils/factories/talkpilot/flows.ts +33 -33
  186. package/src/test-utils/factories/talkpilot/groups.ts +33 -33
  187. package/src/test-utils/factories/talkpilot/phone_numbers.ts +22 -22
  188. package/src/test-utils/factories/talkpilot/sessions.ts +35 -35
  189. package/src/test-utils/factories/websitalk/scans.ts +23 -23
  190. package/src/utils/date.utils.ts +116 -116
  191. package/src/utils/shared.types.ts +4 -4
  192. package/src/utils/validation.ts +23 -23
  193. package/src/websitalk/index.ts +15 -15
  194. package/src/websitalk/mongodb-client.ts +61 -61
  195. package/src/websitalk/scans/__tests__/scans.spec.ts +218 -218
  196. package/src/websitalk/scans/index.ts +2 -2
  197. package/src/websitalk/scans/scans.getters.ts +113 -113
  198. package/src/websitalk/scans/scans.types.ts +53 -53
  199. package/tsconfig.json +23 -23
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
+
@@ -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/municip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F;gBACD,OAAO,EAAE;oBACP,KAAK,EAAE;wBACL,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE;wBACpC,IAAI,EAAE;4BACJ,OAAO,EAAE;gCACP,EAAE,YAAY,EAAE,CAAC,mBAAmB,EAAE,CAAC,CAAC,EAAE;gCAC1C,cAAc;6BACf;yBACF;wBACD,IAAI,EAAE,cAAc;qBACrB;iBACF;aACF;SACF;QACD;YACE,MAAM,EAAE;gBACN,GAAG,EAAE,aAAa;gBAClB,OAAO,EAAE,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"}
@@ -0,0 +1,7 @@
1
+ import type { TicketStatsDateScope } from "./tickets.types";
2
+ export declare const resolveTicketStatsDateRange: (dateScope?: TicketStatsDateScope) => {
3
+ from: Date;
4
+ to: Date;
5
+ };
6
+ export declare const ticketStatsDateScopeFromYmd: (startStr: string, endStr: string, timezone: string) => TicketStatsDateScope;
7
+ //# sourceMappingURL=tickets.statistics.dates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tickets.statistics.dates.d.ts","sourceRoot":"","sources":["../../../src/municipal/tickets/tickets.statistics.dates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAiC5D,eAAO,MAAM,2BAA2B,GACtC,YAAY,oBAAoB,KAC/B;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,EAAE,EAAE,IAAI,CAAA;CAKxB,CAAC;AAEF,eAAO,MAAM,2BAA2B,GACtC,UAAU,MAAM,EAChB,QAAQ,MAAM,EACd,UAAU,MAAM,KACf,oBAGD,CAAC"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ticketStatsDateScopeFromYmd = exports.resolveTicketStatsDateRange = void 0;
4
+ const DEFAULT_LOOKBACK_DAYS = 30;
5
+ const DAY_MS = 24 * 60 * 60 * 1000;
6
+ const formatYmdInTz = (date, timezone) => new Intl.DateTimeFormat("en-CA", { timeZone: timezone }).format(date);
7
+ const dateAtNoonUtc = (dateStr) => {
8
+ const [y, m, d] = dateStr.split("-").map(Number);
9
+ return new Date(Date.UTC(y, m - 1, d, 12, 0, 0));
10
+ };
11
+ const startOfCalendarDayInTz = (dateStr, timezone) => {
12
+ const anchor = dateAtNoonUtc(dateStr).getTime();
13
+ let low = anchor - 2 * DAY_MS;
14
+ let high = anchor + DAY_MS;
15
+ while (high - low > 1) {
16
+ const mid = Math.floor((low + high) / 2);
17
+ if (formatYmdInTz(new Date(mid), timezone) >= dateStr)
18
+ high = mid;
19
+ else
20
+ low = mid;
21
+ }
22
+ return new Date(high);
23
+ };
24
+ const endOfCalendarDayInTz = (dateStr, timezone) => {
25
+ const [y, m, d] = dateStr.split("-").map(Number);
26
+ const nextDay = new Date(Date.UTC(y, m - 1, d + 1)).toISOString().slice(0, 10);
27
+ return new Date(startOfCalendarDayInTz(nextDay, timezone).getTime() - 1);
28
+ };
29
+ const resolveTicketStatsDateRange = (dateScope) => {
30
+ const to = dateScope?.to ?? new Date();
31
+ const from = dateScope?.from ?? new Date(to.getTime() - DEFAULT_LOOKBACK_DAYS * DAY_MS);
32
+ return { from, to };
33
+ };
34
+ exports.resolveTicketStatsDateRange = resolveTicketStatsDateRange;
35
+ const ticketStatsDateScopeFromYmd = (startStr, endStr, timezone) => ({
36
+ from: startOfCalendarDayInTz(startStr, timezone),
37
+ to: endOfCalendarDayInTz(endStr, timezone),
38
+ });
39
+ exports.ticketStatsDateScopeFromYmd = ticketStatsDateScopeFromYmd;
40
+ //# sourceMappingURL=tickets.statistics.dates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tickets.statistics.dates.js","sourceRoot":"","sources":["../../../src/municipal/tickets/tickets.statistics.dates.ts"],"names":[],"mappings":";;;AAEA,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACjC,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEnC,MAAM,aAAa,GAAG,CAAC,IAAU,EAAE,QAAgB,EAAU,EAAE,CAC7D,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAExE,MAAM,aAAa,GAAG,CAAC,OAAe,EAAQ,EAAE;IAC9C,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACjD,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CA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ACN,EAAE;IAC5B,MAAM,EAAE,GAAG,SAAS,EAAE,EAAE,IAAI,IAAI,IAAI,EAAE,CAAC;IACvC,MAAM,IAAI,GACR,SAAS,EAAE,IAAI,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,qBAAqB,GAAG,MAAM,CAAC,CAAC;IAC7E,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AACtB,CAAC,CAAC;AAPW,QAAA,2BAA2B,+BAOtC;AAEK,MAAM,2BAA2B,GAAG,CACzC,QAAgB,EAChB,MAAc,EACd,QAAgB,EACM,EAAE,CAAC,CAAC;IAC1B,IAAI,EAAE,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAChD,EAAE,EAAE,oBAAoB,CAAC,MAAM,EAAE,QAAQ,CAAC;CAC3C,CAAC,CAAC;AAPU,QAAA,2BAA2B,+BAOrC"}
@@ -2,7 +2,11 @@ import { CityName } from "../utils/types";
2
2
  import type { TicketStatsDateRange, TicketStatsDateScope, TicketSubjectRow } from "./tickets.types";
3
3
  export declare const resolveTicketStatsDateRange: (dateScope?: TicketStatsDateScope) => TicketStatsDateRange;
4
4
  export declare const ticketStatsDateScopeFromYmd: (startStr: string, endStr: string, timezone: string) => TicketStatsDateScope;
5
+ /** @deprecated Use findCallSidTicketCountsByCity instead. */
5
6
  export declare const findCallSidsWithTicketsByCity: (cityName: CityName, dateScope?: TicketStatsDateScope) => Promise<string[]>;
7
+ export declare const findCallSidTicketCountsByCity: (cityName: CityName, dateScope?: TicketStatsDateScope) => Promise<Map<string, number>>;
8
+ /** @deprecated Use findCallSidDraftTicketCountsByCity instead. */
6
9
  export declare const findCallSidsWithDraftTicketsByCity: (cityName: CityName, dateScope?: TicketStatsDateScope) => Promise<string[]>;
10
+ export declare const findCallSidDraftTicketCountsByCity: (cityName: CityName, dateScope?: TicketStatsDateScope) => Promise<Map<string, number>>;
7
11
  export declare const findTicketSubjectRows: (cityName: CityName, dateScope?: TicketStatsDateScope) => Promise<TicketSubjectRow[]>;
8
12
  //# sourceMappingURL=tickets.statistics.getters.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tickets.statistics.getters.d.ts","sourceRoot":"","sources":["../../../src/municipal/tickets/tickets.statistics.getters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAa1C,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,iBAAiB,CAAC;AAEzB,eAAO,MAAM,2BAA2B,GACtC,YAAY,oBAAoB,KAC/B,oBAKF,CAAC;AAEF,eAAO,MAAM,2BAA2B,GACtC,UAAU,MAAM,EAChB,QAAQ,MAAM,EACd,UAAU,MAAM,KACf,oBAGD,CAAC;AAEH,eAAO,MAAM,6BAA6B,GACxC,UAAU,QAAQ,EAClB,YAAY,oBAAoB,KAC/B,OAAO,CAAC,MAAM,EAAE,CAMlB,CAAC;AAEF,eAAO,MAAM,kCAAkC,GAC7C,UAAU,QAAQ,EAClB,YAAY,oBAAoB,KAC/B,OAAO,CAAC,MAAM,EAAE,CAOlB,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,UAAU,QAAQ,EAClB,YAAY,oBAAoB,KAC/B,OAAO,CAAC,gBAAgB,EAAE,CAO5B,CAAC"}
1
+ {"version":3,"file":"tickets.statistics.getters.d.ts","sourceRoot":"","sources":["../../../src/municipal/tickets/tickets.statistics.getters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAa1C,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,iBAAiB,CAAC;AAEzB,eAAO,MAAM,2BAA2B,GACtC,YAAY,oBAAoB,KAC/B,oBAKF,CAAC;AAEF,eAAO,MAAM,2BAA2B,GACtC,UAAU,MAAM,EAChB,QAAQ,MAAM,EACd,UAAU,MAAM,KACf,oBAGD,CAAC;AAEH,6DAA6D;AAC7D,eAAO,MAAM,6BAA6B,GACxC,UAAU,QAAQ,EAClB,YAAY,oBAAoB,KAC/B,OAAO,CAAC,MAAM,EAAE,CAQlB,CAAC;AAEF,eAAO,MAAM,6BAA6B,GACxC,UAAU,QAAQ,EAClB,YAAY,oBAAoB,KAC/B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAU7B,CAAC;AAGF,kEAAkE;AAClE,eAAO,MAAM,kCAAkC,GAC7C,UAAU,QAAQ,EAClB,YAAY,oBAAoB,KAC/B,OAAO,CAAC,MAAM,EAAE,CASlB,CAAC;AAEF,eAAO,MAAM,kCAAkC,GAC7C,UAAU,QAAQ,EAClB,YAAY,oBAAoB,KAC/B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAW7B,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,UAAU,QAAQ,EAClB,YAAY,oBAAoB,KAC/B,OAAO,CAAC,gBAAgB,EAAE,CAO5B,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findTicketSubjectRows = exports.findCallSidsWithDraftTicketsByCity = exports.findCallSidsWithTicketsByCity = exports.ticketStatsDateScopeFromYmd = exports.resolveTicketStatsDateRange = void 0;
3
+ exports.findTicketSubjectRows = exports.findCallSidDraftTicketCountsByCity = exports.findCallSidsWithDraftTicketsByCity = exports.findCallSidTicketCountsByCity = exports.findCallSidsWithTicketsByCity = exports.ticketStatsDateScopeFromYmd = exports.resolveTicketStatsDateRange = void 0;
4
4
  const date_utils_1 = require("../../utils/date.utils");
5
5
  const tickets_constants_1 = require("./tickets.constants");
6
6
  const tickets_statistics_aggregation_1 = require("./tickets.statistics.aggregation");
@@ -15,23 +15,50 @@ const ticketStatsDateScopeFromYmd = (startStr, endStr, timezone) => ({
15
15
  to: (0, date_utils_1.endOfCalendarDayInTz)(endStr, timezone),
16
16
  });
17
17
  exports.ticketStatsDateScopeFromYmd = ticketStatsDateScopeFromYmd;
18
+ /** @deprecated Use findCallSidTicketCountsByCity instead. */
18
19
  const findCallSidsWithTicketsByCity = async (cityName, dateScope) => {
19
20
  const rows = await (0, tickets_statistics_aggregation_1.runTicketStatsAggregate)([
20
21
  { $match: (0, tickets_statistics_aggregation_1.ticketsWithCallSidMatch)(cityName, (0, exports.resolveTicketStatsDateRange)(dateScope)) },
21
22
  { $group: { _id: "$callSid" } },
22
23
  ]);
23
- return rows.map((r) => String(r._id)).filter(Boolean);
24
+ return rows
25
+ .filter((r) => r._id != null && r._id !== "")
26
+ .map((r) => String(r._id));
24
27
  };
25
28
  exports.findCallSidsWithTicketsByCity = findCallSidsWithTicketsByCity;
29
+ const findCallSidTicketCountsByCity = async (cityName, dateScope) => {
30
+ const rows = await (0, tickets_statistics_aggregation_1.runTicketStatsAggregate)([
31
+ { $match: (0, tickets_statistics_aggregation_1.ticketsWithCallSidMatch)(cityName, (0, exports.resolveTicketStatsDateRange)(dateScope)) },
32
+ { $group: { _id: "$callSid", ticketCount: { $sum: 1 } } },
33
+ ]);
34
+ return new Map(rows
35
+ .filter((r) => r._id != null && r._id !== "")
36
+ .map((r) => [String(r._id), r.ticketCount]));
37
+ };
38
+ exports.findCallSidTicketCountsByCity = findCallSidTicketCountsByCity;
39
+ /** @deprecated Use findCallSidDraftTicketCountsByCity instead. */
26
40
  const findCallSidsWithDraftTicketsByCity = async (cityName, dateScope) => {
27
41
  const rows = await (0, tickets_statistics_aggregation_1.runTicketStatsAggregate)([
28
42
  { $match: (0, tickets_statistics_aggregation_1.ticketsWithCallSidMatch)(cityName, (0, exports.resolveTicketStatsDateRange)(dateScope)) },
29
43
  { $match: { $expr: tickets_statistics_aggregation_1.isDraftSubjectIdExpr } },
30
44
  { $group: { _id: "$callSid" } },
31
45
  ]);
32
- return rows.map((r) => String(r._id)).filter(Boolean);
46
+ return rows
47
+ .filter((r) => r._id != null && r._id !== "")
48
+ .map((r) => String(r._id));
33
49
  };
34
50
  exports.findCallSidsWithDraftTicketsByCity = findCallSidsWithDraftTicketsByCity;
51
+ const findCallSidDraftTicketCountsByCity = async (cityName, dateScope) => {
52
+ const rows = await (0, tickets_statistics_aggregation_1.runTicketStatsAggregate)([
53
+ { $match: (0, tickets_statistics_aggregation_1.ticketsWithCallSidMatch)(cityName, (0, exports.resolveTicketStatsDateRange)(dateScope)) },
54
+ { $match: { $expr: tickets_statistics_aggregation_1.isDraftSubjectIdExpr } },
55
+ { $group: { _id: "$callSid", ticketCount: { $sum: 1 } } },
56
+ ]);
57
+ return new Map(rows
58
+ .filter((r) => r._id != null && r._id !== "")
59
+ .map((r) => [String(r._id), r.ticketCount]));
60
+ };
61
+ exports.findCallSidDraftTicketCountsByCity = findCallSidDraftTicketCountsByCity;
35
62
  const findTicketSubjectRows = async (cityName, dateScope) => {
36
63
  const rows = await (0, tickets_statistics_aggregation_1.runTicketStatsAggregate)([
37
64
  { $match: (0, tickets_statistics_aggregation_1.ticketsWithCallSidMatch)(cityName, (0, exports.resolveTicketStatsDateRange)(dateScope)) },
@@ -1 +1 @@
1
- {"version":3,"file":"tickets.statistics.getters.js","sourceRoot":"","sources":["../../../src/municipal/tickets/tickets.statistics.getters.ts"],"names":[],"mappings":";;;AACA,uDAIgC;AAChC,2DAA4D;AAC5D,qFAK0C;AAOnC,MAAM,2BAA2B,GAAG,CACzC,SAAgC,EACV,EAAE;IACxB,MAAM,EAAE,GAAG,SAAS,EAAE,EAAE,IAAI,IAAI,IAAI,EAAE,CAAC;IACvC,MAAM,IAAI,GACR,SAAS,EAAE,IAAI,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,yCAAqB,GAAG,mBAAM,CAAC,CAAC;IAC7E,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AACtB,CAAC,CAAC;AAPW,QAAA,2BAA2B,+BAOtC;AAEK,MAAM,2BAA2B,GAAG,CACzC,QAAgB,EAChB,MAAc,EACd,Q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QAAA,kCAAkC,sCAU7C;AAEK,MAAM,qBAAqB,GAAG,KAAK,EACxC,QAAkB,EAClB,SAAgC,EACH,EAAE;IAC/B,MAAM,IAAI,GAAG,MAAM,IAAA,wDAAuB,EAAyC;QACjF,EAAE,MAAM,EAAE,IAAA,wDAAuB,EAAC,QAAQ,EAAE,IAAA,mCAA2B,EAAC,SAAS,CAAC,CAAC,EAAE;QACrF,GAAG,IAAA,wDAAuB,EAAC,QAAQ,CAAC;QACpC,EAAE,QAAQ,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE;KACjD,CAAC,CAAC;IACH,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;AACvF,CAAC,CAAC;AAVW,QAAA,qBAAqB,yBAUhC"}
1
+ {"version":3,"file":"tickets.statistics.getters.js","sourceRoot":"","sources":["../../../src/municipal/tickets/tickets.statistics.getters.ts"],"names":[],"mappings":";;;AACA,uDAIgC;AAChC,2DAA4D;AAC5D,qFAK0C;AAOnC,MAAM,2BAA2B,GAAG,CACzC,SAAgC,EACV,EAAE;IACxB,MAAM,EAAE,GAAG,SAAS,EAAE,EAAE,IAAI,IAAI,IAAI,EAAE,CAAC;IACvC,MAAM,IAAI,GACR,SAAS,EAAE,IAAI,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,yCAAqB,GAAG,mBAAM,CAAC,CAAC;IAC7E,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AACtB,CAAC,CAAC;AAPW,QAAA,2BAA2B,+BAOtC;AAEK,MAAM,2BAA2B,GAAG,CACzC,QAAgB,EAChB,MAAc,EACd,QAAgB,EACM,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