@talkpilot/core-db 1.3.9 → 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.
- package/.cursor/rules/development.mdc +65 -65
- package/DEVELOPMENT.md +141 -141
- package/README.md +297 -257
- package/README_OLD.md +160 -160
- package/dist/municipal/tickets/index.d.ts +1 -1
- package/dist/municipal/tickets/index.d.ts.map +1 -1
- package/dist/municipal/tickets/tickets.statistics.aggregation.d.ts +34 -0
- package/dist/municipal/tickets/tickets.statistics.aggregation.d.ts.map +1 -1
- package/dist/municipal/tickets/tickets.statistics.aggregation.js +14 -1
- package/dist/municipal/tickets/tickets.statistics.aggregation.js.map +1 -1
- package/dist/municipal/tickets/tickets.statistics.getters.d.ts.map +1 -1
- package/dist/municipal/tickets/tickets.statistics.getters.js +15 -6
- package/dist/municipal/tickets/tickets.statistics.getters.js.map +1 -1
- package/dist/municipal/tickets/tickets.types.d.ts +1 -0
- package/dist/municipal/tickets/tickets.types.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.dashboard.d.ts +3 -0
- package/dist/talkpilot/calls/calls.dashboard.d.ts.map +1 -0
- package/dist/talkpilot/calls/calls.dashboard.js +191 -0
- package/dist/talkpilot/calls/calls.dashboard.js.map +1 -0
- package/dist/talkpilot/calls/calls.statistics.getters.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.statistics.getters.js +39 -10
- package/dist/talkpilot/calls/calls.statistics.getters.js.map +1 -1
- package/dist/talkpilot/calls/calls.statistics.types.d.ts +1 -0
- package/dist/talkpilot/calls/calls.statistics.types.d.ts.map +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts.map +1 -1
- package/dist/talkpilot/contextNotes/contextNotes.getters.d.ts.map +1 -1
- package/dist/talkpilot/contextNotes/contextNotes.getters.js +1 -3
- package/dist/talkpilot/contextNotes/contextNotes.getters.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/contextNotes.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/contextNotes.js +4 -1
- package/dist/test-utils/factories/talkpilot/contextNotes.js.map +1 -1
- package/dist/utils/date.utils.d.ts.map +1 -1
- package/dist/utils/date.utils.js +7 -2
- package/dist/utils/date.utils.js.map +1 -1
- package/jest.config.js +20 -20
- package/package.json +46 -46
- package/src/municipal/muniIssues/__tests__/muniIssues.setters.spec.ts +94 -92
- package/src/municipal/tickets/__tests__/tickets.statistics.spec.ts +99 -68
- package/src/municipal/tickets/index.ts +9 -3
- package/src/municipal/tickets/tickets.statistics.aggregation.ts +110 -96
- package/src/municipal/tickets/tickets.statistics.getters.ts +132 -109
- package/src/municipal/tickets/tickets.types.ts +54 -53
- package/src/talkpilot/calls/__tests__/calls.statistics.spec.ts +481 -375
- package/src/talkpilot/calls/calls.statistics.getters.ts +668 -590
- package/src/talkpilot/calls/calls.statistics.types.ts +48 -47
- package/src/talkpilot/clientsConfig/clientsConfig.types.ts +127 -127
- package/src/talkpilot/contextNotes/__tests__/contextNotes.getters.spec.ts +217 -176
- package/src/talkpilot/contextNotes/contextNotes.getters.ts +85 -86
- package/src/talkpilot/products/__tests__/products.getters.spec.ts +44 -45
- package/src/test-utils/factories/talkpilot/contextNotes.ts +40 -33
- package/src/utils/date.utils.ts +126 -116
- package/tsconfig.json +23 -23
- package/.claude/settings.local.json +0 -11
- package/dist/municipal/tickets/tickets.deprecated.getters.d.ts +0 -12
- package/dist/municipal/tickets/tickets.deprecated.getters.d.ts.map +0 -1
- package/dist/municipal/tickets/tickets.deprecated.getters.js +0 -131
- package/dist/municipal/tickets/tickets.deprecated.getters.js.map +0 -1
- package/dist/municipal/tickets/tickets.statistics.dates.d.ts +0 -7
- package/dist/municipal/tickets/tickets.statistics.dates.d.ts.map +0 -1
- package/dist/municipal/tickets/tickets.statistics.dates.js +0 -40
- package/dist/municipal/tickets/tickets.statistics.dates.js.map +0 -1
- package/dist/municipal/tickets/tickets.statistics.pipeline.d.ts +0 -53
- package/dist/municipal/tickets/tickets.statistics.pipeline.d.ts.map +0 -1
- package/dist/municipal/tickets/tickets.statistics.pipeline.js +0 -112
- package/dist/municipal/tickets/tickets.statistics.pipeline.js.map +0 -1
- package/dist/municipal/tickets/tickets.statistics.utils.d.ts +0 -7
- package/dist/municipal/tickets/tickets.statistics.utils.d.ts.map +0 -1
- package/dist/municipal/tickets/tickets.statistics.utils.js +0 -40
- package/dist/municipal/tickets/tickets.statistics.utils.js.map +0 -1
- package/dist/talkpilot/calls/calls.statistics.ticketScope.d.ts +0 -12
- package/dist/talkpilot/calls/calls.statistics.ticketScope.d.ts.map +0 -1
- package/dist/talkpilot/calls/calls.statistics.ticketScope.js +0 -37
- package/dist/talkpilot/calls/calls.statistics.ticketScope.js.map +0 -1
- package/dist/talkpilot/calls/calls.statistics.tickets.d.ts +0 -17
- package/dist/talkpilot/calls/calls.statistics.tickets.d.ts.map +0 -1
- package/dist/talkpilot/calls/calls.statistics.tickets.js +0 -33
- package/dist/talkpilot/calls/calls.statistics.tickets.js.map +0 -1
- package/dist/utils/statistics.aggregation.d.ts +0 -20
- package/dist/utils/statistics.aggregation.d.ts.map +0 -1
- package/dist/utils/statistics.aggregation.js +0 -43
- package/dist/utils/statistics.aggregation.js.map +0 -1
|
@@ -1,45 +1,44 @@
|
|
|
1
|
-
import { getProductsCollection, getAllProducts } from "../products.getters";
|
|
2
|
-
import { ObjectId } from "../../index";
|
|
3
|
-
|
|
4
|
-
describe("products getters", () => {
|
|
5
|
-
it('should return the "products" collection', () => {
|
|
6
|
-
const collection = getProductsCollection();
|
|
7
|
-
expect(collection.collectionName).toBe("products");
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it("should return all product documents", async () => {
|
|
11
|
-
await getProductsCollection().insertMany([
|
|
12
|
-
{ _id: new ObjectId(), name: "Municipal" },
|
|
13
|
-
{ _id: new ObjectId(), name: "Clinics" },
|
|
14
|
-
]);
|
|
15
|
-
|
|
16
|
-
const results = await getAllProducts();
|
|
17
|
-
expect(results.length).toBeGreaterThanOrEqual(2);
|
|
18
|
-
expect(results.map((p) => p.name)).toEqual(
|
|
19
|
-
expect.arrayContaining(["Municipal", "Clinics"]),
|
|
20
|
-
);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("should store and retrieve displayName locale map", async () => {
|
|
24
|
-
const id = new ObjectId();
|
|
25
|
-
await getProductsCollection().insertOne({
|
|
26
|
-
_id: id,
|
|
27
|
-
name: "Municipal",
|
|
28
|
-
displayName: { he: "עירייה", en: "Municipal" },
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const results = await getAllProducts();
|
|
32
|
-
const saved = results.find((p) => p._id.equals(id));
|
|
33
|
-
expect(saved?.displayName).toEqual({ he: "עירייה", en: "Municipal" });
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("should return products without displayName without error", async () => {
|
|
37
|
-
const id = new ObjectId();
|
|
38
|
-
await getProductsCollection().insertOne({ _id: id, name: "Rcure" });
|
|
39
|
-
|
|
40
|
-
const results = await getAllProducts();
|
|
41
|
-
const saved = results.find((p) => p._id.equals(id));
|
|
42
|
-
expect(saved?.displayName).toBeUndefined();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
});
|
|
1
|
+
import { getProductsCollection, getAllProducts } from "../products.getters";
|
|
2
|
+
import { ObjectId } from "../../index";
|
|
3
|
+
|
|
4
|
+
describe("products getters", () => {
|
|
5
|
+
it('should return the "products" collection', () => {
|
|
6
|
+
const collection = getProductsCollection();
|
|
7
|
+
expect(collection.collectionName).toBe("products");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("should return all product documents", async () => {
|
|
11
|
+
await getProductsCollection().insertMany([
|
|
12
|
+
{ _id: new ObjectId(), name: "Municipal" },
|
|
13
|
+
{ _id: new ObjectId(), name: "Clinics" },
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
const results = await getAllProducts();
|
|
17
|
+
expect(results.length).toBeGreaterThanOrEqual(2);
|
|
18
|
+
expect(results.map((p) => p.name)).toEqual(
|
|
19
|
+
expect.arrayContaining(["Municipal", "Clinics"]),
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("should store and retrieve displayName locale map", async () => {
|
|
24
|
+
const id = new ObjectId();
|
|
25
|
+
await getProductsCollection().insertOne({
|
|
26
|
+
_id: id,
|
|
27
|
+
name: "Municipal",
|
|
28
|
+
displayName: { he: "עירייה", en: "Municipal" },
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const results = await getAllProducts();
|
|
32
|
+
const saved = results.find((p) => p._id.equals(id));
|
|
33
|
+
expect(saved?.displayName).toEqual({ he: "עירייה", en: "Municipal" });
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should return products without displayName without error", async () => {
|
|
37
|
+
const id = new ObjectId();
|
|
38
|
+
await getProductsCollection().insertOne({ _id: id, name: "Rcure" });
|
|
39
|
+
|
|
40
|
+
const results = await getAllProducts();
|
|
41
|
+
const saved = results.find((p) => p._id.equals(id));
|
|
42
|
+
expect(saved?.displayName).toBeUndefined();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -1,33 +1,40 @@
|
|
|
1
|
-
import { Factory } from "fishery";
|
|
2
|
-
import { ObjectId } from "mongodb";
|
|
3
|
-
import { faker } from "@faker-js/faker";
|
|
4
|
-
import type { ContextNote, ContextNoteEntry } from "../../../talkpilot";
|
|
5
|
-
|
|
6
|
-
export const contextNoteEntryFactory = Factory.define<ContextNoteEntry>(() => ({
|
|
7
|
-
_id: new ObjectId(),
|
|
8
|
-
title: faker.lorem.words(3),
|
|
9
|
-
content: faker.lorem.sentences(2),
|
|
10
|
-
activeFrom: new Date(),
|
|
11
|
-
expiresAt: null,
|
|
12
|
-
createdAt: new Date(),
|
|
13
|
-
updatedAt: new Date(),
|
|
14
|
-
}));
|
|
15
|
-
|
|
16
|
-
export const contextNoteFactory = Factory.define<
|
|
17
|
-
_id:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
import { Factory } from "fishery";
|
|
2
|
+
import { ObjectId } from "mongodb";
|
|
3
|
+
import { faker } from "@faker-js/faker";
|
|
4
|
+
import type { ContextNote, ContextNoteEntry } from "../../../talkpilot";
|
|
5
|
+
|
|
6
|
+
export const contextNoteEntryFactory = Factory.define<ContextNoteEntry>(() => ({
|
|
7
|
+
_id: new ObjectId(),
|
|
8
|
+
title: faker.lorem.words(3),
|
|
9
|
+
content: faker.lorem.sentences(2),
|
|
10
|
+
activeFrom: new Date(),
|
|
11
|
+
expiresAt: null,
|
|
12
|
+
createdAt: new Date(),
|
|
13
|
+
updatedAt: new Date(),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
export const contextNoteFactory = Factory.define<
|
|
17
|
+
ContextNote & { _id: ObjectId }
|
|
18
|
+
>(() => ({
|
|
19
|
+
_id: new ObjectId(),
|
|
20
|
+
clientId: faker.string.uuid(),
|
|
21
|
+
product: "Municipal",
|
|
22
|
+
notes: [],
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
export function createContextNoteEntry(
|
|
26
|
+
overrides?: Partial<ContextNoteEntry>,
|
|
27
|
+
): ContextNoteEntry {
|
|
28
|
+
return {
|
|
29
|
+
...contextNoteEntryFactory.build(),
|
|
30
|
+
...overrides,
|
|
31
|
+
} as ContextNoteEntry;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function createContextNote(
|
|
35
|
+
overrides?: Partial<ContextNote>,
|
|
36
|
+
): ContextNote & { _id: ObjectId } {
|
|
37
|
+
return { ...contextNoteFactory.build(), ...overrides } as ContextNote & {
|
|
38
|
+
_id: ObjectId;
|
|
39
|
+
};
|
|
40
|
+
}
|
package/src/utils/date.utils.ts
CHANGED
|
@@ -1,116 +1,126 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared timezone-aware date helpers for statistics aggregations.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/** Milliseconds in a single day. */
|
|
6
|
-
export const DAY_MS = 24 * 60 * 60 * 1000;
|
|
7
|
-
|
|
8
|
-
/** Maps a short weekday name (as produced by Intl) to its index (Sun = 0). */
|
|
9
|
-
export const WEEKDAY: Record<string, number> = {
|
|
10
|
-
Sun: 0,
|
|
11
|
-
Mon: 1,
|
|
12
|
-
Tue: 2,
|
|
13
|
-
Wed: 3,
|
|
14
|
-
Thu: 4,
|
|
15
|
-
Fri: 5,
|
|
16
|
-
Sat: 6,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/** Parses a `YYYY-MM-DD` string into `[year, month, day]` numbers. */
|
|
20
|
-
export const parseYmd = (dateStr: string): [number, number, number] => {
|
|
21
|
-
const [y, m, d] = dateStr.split("-").map(Number);
|
|
22
|
-
return [y, m, d];
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/** Builds a zero-padded `YYYY-MM-DD` string from numeric parts. */
|
|
26
|
-
export const ymdToStr = (y: number, m: number, d: number): string =>
|
|
27
|
-
`${y}-${String(m).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
|
|
28
|
-
|
|
29
|
-
/** Parses a `YYYY-MM-DD` string as midnight UTC. */
|
|
30
|
-
export const toUtcDate = (dateStr: string): Date =>
|
|
31
|
-
new Date(`${dateStr}T00:00:00.000Z`);
|
|
32
|
-
|
|
33
|
-
/** Formats a date as a `YYYY-MM-DD` string in UTC. */
|
|
34
|
-
export const formatDate = (date: Date): string =>
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
*
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Shared timezone-aware date helpers for statistics aggregations.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/** Milliseconds in a single day. */
|
|
6
|
+
export const DAY_MS = 24 * 60 * 60 * 1000;
|
|
7
|
+
|
|
8
|
+
/** Maps a short weekday name (as produced by Intl) to its index (Sun = 0). */
|
|
9
|
+
export const WEEKDAY: Record<string, number> = {
|
|
10
|
+
Sun: 0,
|
|
11
|
+
Mon: 1,
|
|
12
|
+
Tue: 2,
|
|
13
|
+
Wed: 3,
|
|
14
|
+
Thu: 4,
|
|
15
|
+
Fri: 5,
|
|
16
|
+
Sat: 6,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Parses a `YYYY-MM-DD` string into `[year, month, day]` numbers. */
|
|
20
|
+
export const parseYmd = (dateStr: string): [number, number, number] => {
|
|
21
|
+
const [y, m, d] = dateStr.split("-").map(Number);
|
|
22
|
+
return [y, m, d];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** Builds a zero-padded `YYYY-MM-DD` string from numeric parts. */
|
|
26
|
+
export const ymdToStr = (y: number, m: number, d: number): string =>
|
|
27
|
+
`${y}-${String(m).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
|
|
28
|
+
|
|
29
|
+
/** Parses a `YYYY-MM-DD` string as midnight UTC. */
|
|
30
|
+
export const toUtcDate = (dateStr: string): Date =>
|
|
31
|
+
new Date(`${dateStr}T00:00:00.000Z`);
|
|
32
|
+
|
|
33
|
+
/** Formats a date as a `YYYY-MM-DD` string in UTC. */
|
|
34
|
+
export const formatDate = (date: Date): string =>
|
|
35
|
+
date.toISOString().slice(0, 10);
|
|
36
|
+
|
|
37
|
+
/** Adds `days` to a `YYYY-MM-DD` string, returning the resulting `YYYY-MM-DD`. */
|
|
38
|
+
export const addDaysToDateStr = (dateStr: string, days: number): string =>
|
|
39
|
+
formatDate(new Date(toUtcDate(dateStr).getTime() + days * DAY_MS));
|
|
40
|
+
|
|
41
|
+
/** Next civil calendar day (proleptic Gregorian). Avoids DST 24h steps that can stall iteration. */
|
|
42
|
+
export const incrementYmd = (
|
|
43
|
+
y: number,
|
|
44
|
+
m: number,
|
|
45
|
+
d: number,
|
|
46
|
+
): [number, number, number] => {
|
|
47
|
+
const next = new Date(Date.UTC(y, m - 1, d + 1));
|
|
48
|
+
return [next.getUTCFullYear(), next.getUTCMonth() + 1, next.getUTCDate()];
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Formats a date as the calendar day in the given timezone.
|
|
53
|
+
* `en-CA` yields ISO-8601 `YYYY-MM-DD`, which is lexicographically sortable
|
|
54
|
+
* (string compare == chronological compare) and matches MongoDB's `%Y-%m-%d`.
|
|
55
|
+
*/
|
|
56
|
+
export const formatYmdInTz = (date: Date, timezone: string): string =>
|
|
57
|
+
new Intl.DateTimeFormat("en-CA", { timeZone: timezone }).format(date);
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Returns the calendar day in the given timezone as numeric parts.
|
|
61
|
+
* Reads parts by `type` (not string order), so `en-US` is fine here.
|
|
62
|
+
*/
|
|
63
|
+
export const getYmdInTz = (date: Date, timezone: string) => {
|
|
64
|
+
const parts = Object.fromEntries(
|
|
65
|
+
new Intl.DateTimeFormat("en-US", {
|
|
66
|
+
timeZone: timezone,
|
|
67
|
+
year: "numeric",
|
|
68
|
+
month: "numeric",
|
|
69
|
+
day: "numeric",
|
|
70
|
+
})
|
|
71
|
+
.formatToParts(date)
|
|
72
|
+
.map((p) => [p.type, Number(p.value)]),
|
|
73
|
+
);
|
|
74
|
+
return { y: parts.year, m: parts.month, d: parts.day };
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/** Weekday index (Sun = 0) of a date in the given timezone. */
|
|
78
|
+
export const getWeekdayInTz = (date: Date, timezone: string): number =>
|
|
79
|
+
WEEKDAY[
|
|
80
|
+
new Intl.DateTimeFormat("en-US", {
|
|
81
|
+
timeZone: timezone,
|
|
82
|
+
weekday: "short",
|
|
83
|
+
}).format(date)
|
|
84
|
+
] ?? 0;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Returns the given `YYYY-MM-DD` day at noon UTC — a stable anchor inside the
|
|
88
|
+
* calendar day, far from midnight so timezone/DST shifts can't cross a date boundary.
|
|
89
|
+
*/
|
|
90
|
+
export const dateAtNoonUtc = (dateStr: string): Date => {
|
|
91
|
+
const [y, m, d] = parseYmd(dateStr);
|
|
92
|
+
return new Date(Date.UTC(y, m - 1, d, 12, 0, 0));
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* UTC instant at the start of the given `YYYY-MM-DD` calendar day in `timezone`.
|
|
97
|
+
* Binary-searches the boundary so it stays correct across DST transitions.
|
|
98
|
+
*/
|
|
99
|
+
export const startOfCalendarDayInTz = (
|
|
100
|
+
dateStr: string,
|
|
101
|
+
timezone: string,
|
|
102
|
+
): Date => {
|
|
103
|
+
const anchor = dateAtNoonUtc(dateStr).getTime();
|
|
104
|
+
let low = anchor - 2 * DAY_MS;
|
|
105
|
+
let high = anchor + DAY_MS;
|
|
106
|
+
|
|
107
|
+
while (high - low > 1 /* ms */) {
|
|
108
|
+
const mid = Math.floor((low + high) / 2);
|
|
109
|
+
if (formatYmdInTz(new Date(mid), timezone) >= dateStr) high = mid;
|
|
110
|
+
else low = mid;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return new Date(high);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/** UTC instant at the last millisecond of the given calendar day in `timezone`. */
|
|
117
|
+
export const endOfCalendarDayInTz = (
|
|
118
|
+
dateStr: string,
|
|
119
|
+
timezone: string,
|
|
120
|
+
): Date => {
|
|
121
|
+
const [y, m, d] = parseYmd(dateStr);
|
|
122
|
+
const nextDay = new Date(Date.UTC(y, m - 1, d + 1))
|
|
123
|
+
.toISOString()
|
|
124
|
+
.slice(0, 10);
|
|
125
|
+
return new Date(startOfCalendarDayInTz(nextDay, timezone).getTime() - 1);
|
|
126
|
+
};
|
package/tsconfig.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "CommonJS",
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"lib": ["ES2022"],
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"declarationMap": true,
|
|
9
|
-
"sourceMap": true,
|
|
10
|
-
"outDir": "dist",
|
|
11
|
-
"rootDir": "src",
|
|
12
|
-
"strict": true,
|
|
13
|
-
"esModuleInterop": true,
|
|
14
|
-
"forceConsistentCasingInFileNames": true,
|
|
15
|
-
"skipLibCheck": true,
|
|
16
|
-
"resolveJsonModule": true,
|
|
17
|
-
"experimentalDecorators": true,
|
|
18
|
-
"emitDecoratorMetadata": true,
|
|
19
|
-
"baseUrl": "."
|
|
20
|
-
},
|
|
21
|
-
"include": ["src/**/*"],
|
|
22
|
-
"exclude": ["node_modules", "dist", "test", "**/*.test.ts", "**/__tests__/*", "**/*.spec.ts"]
|
|
23
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "CommonJS",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"lib": ["ES2022"],
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"declarationMap": true,
|
|
9
|
+
"sourceMap": true,
|
|
10
|
+
"outDir": "dist",
|
|
11
|
+
"rootDir": "src",
|
|
12
|
+
"strict": true,
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"experimentalDecorators": true,
|
|
18
|
+
"emitDecoratorMetadata": true,
|
|
19
|
+
"baseUrl": "."
|
|
20
|
+
},
|
|
21
|
+
"include": ["src/**/*"],
|
|
22
|
+
"exclude": ["node_modules", "dist", "test", "**/*.test.ts", "**/__tests__/*", "**/*.spec.ts"]
|
|
23
|
+
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"permissions": {
|
|
3
|
-
"allow": [
|
|
4
|
-
"Bash(npx jest *)",
|
|
5
|
-
"Bash(git reset *)",
|
|
6
|
-
"Bash(git tag *)",
|
|
7
|
-
"Bash(node -p \"require\\('./package.json'\\).version\")",
|
|
8
|
-
"Bash(echo \"version: $\\(node -p \"require\\('./package.json'\\).version\"\\)\")"
|
|
9
|
-
]
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,131 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tickets.deprecated.getters.js","sourceRoot":"","sources":["../../../src/municipal/tickets/tickets.deprecated.getters.ts"],"names":[],"mappings":";;AAOA,8EAqBC;AAMD,wDAyGC;AA3ID,uDAAyD;AAGzD;;;GAGG;AACI,KAAK,UAAU,iCAAiC,CACrD,QAAgB,EAChB,QAAgB,EAChB,MAAc,EACd,QAAgB;IAEhB,MAAM,GAAG,GAAG,MAAM,IAAA,sCAAoB,GAAE;SACrC,SAAS,CAAgB;QACxB,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE;QACtE;YACE,UAAU,EAAE;gBACV,SAAS,EAAE;oBACT,aAAa,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,QAA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C,CAAC,EAAE,EAAE;KACzB,CAAC;SACD,OAAO,EAAE,CAAC;IAEb,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC5D,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QACxB,YAAY,EAAE,GAAG,CAAC,OAAO;QACzB,UAAU,EAAE,GAAG,CAAC,GAAG;QACnB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,UAAU,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;KAClE,CAAC,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|