@talkpilot/core-db 1.1.15 → 1.1.16
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 -98
- package/README.md +297 -160
- package/README_OLD.md +160 -0
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +10 -0
- package/dist/connection.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/municipal/index.d.ts +1 -0
- package/dist/municipal/index.d.ts.map +1 -1
- package/dist/municipal/index.js +1 -0
- package/dist/municipal/index.js.map +1 -1
- package/dist/municipal/muniIssues/index.d.ts +7 -0
- package/dist/municipal/muniIssues/index.d.ts.map +1 -0
- package/dist/municipal/muniIssues/index.js +29 -0
- package/dist/municipal/muniIssues/index.js.map +1 -0
- package/dist/municipal/muniIssues/muniIssues.constants.d.ts +14 -0
- package/dist/municipal/muniIssues/muniIssues.constants.d.ts.map +1 -0
- package/dist/municipal/muniIssues/muniIssues.constants.js +17 -0
- package/dist/municipal/muniIssues/muniIssues.constants.js.map +1 -0
- package/dist/municipal/muniIssues/muniIssues.getters.d.ts +7 -0
- package/dist/municipal/muniIssues/muniIssues.getters.d.ts.map +1 -0
- package/dist/municipal/muniIssues/muniIssues.getters.js +24 -0
- package/dist/municipal/muniIssues/muniIssues.getters.js.map +1 -0
- package/dist/municipal/muniIssues/muniIssues.schema.d.ts +4 -0
- package/dist/municipal/muniIssues/muniIssues.schema.d.ts.map +1 -0
- package/dist/municipal/muniIssues/muniIssues.schema.js +63 -0
- package/dist/municipal/muniIssues/muniIssues.schema.js.map +1 -0
- package/dist/municipal/muniIssues/muniIssues.setters.d.ts +4 -0
- package/dist/municipal/muniIssues/muniIssues.setters.d.ts.map +1 -0
- package/dist/municipal/muniIssues/muniIssues.setters.js +22 -0
- package/dist/municipal/muniIssues/muniIssues.setters.js.map +1 -0
- package/dist/municipal/muniIssues/muniIssues.setup.d.ts +3 -0
- package/dist/municipal/muniIssues/muniIssues.setup.d.ts.map +1 -0
- package/dist/municipal/muniIssues/muniIssues.setup.js +61 -0
- package/dist/municipal/muniIssues/muniIssues.setup.js.map +1 -0
- package/dist/municipal/muniIssues/muniIssues.types.d.ts +30 -0
- package/dist/municipal/muniIssues/muniIssues.types.d.ts.map +1 -0
- package/dist/municipal/muniIssues/muniIssues.types.js +3 -0
- package/dist/municipal/muniIssues/muniIssues.types.js.map +1 -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.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 +69 -0
- package/dist/municipal/tickets/tickets.statistics.aggregation.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.aggregation.js +99 -0
- package/dist/municipal/tickets/tickets.statistics.aggregation.js.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.getters.d.ts +12 -0
- package/dist/municipal/tickets/tickets.statistics.getters.d.ts.map +1 -0
- package/dist/municipal/tickets/tickets.statistics.getters.js +80 -0
- package/dist/municipal/tickets/tickets.statistics.getters.js.map +1 -0
- package/dist/municipal/tickets/tickets.types.d.ts +15 -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.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.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 +28 -0
- package/dist/talkpilot/calls/calls.statistics.getters.d.ts.map +1 -0
- package/dist/talkpilot/calls/calls.statistics.getters.js +453 -0
- package/dist/talkpilot/calls/calls.statistics.getters.js.map +1 -0
- package/dist/talkpilot/calls/calls.statistics.types.d.ts +43 -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 +8 -7
- 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 +4 -0
- package/dist/talkpilot/calls/dashboard/calls.dashboard.d.ts.map +1 -0
- package/dist/talkpilot/calls/dashboard/calls.dashboard.js +223 -0
- package/dist/talkpilot/calls/dashboard/calls.dashboard.js.map +1 -0
- package/dist/talkpilot/calls/dashboard/calls.dashboard.types.d.ts +45 -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 +20 -7
- 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/contextNotes/contextNotes.getters.d.ts +19 -0
- package/dist/talkpilot/contextNotes/contextNotes.getters.d.ts.map +1 -0
- package/dist/talkpilot/contextNotes/contextNotes.getters.js +55 -0
- package/dist/talkpilot/contextNotes/contextNotes.getters.js.map +1 -0
- package/dist/talkpilot/contextNotes/contextNotes.types.d.ts +19 -0
- package/dist/talkpilot/contextNotes/contextNotes.types.d.ts.map +1 -0
- package/dist/talkpilot/contextNotes/contextNotes.types.js +3 -0
- package/dist/talkpilot/contextNotes/contextNotes.types.js.map +1 -0
- package/dist/talkpilot/contextNotes/index.d.ts +3 -0
- package/dist/talkpilot/contextNotes/index.d.ts.map +1 -0
- package/dist/talkpilot/contextNotes/index.js +19 -0
- package/dist/talkpilot/contextNotes/index.js.map +1 -0
- package/dist/talkpilot/flows/flows.schema.d.ts +3 -0
- package/dist/talkpilot/flows/flows.schema.d.ts.map +1 -1
- package/dist/talkpilot/flows/flows.schema.js +2 -1
- package/dist/talkpilot/flows/flows.schema.js.map +1 -1
- package/dist/talkpilot/flows/flows.types.d.ts +2 -0
- package/dist/talkpilot/flows/flows.types.d.ts.map +1 -1
- package/dist/talkpilot/index.d.ts +3 -0
- package/dist/talkpilot/index.d.ts.map +1 -1
- package/dist/talkpilot/index.js +3 -0
- package/dist/talkpilot/index.js.map +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/products/index.d.ts +3 -0
- package/dist/talkpilot/products/index.d.ts.map +1 -0
- package/dist/talkpilot/products/index.js +19 -0
- package/dist/talkpilot/products/index.js.map +1 -0
- package/dist/talkpilot/products/products.getters.d.ts +6 -0
- package/dist/talkpilot/products/products.getters.d.ts.map +1 -0
- package/dist/talkpilot/products/products.getters.js +14 -0
- package/dist/talkpilot/products/products.getters.js.map +1 -0
- package/dist/talkpilot/products/products.types.d.ts +9 -0
- package/dist/talkpilot/products/products.types.d.ts.map +1 -0
- package/dist/talkpilot/products/products.types.js +3 -0
- package/dist/talkpilot/products/products.types.js.map +1 -0
- package/dist/talkpilot/results/index.d.ts +1 -1
- package/dist/talkpilot/results/index.d.ts.map +1 -1
- package/dist/talkpilot/results/index.js +3 -1
- package/dist/talkpilot/results/index.js.map +1 -1
- package/dist/talkpilot/results/results.getter.d.ts +3 -1
- package/dist/talkpilot/results/results.getter.d.ts.map +1 -1
- package/dist/talkpilot/results/results.getter.js +11 -2
- package/dist/talkpilot/results/results.getter.js.map +1 -1
- package/dist/talkpilot/retry_analyze/index.d.ts +3 -0
- package/dist/talkpilot/retry_analyze/index.d.ts.map +1 -0
- package/dist/talkpilot/retry_analyze/index.js +19 -0
- package/dist/talkpilot/retry_analyze/index.js.map +1 -0
- package/dist/talkpilot/retry_analyze/retryAnalyze.getters.d.ts +10 -0
- package/dist/talkpilot/retry_analyze/retryAnalyze.getters.d.ts.map +1 -0
- package/dist/talkpilot/retry_analyze/retryAnalyze.getters.js +60 -0
- package/dist/talkpilot/retry_analyze/retryAnalyze.getters.js.map +1 -0
- package/dist/talkpilot/retry_analyze/retryAnalyze.types.d.ts +12 -0
- package/dist/talkpilot/retry_analyze/retryAnalyze.types.d.ts.map +1 -0
- package/dist/talkpilot/retry_analyze/retryAnalyze.types.js +3 -0
- package/dist/talkpilot/retry_analyze/retryAnalyze.types.js.map +1 -0
- package/dist/test-utils/db-utils.d.ts.map +1 -1
- package/dist/test-utils/db-utils.js +2 -0
- package/dist/test-utils/db-utils.js.map +1 -1
- package/dist/test-utils/factories/index.d.ts +3 -0
- package/dist/test-utils/factories/index.d.ts.map +1 -1
- package/dist/test-utils/factories/index.js +3 -0
- package/dist/test-utils/factories/index.js.map +1 -1
- package/dist/test-utils/factories/municipal/muniIssues.d.ts +10 -0
- package/dist/test-utils/factories/municipal/muniIssues.d.ts.map +1 -0
- package/dist/test-utils/factories/municipal/muniIssues.js +30 -0
- package/dist/test-utils/factories/municipal/muniIssues.js.map +1 -0
- package/dist/test-utils/factories/talkpilot/contextNotes.d.ts +16 -0
- package/dist/test-utils/factories/talkpilot/contextNotes.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/contextNotes.js +33 -0
- package/dist/test-utils/factories/talkpilot/contextNotes.js.map +1 -0
- package/dist/test-utils/factories/websitalk/scans.d.ts +5 -0
- package/dist/test-utils/factories/websitalk/scans.d.ts.map +1 -0
- package/dist/test-utils/factories/websitalk/scans.js +25 -0
- package/dist/test-utils/factories/websitalk/scans.js.map +1 -0
- 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 +108 -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/websitalk/index.d.ts +7 -0
- package/dist/websitalk/index.d.ts.map +1 -0
- package/dist/websitalk/index.js +34 -0
- package/dist/websitalk/index.js.map +1 -0
- package/dist/websitalk/mongodb-client.d.ts +13 -0
- package/dist/websitalk/mongodb-client.d.ts.map +1 -0
- package/dist/websitalk/mongodb-client.js +56 -0
- package/dist/websitalk/mongodb-client.js.map +1 -0
- package/dist/websitalk/scans/index.d.ts +3 -0
- package/dist/websitalk/scans/index.d.ts.map +1 -0
- package/dist/websitalk/scans/index.js +19 -0
- package/dist/websitalk/scans/index.js.map +1 -0
- package/dist/websitalk/scans/scans.getters.d.ts +12 -0
- package/dist/websitalk/scans/scans.getters.d.ts.map +1 -0
- package/dist/websitalk/scans/scans.getters.js +74 -0
- package/dist/websitalk/scans/scans.getters.js.map +1 -0
- package/dist/websitalk/scans/scans.types.d.ts +45 -0
- package/dist/websitalk/scans/scans.types.d.ts.map +1 -0
- package/dist/websitalk/scans/scans.types.js +3 -0
- package/dist/websitalk/scans/scans.types.js.map +1 -0
- package/jest.config.js +20 -19
- package/package.json +46 -45
- package/src/connection.ts +12 -0
- package/src/index.ts +10 -0
- package/src/municipal/index.ts +1 -0
- package/src/municipal/muniIssues/__tests__/muniIssues.setters.spec.ts +94 -0
- package/src/municipal/muniIssues/__tests__/muniIssues.setup.spec.ts +92 -0
- package/src/municipal/muniIssues/index.ts +17 -0
- package/src/municipal/muniIssues/muniIssues.constants.ts +18 -0
- package/src/municipal/muniIssues/muniIssues.getters.ts +24 -0
- package/src/municipal/muniIssues/muniIssues.schema.ts +66 -0
- package/src/municipal/muniIssues/muniIssues.setters.ts +24 -0
- package/src/municipal/muniIssues/muniIssues.setup.ts +65 -0
- package/src/municipal/muniIssues/muniIssues.types.ts +37 -0
- package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +1 -37
- package/src/municipal/tickets/__tests__/tickets.statistics.spec.ts +99 -0
- package/src/municipal/tickets/index.ts +9 -2
- 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 +110 -0
- package/src/municipal/tickets/tickets.statistics.getters.ts +132 -0
- package/src/municipal/tickets/tickets.types.ts +54 -43
- package/src/talkpilot/calls/__tests__/calls.dashboard.spec.ts +149 -0
- package/src/talkpilot/calls/__tests__/calls.spec.ts +48 -30
- package/src/talkpilot/calls/__tests__/calls.statistics.spec.ts +481 -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 +668 -0
- package/src/talkpilot/calls/calls.statistics.types.ts +48 -0
- package/src/talkpilot/calls/calls.types.ts +18 -14
- package/src/talkpilot/calls/dashboard/calls.dashboard.ts +292 -0
- package/src/talkpilot/calls/dashboard/calls.dashboard.types.ts +57 -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 +91 -7
- package/src/talkpilot/clientsConfig/clientsConfig.getters.ts +34 -1
- package/src/talkpilot/clientsConfig/clientsConfig.types.ts +127 -92
- package/src/talkpilot/contextNotes/__tests__/contextNotes.getters.spec.ts +217 -0
- package/src/talkpilot/contextNotes/contextNotes.getters.ts +85 -0
- package/src/talkpilot/contextNotes/contextNotes.types.ts +20 -0
- package/src/talkpilot/contextNotes/index.ts +2 -0
- package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +31 -2
- package/src/talkpilot/flows/flows.schema.ts +2 -1
- package/src/talkpilot/flows/flows.types.ts +3 -0
- package/src/talkpilot/index.ts +3 -0
- 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/products/__tests__/products.getters.spec.ts +44 -0
- package/src/talkpilot/products/index.ts +2 -0
- package/src/talkpilot/products/products.getters.ts +12 -0
- package/src/talkpilot/products/products.types.ts +9 -0
- package/src/talkpilot/results/index.ts +2 -0
- package/src/talkpilot/results/results.getter.ts +14 -2
- package/src/talkpilot/retry_analyze/__tests__/retryAnalyze.getters.spec.ts +156 -0
- package/src/talkpilot/retry_analyze/index.ts +2 -0
- package/src/talkpilot/retry_analyze/retryAnalyze.getters.ts +84 -0
- package/src/talkpilot/retry_analyze/retryAnalyze.types.ts +13 -0
- package/src/test-utils/db-utils.ts +3 -1
- package/src/test-utils/factories/index.ts +3 -0
- package/src/test-utils/factories/municipal/muniIssues.ts +32 -0
- package/src/test-utils/factories/talkpilot/contextNotes.ts +40 -0
- package/src/test-utils/factories/websitalk/scans.ts +23 -0
- package/src/utils/date.utils.ts +126 -0
- package/src/utils/shared.types.ts +4 -0
- package/src/websitalk/index.ts +15 -0
- package/src/websitalk/mongodb-client.ts +61 -0
- package/src/websitalk/scans/__tests__/scans.spec.ts +218 -0
- package/src/websitalk/scans/index.ts +2 -0
- package/src/websitalk/scans/scans.getters.ts +113 -0
- package/src/websitalk/scans/scans.types.ts +53 -0
- package/tsconfig.json +23 -23
- package/dist/talkpilot/subscriptions/subscriptions.utils.d.ts +0 -4
- package/dist/talkpilot/subscriptions/subscriptions.utils.d.ts.map +0 -1
- package/dist/talkpilot/subscriptions/subscriptions.utils.js +0 -20
- package/dist/talkpilot/subscriptions/subscriptions.utils.js.map +0 -1
|
@@ -6,14 +6,14 @@ import {
|
|
|
6
6
|
getClientPhoneData,
|
|
7
7
|
createPhoneNumberEntity,
|
|
8
8
|
createPurchasedPhoneNumber,
|
|
9
|
-
} from
|
|
10
|
-
import { getFlowsCollection } from
|
|
11
|
-
import { createFlow, createPhoneNumber } from
|
|
12
|
-
import { ObjectId } from
|
|
13
|
-
|
|
14
|
-
describe(
|
|
15
|
-
describe(
|
|
16
|
-
it(
|
|
9
|
+
} from "../phone_numbers.getter";
|
|
10
|
+
import { getFlowsCollection } from "../../flows/flows.getter";
|
|
11
|
+
import { createFlow, createPhoneNumber } from "../../../test-utils/factories";
|
|
12
|
+
import { ObjectId } from "mongodb";
|
|
13
|
+
|
|
14
|
+
describe("db.phoneNumbers", () => {
|
|
15
|
+
describe("getPhoneDataByPhoneNumber", () => {
|
|
16
|
+
it("return phone number data with flow", async () => {
|
|
17
17
|
const flow = createFlow({
|
|
18
18
|
clientId: "test-client-id",
|
|
19
19
|
conversationSettings: {
|
|
@@ -129,9 +129,9 @@ describe('db.phoneNumbers', () => {
|
|
|
129
129
|
});
|
|
130
130
|
});
|
|
131
131
|
|
|
132
|
-
describe(
|
|
133
|
-
it(
|
|
134
|
-
const clientId =
|
|
132
|
+
describe("getPhoneNumbersForFlows", () => {
|
|
133
|
+
it("returns all phone numbers for the client with flow ObjectIds, newest first", async () => {
|
|
134
|
+
const clientId = "flowsClient";
|
|
135
135
|
const flow1 = createFlow({ clientId });
|
|
136
136
|
const flow2 = createFlow({ clientId });
|
|
137
137
|
await getFlowsCollection().insertMany([flow1, flow2]);
|
|
@@ -139,16 +139,16 @@ describe('db.phoneNumbers', () => {
|
|
|
139
139
|
const older = createPhoneNumber({
|
|
140
140
|
client_id: clientId,
|
|
141
141
|
flow_id: flow1._id,
|
|
142
|
-
phone_number:
|
|
142
|
+
phone_number: "+100",
|
|
143
143
|
is_primary: true,
|
|
144
|
-
createdAt: new Date(
|
|
144
|
+
createdAt: new Date("2023-01-01"),
|
|
145
145
|
});
|
|
146
146
|
const newer = createPhoneNumber({
|
|
147
147
|
client_id: clientId,
|
|
148
148
|
flow_id: flow2._id,
|
|
149
|
-
phone_number:
|
|
149
|
+
phone_number: "+200",
|
|
150
150
|
is_primary: false,
|
|
151
|
-
createdAt: new Date(
|
|
151
|
+
createdAt: new Date("2023-06-01"),
|
|
152
152
|
});
|
|
153
153
|
|
|
154
154
|
await getPhoneNumbersCollection().insertMany([older, newer]);
|
|
@@ -158,27 +158,30 @@ describe('db.phoneNumbers', () => {
|
|
|
158
158
|
expect(result).toHaveLength(2);
|
|
159
159
|
expect(result[0]).toEqual({
|
|
160
160
|
flowId: String(flow2._id),
|
|
161
|
-
phoneNumber:
|
|
161
|
+
phoneNumber: "+200",
|
|
162
162
|
isPrimary: false,
|
|
163
163
|
});
|
|
164
164
|
expect(result[1]).toEqual({
|
|
165
165
|
flowId: String(flow1._id),
|
|
166
|
-
phoneNumber:
|
|
166
|
+
phoneNumber: "+100",
|
|
167
167
|
isPrimary: true,
|
|
168
168
|
});
|
|
169
169
|
});
|
|
170
170
|
|
|
171
|
-
it(
|
|
172
|
-
const result = await getPhoneNumbersForFlows(
|
|
171
|
+
it("returns an empty array when the client has no phone numbers", async () => {
|
|
172
|
+
const result = await getPhoneNumbersForFlows("noSuchClient");
|
|
173
173
|
expect(result).toEqual([]);
|
|
174
174
|
});
|
|
175
175
|
|
|
176
|
-
it(
|
|
177
|
-
const clientA =
|
|
178
|
-
const clientB =
|
|
176
|
+
it("does not include phone numbers for other clients", async () => {
|
|
177
|
+
const clientA = "clientA";
|
|
178
|
+
const clientB = "clientB";
|
|
179
179
|
const flow = createFlow();
|
|
180
180
|
await getFlowsCollection().insertOne(flow);
|
|
181
|
-
const phone = createPhoneNumber({
|
|
181
|
+
const phone = createPhoneNumber({
|
|
182
|
+
client_id: clientA,
|
|
183
|
+
flow_id: flow._id,
|
|
184
|
+
});
|
|
182
185
|
await getPhoneNumbersCollection().insertOne(phone);
|
|
183
186
|
|
|
184
187
|
const result = await getPhoneNumbersForFlows(clientB);
|
|
@@ -186,9 +189,9 @@ describe('db.phoneNumbers', () => {
|
|
|
186
189
|
});
|
|
187
190
|
});
|
|
188
191
|
|
|
189
|
-
describe(
|
|
190
|
-
it(
|
|
191
|
-
const clientId =
|
|
192
|
+
describe("createPhoneNumberEntity", () => {
|
|
193
|
+
it("creates first phone number as primary", async () => {
|
|
194
|
+
const clientId = "newClient";
|
|
192
195
|
const flowId = new ObjectId().toHexString();
|
|
193
196
|
const phoneNumber = "+123456789";
|
|
194
197
|
|
|
@@ -215,14 +218,14 @@ describe('db.phoneNumbers', () => {
|
|
|
215
218
|
});
|
|
216
219
|
});
|
|
217
220
|
|
|
218
|
-
describe(
|
|
219
|
-
it(
|
|
220
|
-
const clientId =
|
|
221
|
+
describe("createPurchasedPhoneNumber", () => {
|
|
222
|
+
it("persists a phone_numbers document with provider payload and flow", async () => {
|
|
223
|
+
const clientId = "purchasedClientDb";
|
|
221
224
|
const flowId = new ObjectId().toHexString();
|
|
222
|
-
const phoneNumber =
|
|
225
|
+
const phoneNumber = "+15551234567";
|
|
223
226
|
const providerPayload = {
|
|
224
|
-
provider:
|
|
225
|
-
provider_sid:
|
|
227
|
+
provider: "twilio" as const,
|
|
228
|
+
provider_sid: "PNxxxxxxxx",
|
|
226
229
|
};
|
|
227
230
|
|
|
228
231
|
await createPurchasedPhoneNumber(
|
|
@@ -233,13 +236,15 @@ describe('db.phoneNumbers', () => {
|
|
|
233
236
|
);
|
|
234
237
|
|
|
235
238
|
// Re-read from Mongo to confirm insert succeeded (not only the function return value).
|
|
236
|
-
const stored = await getPhoneNumbersCollection().findOne({
|
|
239
|
+
const stored = await getPhoneNumbersCollection().findOne({
|
|
240
|
+
phone_number: phoneNumber,
|
|
241
|
+
});
|
|
237
242
|
expect(stored).not.toBeNull();
|
|
238
243
|
expect(stored).toMatchObject({
|
|
239
244
|
phone_number: phoneNumber,
|
|
240
245
|
client_id: clientId,
|
|
241
|
-
provider:
|
|
242
|
-
provider_sid:
|
|
246
|
+
provider: "twilio",
|
|
247
|
+
provider_sid: "PNxxxxxxxx",
|
|
243
248
|
flow_id: new ObjectId(flowId),
|
|
244
249
|
});
|
|
245
250
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export type * from
|
|
1
|
+
export * from "./phone_numbers.getter";
|
|
2
|
+
export type * from "./phone_numbers.types";
|
|
@@ -6,12 +6,12 @@ import {
|
|
|
6
6
|
getFlowsCollection,
|
|
7
7
|
ObjectId,
|
|
8
8
|
findSubscriptions,
|
|
9
|
-
} from
|
|
9
|
+
} from "../index";
|
|
10
10
|
import {
|
|
11
11
|
ClientPhoneNumberForFlow,
|
|
12
12
|
PhoneNumber,
|
|
13
13
|
PhoneNumberWithFlow,
|
|
14
|
-
PurchasedPhoneProviderPayload
|
|
14
|
+
PurchasedPhoneProviderPayload,
|
|
15
15
|
} from "./phone_numbers.types";
|
|
16
16
|
|
|
17
17
|
export const getPhoneNumbersCollection = (): Collection<PhoneNumber> =>
|
|
@@ -140,13 +140,17 @@ export const createPurchasedPhoneNumber = async (
|
|
|
140
140
|
await getPhoneNumbersCollection().insertOne(doc);
|
|
141
141
|
|
|
142
142
|
const created = await getClientPhoneData(clientId, isPrimary);
|
|
143
|
-
if (!created) throw new Error(
|
|
143
|
+
if (!created) throw new Error("Failed to create phoneNumber");
|
|
144
144
|
return created;
|
|
145
145
|
};
|
|
146
146
|
|
|
147
|
-
export const findClientByPhoneNumber = async (
|
|
148
|
-
|
|
149
|
-
|
|
147
|
+
export const findClientByPhoneNumber = async (
|
|
148
|
+
phoneNumber: string,
|
|
149
|
+
): Promise<Client> => {
|
|
150
|
+
const phoneData = await getPhoneNumbersCollection().findOne({
|
|
151
|
+
phone_number: phoneNumber,
|
|
152
|
+
});
|
|
153
|
+
if (!phoneData) throw new Error("Failed to get phone data");
|
|
150
154
|
const clientId = phoneData.client_id;
|
|
151
155
|
const client = await getClientsCollection().findOne({ clientId });
|
|
152
156
|
if (!client) throw new Error("Failed to get client");
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
export const phoneNumbersMongoSchema = {
|
|
2
|
-
bsonType:
|
|
3
|
-
required: [
|
|
2
|
+
bsonType: "object",
|
|
3
|
+
required: ["client_id", "phone_number"],
|
|
4
4
|
properties: {
|
|
5
|
-
_id: { bsonType:
|
|
6
|
-
client_id: { bsonType:
|
|
7
|
-
flow_id: { bsonType: [
|
|
8
|
-
phone_number: { bsonType:
|
|
9
|
-
is_primary: { bsonType:
|
|
10
|
-
provider: { bsonType:
|
|
11
|
-
provider_sid: { bsonType:
|
|
12
|
-
friendly_name: { bsonType:
|
|
13
|
-
createdAt: { bsonType:
|
|
14
|
-
updatedAt: { bsonType:
|
|
5
|
+
_id: { bsonType: "objectId" },
|
|
6
|
+
client_id: { bsonType: "string" },
|
|
7
|
+
flow_id: { bsonType: ["objectId", "string"] },
|
|
8
|
+
phone_number: { bsonType: "string" },
|
|
9
|
+
is_primary: { bsonType: "bool" },
|
|
10
|
+
provider: { bsonType: "string" },
|
|
11
|
+
provider_sid: { bsonType: "string" },
|
|
12
|
+
friendly_name: { bsonType: "string" },
|
|
13
|
+
createdAt: { bsonType: "date" },
|
|
14
|
+
updatedAt: { bsonType: "date" },
|
|
15
15
|
},
|
|
16
16
|
additionalProperties: false,
|
|
17
17
|
} as const;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ObjectId, WithId } from
|
|
2
|
-
import { Flow } from
|
|
1
|
+
import { ObjectId, WithId } from "mongodb";
|
|
2
|
+
import { Flow } from "../flows/flows.types";
|
|
3
3
|
|
|
4
4
|
export type PurchasedPhoneProviderPayload = {
|
|
5
|
-
provider:
|
|
5
|
+
provider: "twilio" | "telnyx";
|
|
6
6
|
provider_sid: string;
|
|
7
7
|
friendly_name?: string;
|
|
8
8
|
};
|
|
@@ -14,7 +14,7 @@ export type PhoneNumber = {
|
|
|
14
14
|
phone_number: string;
|
|
15
15
|
subscriptionId?: string;
|
|
16
16
|
is_primary: boolean;
|
|
17
|
-
provider?:
|
|
17
|
+
provider?: "twilio" | "telnyx";
|
|
18
18
|
provider_sid?: string;
|
|
19
19
|
friendly_name?: string;
|
|
20
20
|
createdAt: Date;
|
|
@@ -0,0 +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
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Collection, WithId } from "mongodb";
|
|
2
|
+
import { getDb } from "../index";
|
|
3
|
+
import type { Product } from "./products.types";
|
|
4
|
+
|
|
5
|
+
export const getProductsCollection = (): Collection<Product> => {
|
|
6
|
+
return getDb().collection<Product>("products");
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/** Returns all product documents */
|
|
10
|
+
export const getAllProducts = (): Promise<WithId<Product>[]> => {
|
|
11
|
+
return getProductsCollection().find().toArray();
|
|
12
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getDb,
|
|
1
|
+
import { Collection, ObjectId } from "mongodb";
|
|
2
|
+
import { getDb, Session } from "../index";
|
|
3
3
|
import type { Result } from "./results.types";
|
|
4
4
|
|
|
5
5
|
export const getResultsCollection = (): Collection<Result> =>
|
|
@@ -25,3 +25,15 @@ export const initializeResultDocument = async (
|
|
|
25
25
|
if (!result) throw new Error("Failed to initialized result");
|
|
26
26
|
return result;
|
|
27
27
|
};
|
|
28
|
+
|
|
29
|
+
export const findResultById = async (
|
|
30
|
+
resultId: string | ObjectId,
|
|
31
|
+
): Promise<Result | null> => {
|
|
32
|
+
return getResultsCollection().findOne({ _id: new ObjectId(resultId) });
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const findResultByCallSid = async (
|
|
36
|
+
callSid: string,
|
|
37
|
+
): Promise<Result | null> => {
|
|
38
|
+
return getResultsCollection().findOne({ "calls.callSid": callSid });
|
|
39
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, jest } from "@jest/globals";
|
|
2
|
+
import { ObjectId } from "mongodb";
|
|
3
|
+
import {
|
|
4
|
+
getAllRetryAnalyzeDocs,
|
|
5
|
+
upsertRetryAnalyzeDoc,
|
|
6
|
+
insertRetryAnalyzeDoc,
|
|
7
|
+
updateRetryAnalyzeErrorLog,
|
|
8
|
+
} from "../retryAnalyze.getters";
|
|
9
|
+
import { setDb } from "../../index";
|
|
10
|
+
import { RetryAnalyzeDoc } from "../retryAnalyze.types";
|
|
11
|
+
|
|
12
|
+
describe("retryAnalyze.getters", () => {
|
|
13
|
+
let mockCollection: any;
|
|
14
|
+
let mockDb: any;
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
mockCollection = {
|
|
18
|
+
find: jest.fn().mockReturnThis(),
|
|
19
|
+
toArray: jest.fn(),
|
|
20
|
+
insertOne: jest.fn(),
|
|
21
|
+
updateOne: jest.fn(),
|
|
22
|
+
deleteOne: jest.fn(),
|
|
23
|
+
};
|
|
24
|
+
mockDb = {
|
|
25
|
+
collection: jest.fn().mockReturnValue(mockCollection),
|
|
26
|
+
};
|
|
27
|
+
setDb(mockDb as any);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("getAllRetryAnalyzeDocs", () => {
|
|
31
|
+
it("should filter documents with retry >= 5 and include old format docs", async () => {
|
|
32
|
+
const mockDocs = [
|
|
33
|
+
{ _id: new ObjectId(), callSid: "old-doc", errorLog: "{}" },
|
|
34
|
+
{ _id: new ObjectId(), callSid: "retry-1", errorLog: "{}", retry: 1 },
|
|
35
|
+
{ _id: new ObjectId(), callSid: "retry-5", errorLog: "{}", retry: 5 },
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
mockCollection.toArray.mockResolvedValue(mockDocs);
|
|
39
|
+
|
|
40
|
+
await getAllRetryAnalyzeDocs();
|
|
41
|
+
|
|
42
|
+
expect(mockCollection.find).toHaveBeenCalledWith({
|
|
43
|
+
$or: [{ retry: { $lt: 5 } }, { retry: { $exists: false } }],
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("upsertRetryAnalyzeDoc", () => {
|
|
49
|
+
const error429 = JSON.stringify({
|
|
50
|
+
error: {
|
|
51
|
+
code: 429,
|
|
52
|
+
message: "Resource exhausted. Please try again later.",
|
|
53
|
+
status: "RESOURCE_EXHAUSTED",
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should upsert document correctly with $setOnInsert for clientId and createdAt", async () => {
|
|
58
|
+
const doc = {
|
|
59
|
+
callSid: "call-123",
|
|
60
|
+
errorLog: error429,
|
|
61
|
+
clientId: "client-1",
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
mockCollection.updateOne.mockResolvedValue({
|
|
65
|
+
upsertedId: new ObjectId(),
|
|
66
|
+
matchedCount: 0,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
await upsertRetryAnalyzeDoc(doc);
|
|
70
|
+
|
|
71
|
+
expect(mockCollection.updateOne).toHaveBeenCalledWith(
|
|
72
|
+
{ callSid: doc.callSid },
|
|
73
|
+
expect.objectContaining({
|
|
74
|
+
$set: expect.objectContaining({
|
|
75
|
+
errorLog: doc.errorLog,
|
|
76
|
+
updatedAt: expect.any(Date),
|
|
77
|
+
}),
|
|
78
|
+
$setOnInsert: expect.objectContaining({
|
|
79
|
+
createdAt: expect.any(Date),
|
|
80
|
+
clientId: doc.clientId,
|
|
81
|
+
retry: 0,
|
|
82
|
+
}),
|
|
83
|
+
}),
|
|
84
|
+
{ upsert: true },
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("should ensure only one document exists for the same callSid even on multiple failures", async () => {
|
|
89
|
+
const doc = {
|
|
90
|
+
callSid: "CA_SINGLE_DOC",
|
|
91
|
+
errorLog: error429,
|
|
92
|
+
clientId: "client-1",
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
mockCollection.updateOne
|
|
96
|
+
.mockResolvedValueOnce({ upsertedId: new ObjectId(), matchedCount: 0 })
|
|
97
|
+
.mockResolvedValueOnce({ upsertedId: null, matchedCount: 1 });
|
|
98
|
+
|
|
99
|
+
await upsertRetryAnalyzeDoc(doc);
|
|
100
|
+
await upsertRetryAnalyzeDoc(doc);
|
|
101
|
+
|
|
102
|
+
expect(mockCollection.updateOne).toHaveBeenCalledWith(
|
|
103
|
+
{ callSid: doc.callSid },
|
|
104
|
+
expect.objectContaining({
|
|
105
|
+
$setOnInsert: expect.objectContaining({ retry: 0 }),
|
|
106
|
+
}),
|
|
107
|
+
{ upsert: true },
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
expect(mockCollection.updateOne).toHaveBeenLastCalledWith(
|
|
111
|
+
{ callSid: doc.callSid },
|
|
112
|
+
{ $inc: { retry: 1 } },
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe("insertRetryAnalyzeDoc", () => {
|
|
118
|
+
it("should perform a simple insert", async () => {
|
|
119
|
+
const doc: Omit<RetryAnalyzeDoc, "_id"> = {
|
|
120
|
+
callSid: "call-456",
|
|
121
|
+
retry: 0,
|
|
122
|
+
clientId: "client-2",
|
|
123
|
+
errorLog: "err",
|
|
124
|
+
updatedAt: new Date(),
|
|
125
|
+
createdAt: new Date(),
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
mockCollection.insertOne.mockResolvedValue({
|
|
129
|
+
insertedId: new ObjectId(),
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
await insertRetryAnalyzeDoc(doc);
|
|
133
|
+
|
|
134
|
+
expect(mockCollection.insertOne).toHaveBeenCalledWith(doc);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("updateRetryAnalyzeErrorLog", () => {
|
|
139
|
+
it("should update errorLog, updatedAt and increment retry", async () => {
|
|
140
|
+
const id = new ObjectId();
|
|
141
|
+
const errorLog = "new retry error";
|
|
142
|
+
|
|
143
|
+
mockCollection.updateOne.mockResolvedValue({ modifiedCount: 1 });
|
|
144
|
+
|
|
145
|
+
await updateRetryAnalyzeErrorLog(id, errorLog);
|
|
146
|
+
|
|
147
|
+
expect(mockCollection.updateOne).toHaveBeenCalledWith(
|
|
148
|
+
{ _id: id },
|
|
149
|
+
{
|
|
150
|
+
$set: { errorLog, updatedAt: expect.any(Date) },
|
|
151
|
+
$inc: { retry: 1 },
|
|
152
|
+
},
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Collection, ObjectId } from "mongodb";
|
|
2
|
+
import { getDb } from "../index";
|
|
3
|
+
import type { RetryAnalyzeDoc, RetryAnalyzeWithId } from "./retryAnalyze.types";
|
|
4
|
+
|
|
5
|
+
const COLLECTION_NAME = "retryAnalyze";
|
|
6
|
+
|
|
7
|
+
export const getRetryAnalyzeCollection = (): Collection<RetryAnalyzeDoc> => {
|
|
8
|
+
return getDb().collection<RetryAnalyzeDoc>(COLLECTION_NAME);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const getAllRetryAnalyzeDocs = async (): Promise<
|
|
12
|
+
RetryAnalyzeWithId[]
|
|
13
|
+
> => {
|
|
14
|
+
return getRetryAnalyzeCollection()
|
|
15
|
+
.find({
|
|
16
|
+
$or: [{ retry: { $lt: 5 } }, { retry: { $exists: false } }],
|
|
17
|
+
})
|
|
18
|
+
.toArray();
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const insertRetryAnalyzeDoc = async (
|
|
22
|
+
doc: Omit<RetryAnalyzeDoc, "_id">,
|
|
23
|
+
): Promise<ObjectId> => {
|
|
24
|
+
const result = await getRetryAnalyzeCollection().insertOne(doc);
|
|
25
|
+
return result.insertedId;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const upsertRetryAnalyzeDoc = async (
|
|
29
|
+
doc: Pick<RetryAnalyzeDoc, "callSid" | "errorLog" | "clientId">,
|
|
30
|
+
): Promise<ObjectId | null> => {
|
|
31
|
+
const now = new Date();
|
|
32
|
+
const result = await getRetryAnalyzeCollection().updateOne(
|
|
33
|
+
{ callSid: doc.callSid },
|
|
34
|
+
{
|
|
35
|
+
$set: {
|
|
36
|
+
errorLog: doc.errorLog,
|
|
37
|
+
updatedAt: now,
|
|
38
|
+
},
|
|
39
|
+
$setOnInsert: {
|
|
40
|
+
createdAt: now,
|
|
41
|
+
clientId: doc.clientId,
|
|
42
|
+
retry: 0,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
{ upsert: true },
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
if (result.matchedCount > 0) {
|
|
49
|
+
await getRetryAnalyzeCollection().updateOne(
|
|
50
|
+
{ callSid: doc.callSid },
|
|
51
|
+
{ $inc: { retry: 1 } },
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return result.upsertedId || null;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const deleteRetryAnalyzeDocById = async (
|
|
59
|
+
id: ObjectId,
|
|
60
|
+
): Promise<boolean> => {
|
|
61
|
+
const result = await getRetryAnalyzeCollection().deleteOne({ _id: id });
|
|
62
|
+
return result.deletedCount === 1;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const deleteRetryAnalyzeDocByCallSid = async (
|
|
66
|
+
callSid: string,
|
|
67
|
+
): Promise<boolean> => {
|
|
68
|
+
const result = await getRetryAnalyzeCollection().deleteOne({ callSid });
|
|
69
|
+
return result.deletedCount === 1;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const updateRetryAnalyzeErrorLog = async (
|
|
73
|
+
id: ObjectId,
|
|
74
|
+
errorLog: string,
|
|
75
|
+
): Promise<boolean> => {
|
|
76
|
+
const result = await getRetryAnalyzeCollection().updateOne(
|
|
77
|
+
{ _id: id },
|
|
78
|
+
{
|
|
79
|
+
$set: { errorLog, updatedAt: new Date() },
|
|
80
|
+
$inc: { retry: 1 },
|
|
81
|
+
},
|
|
82
|
+
);
|
|
83
|
+
return result.modifiedCount === 1;
|
|
84
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ObjectId, WithId } from "mongodb";
|
|
2
|
+
|
|
3
|
+
export type RetryAnalyzeDoc = {
|
|
4
|
+
_id?: ObjectId;
|
|
5
|
+
callSid: string;
|
|
6
|
+
retry: number;
|
|
7
|
+
clientId: string;
|
|
8
|
+
errorLog: string;
|
|
9
|
+
updatedAt: Date;
|
|
10
|
+
createdAt: Date;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type RetryAnalyzeWithId = WithId<RetryAnalyzeDoc>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MongoMemoryServer } from "mongodb-memory-server";
|
|
2
2
|
import { MongoClient, Db } from "mongodb";
|
|
3
|
-
import { setDb, setMunicipalDataDb } from "../index";
|
|
3
|
+
import { setDb, setMunicipalDataDb, setWebsitalkDb } from "../index";
|
|
4
4
|
|
|
5
5
|
let mongoServer: MongoMemoryServer;
|
|
6
6
|
let client: MongoClient;
|
|
@@ -13,8 +13,10 @@ export async function initTestDb(): Promise<Db> {
|
|
|
13
13
|
await client.connect();
|
|
14
14
|
const talkpilotDb = client.db();
|
|
15
15
|
const municipalDb = client.db("municipal-data");
|
|
16
|
+
const websitalkDb = client.db("website-talk");
|
|
16
17
|
setDb(talkpilotDb);
|
|
17
18
|
setMunicipalDataDb(municipalDb);
|
|
19
|
+
setWebsitalkDb(websitalkDb);
|
|
18
20
|
return talkpilotDb;
|
|
19
21
|
}
|
|
20
22
|
|
|
@@ -3,10 +3,13 @@ export * from "./talkpilot/calls";
|
|
|
3
3
|
export * from "./talkpilot/clientAudioBuffers";
|
|
4
4
|
export * from "./talkpilot/clientsConfig";
|
|
5
5
|
export * from "./talkpilot/flows";
|
|
6
|
+
export * from "./talkpilot/contextNotes";
|
|
6
7
|
export * from "./talkpilot/groups";
|
|
7
8
|
export * from "./talkpilot/phone_numbers";
|
|
8
9
|
export * from "./talkpilot/sessions";
|
|
9
10
|
export * from "./municipal/cities";
|
|
10
11
|
export * from "./municipal/departmentsSubjects";
|
|
12
|
+
export * from "./municipal/muniIssues";
|
|
11
13
|
export * from "./municipal/streets";
|
|
12
14
|
export * from "./municipal/tickets";
|
|
15
|
+
export * from "./websitalk/scans";
|