@talkpilot/core-db 1.2.1 → 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.
- package/README.md +117 -108
- package/README_OLD.md +160 -0
- package/dist/municipal/tickets/index.d.ts +2 -1
- package/dist/municipal/tickets/index.d.ts.map +1 -1
- package/dist/municipal/tickets/index.js +1 -0
- package/dist/municipal/tickets/index.js.map +1 -1
- package/dist/municipal/tickets/tickets.constants.d.ts +7 -0
- package/dist/municipal/tickets/tickets.constants.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.constants.js +10 -0
- package/dist/municipal/tickets/tickets.constants.js.map +1 -0
- package/dist/municipal/tickets/tickets.deprecated.getters.d.ts +12 -0
- package/dist/municipal/tickets/tickets.deprecated.getters.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.deprecated.getters.js +131 -0
- package/dist/municipal/tickets/tickets.deprecated.getters.js.map +1 -0
- package/dist/municipal/tickets/tickets.getters.d.ts +0 -11
- package/dist/municipal/tickets/tickets.getters.d.ts.map +1 -1
- package/dist/municipal/tickets/tickets.getters.js +0 -128
- package/dist/municipal/tickets/tickets.getters.js.map +1 -1
- package/dist/municipal/tickets/tickets.statistics.aggregation.d.ts +45 -0
- package/dist/municipal/tickets/tickets.statistics.aggregation.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.aggregation.js +98 -0
- package/dist/municipal/tickets/tickets.statistics.aggregation.js.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.dates.d.ts +7 -0
- package/dist/municipal/tickets/tickets.statistics.dates.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.dates.js +40 -0
- package/dist/municipal/tickets/tickets.statistics.dates.js.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.getters.d.ts +9 -0
- package/dist/municipal/tickets/tickets.statistics.getters.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.getters.js +55 -0
- package/dist/municipal/tickets/tickets.statistics.getters.js.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.pipeline.d.ts +53 -0
- package/dist/municipal/tickets/tickets.statistics.pipeline.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.pipeline.js +112 -0
- package/dist/municipal/tickets/tickets.statistics.pipeline.js.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.utils.d.ts +7 -0
- package/dist/municipal/tickets/tickets.statistics.utils.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.utils.js +40 -0
- package/dist/municipal/tickets/tickets.statistics.utils.js.map +1 -0
- package/dist/municipal/tickets/tickets.types.d.ts +10 -5
- package/dist/municipal/tickets/tickets.types.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.constants.d.ts +17 -0
- package/dist/talkpilot/calls/calls.constants.d.ts.map +1 -0
- package/dist/talkpilot/calls/calls.constants.js +20 -0
- package/dist/talkpilot/calls/calls.constants.js.map +1 -0
- package/dist/talkpilot/calls/calls.getters.d.ts +3 -2
- package/dist/talkpilot/calls/calls.getters.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.getters.js +1 -2
- package/dist/talkpilot/calls/calls.getters.js.map +1 -1
- package/dist/talkpilot/calls/calls.statistics.getters.d.ts +19 -0
- package/dist/talkpilot/calls/calls.statistics.getters.d.ts.map +1 -0
- package/dist/talkpilot/calls/calls.statistics.getters.js +375 -0
- package/dist/talkpilot/calls/calls.statistics.getters.js.map +1 -0
- package/dist/talkpilot/calls/calls.statistics.ticketScope.d.ts +12 -0
- package/dist/talkpilot/calls/calls.statistics.ticketScope.d.ts.map +1 -0
- package/dist/talkpilot/calls/calls.statistics.ticketScope.js +37 -0
- package/dist/talkpilot/calls/calls.statistics.ticketScope.js.map +1 -0
- package/dist/talkpilot/calls/calls.statistics.tickets.d.ts +17 -0
- package/dist/talkpilot/calls/calls.statistics.tickets.d.ts.map +1 -0
- package/dist/talkpilot/calls/calls.statistics.tickets.js +33 -0
- package/dist/talkpilot/calls/calls.statistics.tickets.js.map +1 -0
- package/dist/talkpilot/calls/calls.statistics.types.d.ts +39 -0
- package/dist/talkpilot/calls/calls.statistics.types.d.ts.map +1 -0
- package/dist/talkpilot/calls/calls.statistics.types.js +3 -0
- package/dist/talkpilot/calls/calls.statistics.types.js.map +1 -0
- package/dist/talkpilot/calls/calls.types.d.ts +6 -10
- package/dist/talkpilot/calls/calls.types.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.types.js +0 -3
- package/dist/talkpilot/calls/calls.types.js.map +1 -1
- package/dist/talkpilot/calls/dashboard/calls.dashboard.d.ts +36 -0
- package/dist/talkpilot/calls/dashboard/calls.dashboard.d.ts.map +1 -0
- package/dist/talkpilot/calls/dashboard/calls.dashboard.js +208 -0
- package/dist/talkpilot/calls/dashboard/calls.dashboard.js.map +1 -0
- package/dist/talkpilot/calls/dashboard/calls.dashboard.types.d.ts +66 -0
- package/dist/talkpilot/calls/dashboard/calls.dashboard.types.d.ts.map +1 -0
- package/dist/talkpilot/calls/dashboard/calls.dashboard.types.js +3 -0
- package/dist/talkpilot/calls/dashboard/calls.dashboard.types.js.map +1 -0
- package/dist/talkpilot/calls/index.d.ts +4 -0
- package/dist/talkpilot/calls/index.d.ts.map +1 -1
- package/dist/talkpilot/calls/index.js +4 -0
- package/dist/talkpilot/calls/index.js.map +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts +2 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts.map +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.js +14 -0
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.js.map +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts +4 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts.map +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.types.js +6 -0
- package/dist/talkpilot/clientsConfig/clientsConfig.types.js.map +1 -1
- package/dist/talkpilot/flows/flows.schema.js +1 -1
- package/dist/talkpilot/phone_numbers/index.d.ts +2 -2
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.js +5 -3
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.js.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.schema.js +12 -12
- package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts +4 -4
- package/dist/talkpilot/results/results.getter.d.ts.map +1 -1
- package/dist/talkpilot/results/results.getter.js.map +1 -1
- package/dist/talkpilot/retry_analyze/retryAnalyze.getters.d.ts.map +1 -1
- package/dist/talkpilot/retry_analyze/retryAnalyze.getters.js.map +1 -1
- package/dist/utils/date.utils.d.ts +49 -0
- package/dist/utils/date.utils.d.ts.map +1 -0
- package/dist/utils/date.utils.js +103 -0
- package/dist/utils/date.utils.js.map +1 -0
- package/dist/utils/shared.types.d.ts +5 -0
- package/dist/utils/shared.types.d.ts.map +1 -0
- package/dist/utils/shared.types.js +3 -0
- package/dist/utils/shared.types.js.map +1 -0
- package/dist/utils/statistics.aggregation.d.ts +20 -0
- package/dist/utils/statistics.aggregation.d.ts.map +1 -0
- package/dist/utils/statistics.aggregation.js +43 -0
- package/dist/utils/statistics.aggregation.js.map +1 -0
- package/package.json +2 -1
- package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +1 -37
- package/src/municipal/tickets/__tests__/tickets.statistics.spec.ts +104 -0
- package/src/municipal/tickets/index.ts +2 -1
- package/src/municipal/tickets/tickets.constants.ts +8 -0
- package/src/municipal/tickets/tickets.getters.ts +0 -140
- package/src/municipal/tickets/tickets.statistics.aggregation.ts +113 -0
- package/src/municipal/tickets/tickets.statistics.getters.ts +93 -0
- package/src/municipal/tickets/tickets.types.ts +14 -9
- package/src/talkpilot/calls/__tests__/calls.dashboard.spec.ts +46 -0
- package/src/talkpilot/calls/__tests__/calls.spec.ts +48 -30
- package/src/talkpilot/calls/__tests__/calls.statistics.spec.ts +281 -0
- package/src/talkpilot/calls/calls.constants.ts +20 -0
- package/src/talkpilot/calls/calls.getters.ts +6 -6
- package/src/talkpilot/calls/calls.statistics.getters.ts +525 -0
- package/src/talkpilot/calls/calls.statistics.types.ts +44 -0
- package/src/talkpilot/calls/calls.types.ts +16 -15
- package/src/talkpilot/calls/dashboard/calls.dashboard.ts +243 -0
- package/src/talkpilot/calls/dashboard/calls.dashboard.types.ts +70 -0
- package/src/talkpilot/calls/index.ts +4 -0
- package/src/talkpilot/clientsConfig/__tests__/clientsConfig.getters.spec.ts +53 -0
- package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +19 -9
- package/src/talkpilot/clientsConfig/clientsConfig.getters.ts +34 -1
- package/src/talkpilot/clientsConfig/clientsConfig.types.ts +9 -1
- package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +6 -2
- package/src/talkpilot/flows/flows.schema.ts +1 -1
- package/src/talkpilot/phone_numbers/__tests__/phone_numbers.spec.ts +40 -35
- package/src/talkpilot/phone_numbers/index.ts +2 -2
- package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +10 -6
- package/src/talkpilot/phone_numbers/phone_numbers.schema.ts +12 -12
- package/src/talkpilot/phone_numbers/phone_numbers.types.ts +4 -4
- package/src/talkpilot/results/results.getter.ts +6 -2
- package/src/talkpilot/retry_analyze/retryAnalyze.getters.ts +13 -4
- package/src/utils/date.utils.ts +116 -0
- package/src/utils/shared.types.ts +4 -0
package/README.md
CHANGED
|
@@ -1,160 +1,169 @@
|
|
|
1
|
-
|
|
1
|
+
L1:# @talkpilot/core-db
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@talkpilot/core-db` is the shared TypeScript database package that wires TalkPilot APIs, municipal CRM integrations, and internal tools to a single, type-safe MongoDB surface. Every repo (MIS, CIS, TalkPilot Server, etc.) imports this package to avoid re-implementing connections, collections, or validation helpers.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Purpose
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- Provide a reliable, multi-domain MongoDB layer for TalkPilot and municipal data.
|
|
8
|
+
- Export typed getters, vector search helpers, and document factories so services can focus on behavior instead of schema wiring.
|
|
9
|
+
- Manage connection lifecycles, environment configuration, and test helpers from one place so every repo reuses the same plumbing.
|
|
8
10
|
|
|
9
|
-
|
|
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.
|
|
11
|
+
## Main Concepts
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
- **Multi-domain clients** – `src/connection.ts` exposes `mongodbClient` (TalkPilot) and `municipalDataMongodbClient`, each of which resolves `MONGO_URI`, DB overrides, and default names.
|
|
14
|
+
- **Domain-specific getters** – `src/talkpilot/` and `src/municipal/` host typed getters (agents, calls, streets, tickets, etc.), vector-search helpers, and service-friendly adapters that keep caller code DRY.
|
|
15
|
+
- **Product-specific clients (future)** – While the package currently exposes the shared TalkPilot + municipal clients, we expect each product (CIS, MIS, TalkPilot Server) to eventually get its own domain-specific client helpers or wrappers so the shared core can remain stable while new consumers add targeted extensions.
|
|
16
|
+
- **Test helpers** – `src/test-utils/` plus `src/__tests__/` reuse `MongoMemoryServer` and shared factories so tests start with clean data regardless of the consuming repo.
|
|
17
|
+
- **Utility layers** – `src/utils/` contains shared validation, pagination, and environment helpers that complement the getters.
|
|
18
|
+
- **Environment awareness** – Defaults, fallbacks, and `process.env` lookups ensure local, CI, and Cloud Run clients all connect using the right URI/DB names.
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
## Key Components
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
npm install github:talkpilot/core-db
|
|
25
|
-
```
|
|
22
|
+
- `src/connection.ts` – Central connection logic that resolves URIs/DB names from env vars (`MONGO_URI`, `MONGODB_URI`, `TALKPILOT_DB_NAME`, `MUNICIPAL_DB_NAME`) and reuses a single `MongoClient`.
|
|
23
|
+
- `src/talkpilot/` – Call history, agents, flows, sessions, leads, subscriptions, and support helpers exposed as getters plus helper enums/types for each collection.
|
|
24
|
+
- `src/municipal/` – Municipal-specific collections (`cities`, `streets`, `departmentsSubjects`, `tickets`, etc.) plus vector search helpers and Ash Bina helpers used by MIS.
|
|
25
|
+
- `src/utils/` – Shared helpers such as `resolveConnection`, pagination utilities, and schema validation helper functions.
|
|
26
|
+
- `src/test-utils/` and `src/__tests__/` – Utilities that bootstrap `MongoMemoryServer`, expose factories, and make sure Jest environments can stub database calls predictably.
|
|
27
|
+
- `dist/` – Compiled output consumed by downstream repos (CJS + ESM + type defs).
|
|
26
28
|
|
|
27
|
-
##
|
|
29
|
+
## Domain APIs
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
- **TalkPilot domain** – Imports like `findAgents`, `getFlows`, `findCalls`, and `vectorSearchCalls` live in `src/talkpilot`. These functions are the canonical access pattern for call history, session metadata, and provider configs.
|
|
32
|
+
- **Municipal domain** – Helpers such as `findStreets`, `getMunicipalCities`, `findDepartmentSubjects`, and `createTicket` live under `src/municipal` and feed MIS workflows (street hints, subject matching, Ash Bina tickets).
|
|
30
33
|
|
|
31
|
-
|
|
34
|
+
## Environment variables
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
| Variable | Purpose | Required |
|
|
37
|
+
|---------------------------|--------------------------------------------------------------------------------------|----------|
|
|
38
|
+
| `MONGO_URI` | Primary MongoDB connection string for every domain (overridden by `MONGODB_URI`). | ✅ |
|
|
39
|
+
| `MONGODB_URI` | Alternate connection string used when Mongo needs a second URI parameter. | ✅ |
|
|
40
|
+
| `TALKPILOT_DB_NAME` | Optional override for the TalkPilot database name (defaults from URI path). | ❌ |
|
|
41
|
+
| `MUNICIPAL_DB_NAME` | Optional override for the municipal database name (defaults to `municipal-data`). | ❌ |
|
|
42
|
+
| `ENV` | Free-form label used in logs/validators (defaults to `unknown`). | ❌ |
|
|
35
43
|
|
|
36
|
-
|
|
37
|
-
// Initialize TalkPilot DB
|
|
38
|
-
await mongodbClient.connect(process.env.TALKPILOT_MONGO_URI);
|
|
44
|
+
If you pass a `uri` directly to `mongodbClient.connect()` or `municipalDataMongodbClient.connect()`, the client will prefer that value over the env vars.
|
|
39
45
|
|
|
40
|
-
|
|
41
|
-
await municipalDataMongodbClient.connect(process.env.MUNICIPAL_MONGO_URI);
|
|
42
|
-
}
|
|
46
|
+
## Getting Started
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
```
|
|
48
|
+
### Prerequisites
|
|
46
49
|
|
|
47
|
-
|
|
50
|
+
- Node.js 22.x+ (aligns with downstream services).
|
|
51
|
+
- npm 11+ or Yarn.
|
|
52
|
+
- MongoDB accessible from your environment or a `MongoMemoryServer` for tests.
|
|
48
53
|
|
|
49
|
-
|
|
54
|
+
### Setup
|
|
50
55
|
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
1. Clone the repo and install dependencies:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
git clone https://github.com/talkpilot/core-db.git
|
|
60
|
+
cd core-db
|
|
61
|
+
npm install
|
|
62
|
+
```
|
|
53
63
|
|
|
54
|
-
|
|
55
|
-
// Get all agents from TalkPilot DB
|
|
56
|
-
const agents = await findAgents();
|
|
57
|
-
console.log('Total Agents:', agents.length);
|
|
64
|
+
2. Build the package before using it locally:
|
|
58
65
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
```
|
|
66
|
+
```bash
|
|
67
|
+
npm run build
|
|
68
|
+
```
|
|
64
69
|
|
|
65
|
-
|
|
70
|
+
3. Import `@talkpilot/core-db` from another project by pointing `package.json` at the local path during development or installing the published release.
|
|
66
71
|
|
|
67
|
-
|
|
72
|
+
## Sample `.env`
|
|
68
73
|
|
|
69
|
-
|
|
74
|
+
```
|
|
75
|
+
MONGO_URI=mongodb://localhost:27017
|
|
76
|
+
TALKPILOT_DB_NAME=talkpilot-dev
|
|
77
|
+
MUNICIPAL_DB_NAME=municipal-dev
|
|
78
|
+
ENV=development
|
|
79
|
+
```
|
|
70
80
|
|
|
71
|
-
|
|
81
|
+
Adjust `MONGO_URI` to match the running Mongo instance and configure `talkpilot`/`municipal` DB names if you want to keep them separate.
|
|
72
82
|
|
|
73
|
-
|
|
74
|
-
- Exported as root level functions or via `mongodbClient`.
|
|
83
|
+
## Local development
|
|
75
84
|
|
|
76
|
-
|
|
85
|
+
1. Run `npm install`.
|
|
86
|
+
2. Build the compiled output: `npm run build`.
|
|
87
|
+
3. Execute tests: `npm run test`.
|
|
88
|
+
4. Use `npm link` or `npm pack` to consume the freshly built package from other repos (`CIS`, `MIS`, `TalkPilot Server`).
|
|
77
89
|
|
|
78
|
-
|
|
90
|
+
## Development guide
|
|
79
91
|
|
|
80
|
-
|
|
81
|
-
- Functions are prefixed where necessary or accessible via `getMunicipalDataDb`.
|
|
92
|
+
`DEVELOPMENT.md` contains the tactical steps for contributors. At a glance:
|
|
82
93
|
|
|
83
|
-
|
|
94
|
+
- Node 18+/TypeScript is required (aligns with downstream services).
|
|
95
|
+
- Run `npm install` → `npm run build` after cloning.
|
|
96
|
+
- Use `npm link`/`npm link @talkpilot/core-db` to test the package locally before publishing.
|
|
97
|
+
- When adding getters, define types, implement the function, export it through the domain `index.ts`, and add a corresponding test under the domain’s `__tests__` folder.
|
|
98
|
+
- Always rely on the provided test factories (`src/test-utils/factories`) to seed data so tests remain consistent.
|
|
99
|
+
- Jest with `mongodb-memory-server` is the only execution path we have to verify this core utility—unit tests are the safety net for every change.
|
|
84
100
|
|
|
85
|
-
|
|
101
|
+
Refer to `DEVELOPMENT.md` for the full walkthrough, token instructions, and factory samples.
|
|
86
102
|
|
|
87
|
-
|
|
88
|
-
- `MONGODB_DB_NAME`: Database name (defaults to 'municipal-data' for the municipal client if not specified).
|
|
103
|
+
## 🧪 Testing
|
|
89
104
|
|
|
90
|
-
|
|
105
|
+
- `npm run test` – Jest suite (factories, utils, integration mocks) powered by `mongodb-memory-server`.
|
|
106
|
+
- Tests rely on `src/__tests__/setup.ts` to bootstrap the in-memory Mongo instances and wire shared factories/helpers before each run.
|
|
107
|
+
- When adding getters, helpers, or domain logic, create focused coverage inside the consuming domain’s `__tests__/` folder and use the provided factories to keep fixtures consistent.
|
|
91
108
|
|
|
92
|
-
|
|
109
|
+
`@talkpilot/core-db` does not run in a product UI or feature branch—unit tests are the *only* reliable execution path to ensure your changes work. Every change must ship with a unit test so downstream repos can upgrade without surprises; treat the test suite as the canonical safety net for this core utility package.
|
|
93
110
|
|
|
94
|
-
|
|
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
|
-
```
|
|
111
|
+
## 🧹 Lint & build verification
|
|
104
112
|
|
|
105
|
-
|
|
113
|
+
- `npm run lint` – Run ESLint over `src/**/*.{ts,tsx}`.
|
|
114
|
+
- `npm run format` – Format the source files with Prettier.
|
|
115
|
+
- `npm run build` – Compile TypeScript and emit `dist/` (used by downstream consumers).
|
|
106
116
|
|
|
107
|
-
|
|
117
|
+
## ✅ Pre-push checklist
|
|
108
118
|
|
|
109
|
-
|
|
119
|
+
1. `npm run build`.
|
|
120
|
+
2. `npm run test`.
|
|
121
|
+
3. `npm run format`.
|
|
110
122
|
|
|
111
|
-
|
|
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
|
-
```
|
|
123
|
+
## Publishing & release notes
|
|
130
124
|
|
|
131
|
-
|
|
125
|
+
- Releases are handled by `npm version <patch|minor|major>` followed by `npm publish`. The package is a **private `@talkpilot` dependency**, so every contributor must install the shared npm automation token into their global `~/.npmrc` before running publish or `npm install`.
|
|
126
|
+
- The shared token is rotated periodically—if you see authentication failures, request the refreshed token, update your `~/.npmrc`, and retry. Never commit credentials to source control.
|
|
127
|
+
- After publishing, downstream repos (`CIS`, `MIS`, `TalkPilot Server`, etc.) should run `npm update @talkpilot/core-db` so they receive the latest helpers/bug fixes.
|
|
128
|
+
- Cloud Build & Cloud Run jobs that depend on this package pick up the new version the next time they rebuild their container; the services pull the compiled `dist/` output and type definitions when installing the dependency.
|
|
132
129
|
|
|
133
|
-
MIT
|
|
134
130
|
|
|
135
|
-
---
|
|
136
131
|
|
|
137
|
-
|
|
132
|
+
| Version | Note |
|
|
133
|
+
| ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
134
|
+
| 1.1.9 | Maintenance release (build, test, format). |
|
|
135
|
+
| 1.2.0 | Added new statistics getters for call & ticket dashboards (CP-149): summary, trend, hourly, and routing for calls, plus open/draft/subject ticket stats. **Removed** the legacy getters `getTicketsCountByCityAndDateRange` and `getTicketsSubjectStats`. |
|
|
138
136
|
|
|
139
|
-
## Release Notes
|
|
140
137
|
|
|
141
138
|
### 1.1.9
|
|
142
139
|
|
|
143
|
-
|
|
144
|
-
|
|
140
|
+
1. `npm run build`.
|
|
141
|
+
2. `npm run test`.
|
|
142
|
+
3. `npm run format`.
|
|
143
|
+
|
|
144
|
+
### 1.2.0 — Call & ticket statistics (CP-149)
|
|
145
|
+
|
|
146
|
+
New call statistics getters for dashboards (summary, trend, hourly, routing) and ticket statistics scoped to the same date range (open tickets, draft tickets, subject breakdowns).
|
|
147
|
+
|
|
148
|
+
**Removed**
|
|
149
|
+
|
|
150
|
+
| Removed | Replacement |
|
|
151
|
+
| --- | --- |
|
|
152
|
+
| `getTicketsCountByCityAndDateRange` | `aggregateCallsSummary` + `findCallSidsWithTicketsByCity` |
|
|
153
|
+
| `getTicketsSubjectStats` | `findSubjectsByCallSids` |
|
|
154
|
+
| `SubjectStatsItem` | `SubjectItem` |
|
|
145
155
|
|
|
146
|
-
|
|
156
|
+
**Do I need to update my app?**
|
|
147
157
|
|
|
148
|
-
|
|
158
|
+
Yes — if you used any of the removed functions above.
|
|
149
159
|
|
|
150
|
-
|
|
151
|
-
- **Warning**: Version 1.0.15 is bugged and should not be used. Please use at least version 1.0.16.
|
|
160
|
+
## 🛠 CI/CD & deployment
|
|
152
161
|
|
|
153
|
-
|
|
162
|
+
- This package is consumed by Cloud Build-based services (TalkPilot Server, MIS, CIS) as a dependency when Docker images are built. Keep `dist/` in sync with your builds because the compiled artifact is what downstream services install.
|
|
163
|
+
- Releases require the shared npm token documented in `DEVELOPMENT.md`; consult that guide for contribution, linking, and token rotation procedures.
|
|
154
164
|
|
|
155
|
-
|
|
156
|
-
- withNeedAttentionCalls?: boolean
|
|
165
|
+
## Resources
|
|
157
166
|
|
|
158
|
-
|
|
159
|
-
-
|
|
167
|
+
- [DEVELOPMENT.md](./DEVELOPMENT.md) (setup, tooling, publishing, token management)
|
|
168
|
+
- [src/test-utils](src/test-utils) and the `__tests__` folder for examples of `MongoMemoryServer` wiring.
|
|
160
169
|
|
package/README_OLD.md
ADDED
|
@@ -0,0 +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,3 +1,4 @@
|
|
|
1
1
|
export * from "./tickets.getters";
|
|
2
|
-
export
|
|
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,
|
|
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,iCAAi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