@talkpilot/core-db 1.3.11 → 1.3.12

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 (45) hide show
  1. package/.cursor/rules/development.mdc +65 -65
  2. package/DEVELOPMENT.md +141 -141
  3. package/README.md +297 -287
  4. package/README_OLD.md +160 -160
  5. package/dist/municipal/tickets/index.d.ts +1 -1
  6. package/dist/municipal/tickets/index.d.ts.map +1 -1
  7. package/dist/municipal/tickets/tickets.statistics.getters.d.ts.map +1 -1
  8. package/dist/municipal/tickets/tickets.statistics.getters.js +13 -4
  9. package/dist/municipal/tickets/tickets.statistics.getters.js.map +1 -1
  10. package/dist/talkpilot/calls/calls.dashboard.d.ts +3 -0
  11. package/dist/talkpilot/calls/calls.dashboard.d.ts.map +1 -0
  12. package/dist/talkpilot/calls/calls.dashboard.js +191 -0
  13. package/dist/talkpilot/calls/calls.dashboard.js.map +1 -0
  14. package/dist/talkpilot/calls/calls.statistics.getters.d.ts.map +1 -1
  15. package/dist/talkpilot/calls/calls.statistics.getters.js +39 -10
  16. package/dist/talkpilot/calls/calls.statistics.getters.js.map +1 -1
  17. package/dist/talkpilot/calls/calls.statistics.types.d.ts +1 -0
  18. package/dist/talkpilot/calls/calls.statistics.types.d.ts.map +1 -1
  19. package/dist/talkpilot/contextNotes/contextNotes.getters.d.ts.map +1 -1
  20. package/dist/talkpilot/contextNotes/contextNotes.getters.js +1 -3
  21. package/dist/talkpilot/contextNotes/contextNotes.getters.js.map +1 -1
  22. package/dist/test-utils/factories/talkpilot/contextNotes.d.ts.map +1 -1
  23. package/dist/test-utils/factories/talkpilot/contextNotes.js +4 -1
  24. package/dist/test-utils/factories/talkpilot/contextNotes.js.map +1 -1
  25. package/dist/utils/date.utils.d.ts.map +1 -1
  26. package/dist/utils/date.utils.js +7 -2
  27. package/dist/utils/date.utils.js.map +1 -1
  28. package/jest.config.js +20 -20
  29. package/package.json +46 -46
  30. package/src/municipal/muniIssues/__tests__/muniIssues.setters.spec.ts +94 -92
  31. package/src/municipal/tickets/__tests__/tickets.statistics.spec.ts +99 -94
  32. package/src/municipal/tickets/index.ts +9 -3
  33. package/src/municipal/tickets/tickets.statistics.aggregation.ts +110 -110
  34. package/src/municipal/tickets/tickets.statistics.getters.ts +132 -109
  35. package/src/municipal/tickets/tickets.types.ts +54 -54
  36. package/src/talkpilot/calls/__tests__/calls.statistics.spec.ts +481 -375
  37. package/src/talkpilot/calls/calls.statistics.getters.ts +668 -590
  38. package/src/talkpilot/calls/calls.statistics.types.ts +48 -47
  39. package/src/talkpilot/clientsConfig/clientsConfig.types.ts +127 -127
  40. package/src/talkpilot/contextNotes/__tests__/contextNotes.getters.spec.ts +217 -176
  41. package/src/talkpilot/contextNotes/contextNotes.getters.ts +85 -86
  42. package/src/talkpilot/products/__tests__/products.getters.spec.ts +44 -45
  43. package/src/test-utils/factories/talkpilot/contextNotes.ts +40 -33
  44. package/src/utils/date.utils.ts +126 -116
  45. package/tsconfig.json +23 -23
@@ -1,109 +1,132 @@
1
- import { CityName } from "../utils/types";
2
- import {
3
- DAY_MS,
4
- endOfCalendarDayInTz,
5
- startOfCalendarDayInTz,
6
- } from "../../utils/date.utils";
7
- import { DEFAULT_LOOKBACK_DAYS } from "./tickets.constants";
8
- import {
9
- isDraftTicketExpr,
10
- runTicketStatsAggregate,
11
- subjectResolutionStages,
12
- ticketsWithCallSidMatch,
13
- } from "./tickets.statistics.aggregation";
14
- import type {
15
- TicketStatsDateRange,
16
- TicketStatsDateScope,
17
- TicketSubjectRow,
18
- } from "./tickets.types";
19
-
20
- export const resolveTicketStatsDateRange = (
21
- dateScope?: TicketStatsDateScope,
22
- ): TicketStatsDateRange => {
23
- const to = dateScope?.to ?? new Date();
24
- const from =
25
- dateScope?.from ?? new Date(to.getTime() - DEFAULT_LOOKBACK_DAYS * DAY_MS);
26
- return { from, to };
27
- };
28
-
29
- export const ticketStatsDateScopeFromYmd = (
30
- startStr: string,
31
- endStr: string,
32
- timezone: string,
33
- ): TicketStatsDateScope => ({
34
- from: startOfCalendarDayInTz(startStr, timezone),
35
- to: endOfCalendarDayInTz(endStr, timezone),
36
- });
37
-
38
- /** @deprecated Use findCallSidTicketCountsByCity instead. */
39
- export const findCallSidsWithTicketsByCity = async (
40
- cityName: CityName,
41
- dateScope?: TicketStatsDateScope,
42
- ): Promise<string[]> => {
43
- const rows = await runTicketStatsAggregate<{ _id: unknown }>([
44
- { $match: ticketsWithCallSidMatch(cityName, resolveTicketStatsDateRange(dateScope)) },
45
- { $group: { _id: "$callSid" } },
46
- ]);
47
- return rows
48
- .filter((r) => r._id != null && r._id !== "")
49
- .map((r) => String(r._id));
50
- };
51
-
52
- export const findCallSidTicketCountsByCity = async (
53
- cityName: CityName,
54
- dateScope?: TicketStatsDateScope,
55
- ): Promise<Map<string, number>> => {
56
- const rows = await runTicketStatsAggregate<{ _id: unknown; ticketCount: number }>([
57
- { $match: ticketsWithCallSidMatch(cityName, resolveTicketStatsDateRange(dateScope)) },
58
- { $group: { _id: "$callSid", ticketCount: { $sum: 1 } } },
59
- ]);
60
- return new Map(
61
- rows
62
- .filter((r) => r._id != null && r._id !== "")
63
- .map((r) => [String(r._id), r.ticketCount])
64
- );
65
- };
66
-
67
-
68
- /** @deprecated Use findCallSidDraftTicketCountsByCity instead. */
69
- export const findCallSidsWithDraftTicketsByCity = async (
70
- cityName: CityName,
71
- dateScope?: TicketStatsDateScope,
72
- ): Promise<string[]> => {
73
- const rows = await runTicketStatsAggregate<{ _id: unknown }>([
74
- { $match: ticketsWithCallSidMatch(cityName, resolveTicketStatsDateRange(dateScope)) },
75
- { $match: { $expr: isDraftTicketExpr } },
76
- { $group: { _id: "$callSid" } },
77
- ]);
78
- return rows
79
- .filter((r) => r._id != null && r._id !== "")
80
- .map((r) => String(r._id));
81
- };
82
-
83
- export const findCallSidDraftTicketCountsByCity = async (
84
- cityName: CityName,
85
- dateScope?: TicketStatsDateScope,
86
- ): Promise<Map<string, number>> => {
87
- const rows = await runTicketStatsAggregate<{ _id: unknown; ticketCount: number }>([
88
- { $match: ticketsWithCallSidMatch(cityName, resolveTicketStatsDateRange(dateScope)) },
89
- { $match: { $expr: isDraftTicketExpr } },
90
- { $group: { _id: "$callSid", ticketCount: { $sum: 1 } } },
91
- ]);
92
- return new Map(
93
- rows
94
- .filter((r) => r._id != null && r._id !== "")
95
- .map((r) => [String(r._id), r.ticketCount])
96
- );
97
- };
98
-
99
- export const findTicketSubjectRows = async (
100
- cityName: CityName,
101
- dateScope?: TicketStatsDateScope,
102
- ): Promise<TicketSubjectRow[]> => {
103
- const rows = await runTicketStatsAggregate<{ callSid: unknown; subject: unknown }>([
104
- { $match: ticketsWithCallSidMatch(cityName, resolveTicketStatsDateRange(dateScope)) },
105
- ...subjectResolutionStages(cityName),
106
- { $project: { _id: 0, callSid: 1, subject: 1 } },
107
- ]);
108
- return rows.map((r) => ({ callSid: String(r.callSid), subject: String(r.subject) }));
109
- };
1
+ import { CityName } from "../utils/types";
2
+ import {
3
+ DAY_MS,
4
+ endOfCalendarDayInTz,
5
+ startOfCalendarDayInTz,
6
+ } from "../../utils/date.utils";
7
+ import { DEFAULT_LOOKBACK_DAYS } from "./tickets.constants";
8
+ import {
9
+ isDraftTicketExpr,
10
+ runTicketStatsAggregate,
11
+ subjectResolutionStages,
12
+ ticketsWithCallSidMatch,
13
+ } from "./tickets.statistics.aggregation";
14
+ import type {
15
+ TicketStatsDateRange,
16
+ TicketStatsDateScope,
17
+ TicketSubjectRow,
18
+ } from "./tickets.types";
19
+
20
+ export const resolveTicketStatsDateRange = (
21
+ dateScope?: TicketStatsDateScope,
22
+ ): TicketStatsDateRange => {
23
+ const to = dateScope?.to ?? new Date();
24
+ const from =
25
+ dateScope?.from ?? new Date(to.getTime() - DEFAULT_LOOKBACK_DAYS * DAY_MS);
26
+ return { from, to };
27
+ };
28
+
29
+ export const ticketStatsDateScopeFromYmd = (
30
+ startStr: string,
31
+ endStr: string,
32
+ timezone: string,
33
+ ): TicketStatsDateScope => ({
34
+ from: startOfCalendarDayInTz(startStr, timezone),
35
+ to: endOfCalendarDayInTz(endStr, timezone),
36
+ });
37
+
38
+ /** @deprecated Use findCallSidTicketCountsByCity instead. */
39
+ export const findCallSidsWithTicketsByCity = async (
40
+ cityName: CityName,
41
+ dateScope?: TicketStatsDateScope,
42
+ ): Promise<string[]> => {
43
+ const rows = await runTicketStatsAggregate<{ _id: unknown }>([
44
+ {
45
+ $match: ticketsWithCallSidMatch(
46
+ cityName,
47
+ resolveTicketStatsDateRange(dateScope),
48
+ ),
49
+ },
50
+ { $group: { _id: "$callSid" } },
51
+ ]);
52
+ return rows
53
+ .filter((r) => r._id != null && r._id !== "")
54
+ .map((r) => String(r._id));
55
+ };
56
+
57
+ export const findCallSidTicketCountsByCity = async (
58
+ cityName: CityName,
59
+ dateScope?: TicketStatsDateScope,
60
+ ): Promise<Map<string, number>> => {
61
+ const rows = await runTicketStatsAggregate<{
62
+ _id: unknown;
63
+ ticketCount: number;
64
+ }>([
65
+ {
66
+ $match: ticketsWithCallSidMatch(
67
+ cityName,
68
+ resolveTicketStatsDateRange(dateScope),
69
+ ),
70
+ },
71
+ { $group: { _id: "$callSid", ticketCount: { $sum: 1 } } },
72
+ ]);
73
+ return new Map(
74
+ rows
75
+ .filter((r) => r._id != null && r._id !== "")
76
+ .map((r) => [String(r._id), r.ticketCount]),
77
+ );
78
+ };
79
+
80
+ /** @deprecated Use findCallSidDraftTicketCountsByCity instead. */
81
+ export const findCallSidsWithDraftTicketsByCity = async (
82
+ cityName: CityName,
83
+ dateScope?: TicketStatsDateScope,
84
+ ): Promise<string[]> => {
85
+ const rows = await runTicketStatsAggregate<{ _id: unknown }>([
86
+ { $match: ticketsWithCallSidMatch(cityName, resolveTicketStatsDateRange(dateScope)) },
87
+ { $match: { $expr: isDraftTicketExpr } },
88
+ { $group: { _id: "$callSid" } },
89
+ ]);
90
+ return rows
91
+ .filter((r) => r._id != null && r._id !== "")
92
+ .map((r) => String(r._id));
93
+ };
94
+
95
+ export const findCallSidDraftTicketCountsByCity = async (
96
+ cityName: CityName,
97
+ dateScope?: TicketStatsDateScope,
98
+ ): Promise<Map<string, number>> => {
99
+ const rows = await runTicketStatsAggregate<{ _id: unknown; ticketCount: number }>([
100
+ { $match: ticketsWithCallSidMatch(cityName, resolveTicketStatsDateRange(dateScope)) },
101
+ { $match: { $expr: isDraftTicketExpr } },
102
+ { $group: { _id: "$callSid", ticketCount: { $sum: 1 } } },
103
+ ]);
104
+ return new Map(
105
+ rows
106
+ .filter((r) => r._id != null && r._id !== "")
107
+ .map((r) => [String(r._id), r.ticketCount]),
108
+ );
109
+ };
110
+
111
+ export const findTicketSubjectRows = async (
112
+ cityName: CityName,
113
+ dateScope?: TicketStatsDateScope,
114
+ ): Promise<TicketSubjectRow[]> => {
115
+ const rows = await runTicketStatsAggregate<{
116
+ callSid: unknown;
117
+ subject: unknown;
118
+ }>([
119
+ {
120
+ $match: ticketsWithCallSidMatch(
121
+ cityName,
122
+ resolveTicketStatsDateRange(dateScope),
123
+ ),
124
+ },
125
+ ...subjectResolutionStages(cityName),
126
+ { $project: { _id: 0, callSid: 1, subject: 1 } },
127
+ ]);
128
+ return rows.map((r) => ({
129
+ callSid: String(r.callSid),
130
+ subject: String(r.subject),
131
+ }));
132
+ };
@@ -1,54 +1,54 @@
1
- import { ObjectId, WithId } from "mongodb";
2
-
3
- import { CityName } from "../utils/types";
4
-
5
- export type Ticket = {
6
- _id: ObjectId;
7
- createdAt: Date;
8
- updatedAt: Date;
9
- callSid?: string;
10
- isDraft?: boolean;
11
- cityName: CityName;
12
- externalCallFields: {
13
- first_name?: string;
14
- last_name?: string;
15
- event_description?: string;
16
- street?: string;
17
- house_number?: string;
18
- event_subject_id?: string;
19
- event_sub_subject_id?: string;
20
- event_sub_subject_id2?: string | null;
21
- call_number?: string;
22
- status?: number;
23
- error?: string;
24
- image1?: string;
25
- image2?: string;
26
- image3?: string;
27
- file1?: string;
28
- file2?: string;
29
- file3?: string;
30
- };
31
- guestJwt?: string;
32
- };
33
-
34
- export type TicketDoc = WithId<Ticket>;
35
-
36
- export type SubjectItem = {
37
- subject: string;
38
- count: number;
39
- };
40
-
41
- export type TicketSubjectRow = {
42
- callSid: string;
43
- subject: string;
44
- };
45
-
46
- export type TicketStatsDateScope = {
47
- from?: Date;
48
- to?: Date;
49
- };
50
-
51
- export type TicketStatsDateRange = {
52
- from: Date;
53
- to: Date;
54
- };
1
+ import { ObjectId, WithId } from "mongodb";
2
+
3
+ import { CityName } from "../utils/types";
4
+
5
+ export type Ticket = {
6
+ _id: ObjectId;
7
+ createdAt: Date;
8
+ updatedAt: Date;
9
+ callSid?: string;
10
+ isDraft?: boolean;
11
+ cityName: CityName;
12
+ externalCallFields: {
13
+ first_name?: string;
14
+ last_name?: string;
15
+ event_description?: string;
16
+ street?: string;
17
+ house_number?: string;
18
+ event_subject_id?: string;
19
+ event_sub_subject_id?: string;
20
+ event_sub_subject_id2?: string | null;
21
+ call_number?: string;
22
+ status?: number;
23
+ error?: string;
24
+ image1?: string;
25
+ image2?: string;
26
+ image3?: string;
27
+ file1?: string;
28
+ file2?: string;
29
+ file3?: string;
30
+ };
31
+ guestJwt?: string;
32
+ };
33
+
34
+ export type TicketDoc = WithId<Ticket>;
35
+
36
+ export type SubjectItem = {
37
+ subject: string;
38
+ count: number;
39
+ };
40
+
41
+ export type TicketSubjectRow = {
42
+ callSid: string;
43
+ subject: string;
44
+ };
45
+
46
+ export type TicketStatsDateScope = {
47
+ from?: Date;
48
+ to?: Date;
49
+ };
50
+
51
+ export type TicketStatsDateRange = {
52
+ from: Date;
53
+ to: Date;
54
+ };