@talkpilot/core-db 1.1.6 → 1.1.8
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/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +24 -21
- package/dist/connection.js.map +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/municipal/cities/cities.getters.d.ts +2 -2
- package/dist/municipal/cities/cities.getters.d.ts.map +1 -1
- package/dist/municipal/cities/cities.getters.js +4 -8
- package/dist/municipal/cities/cities.getters.js.map +1 -1
- package/dist/municipal/cities/cities.types.d.ts +1 -1
- package/dist/municipal/cities/index.d.ts +2 -2
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.d.ts +3 -3
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.d.ts.map +1 -1
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.js +22 -30
- package/dist/municipal/departmentsSubjects/departmentsSubjects.getters.js.map +1 -1
- package/dist/municipal/departmentsSubjects/departmentsSubjects.types.d.ts +4 -4
- package/dist/municipal/departmentsSubjects/departmentsSubjects.types.d.ts.map +1 -1
- package/dist/municipal/departmentsSubjects/index.d.ts +2 -2
- package/dist/municipal/index.d.ts +8 -8
- package/dist/municipal/index.d.ts.map +1 -1
- package/dist/municipal/index.js +1 -1
- package/dist/municipal/mongodb-client.d.ts +1 -1
- package/dist/municipal/mongodb-client.d.ts.map +1 -1
- package/dist/municipal/mongodb-client.js +25 -13
- package/dist/municipal/mongodb-client.js.map +1 -1
- package/dist/municipal/streets/index.d.ts +2 -2
- package/dist/municipal/streets/streets.getters.d.ts +3 -3
- package/dist/municipal/streets/streets.getters.d.ts.map +1 -1
- package/dist/municipal/streets/streets.getters.js +9 -19
- package/dist/municipal/streets/streets.getters.js.map +1 -1
- package/dist/municipal/streets/streets.types.d.ts +1 -1
- package/dist/municipal/systemInstructions/index.d.ts +3 -3
- package/dist/municipal/systemInstructions/index.d.ts.map +1 -1
- package/dist/municipal/systemInstructions/instructions.getters.d.ts +3 -3
- package/dist/municipal/systemInstructions/instructions.getters.d.ts.map +1 -1
- package/dist/municipal/systemInstructions/instructions.getters.js +4 -10
- package/dist/municipal/systemInstructions/instructions.getters.js.map +1 -1
- package/dist/municipal/systemInstructions/instructions.setters.d.ts +2 -2
- package/dist/municipal/systemInstructions/instructions.setters.d.ts.map +1 -1
- package/dist/municipal/systemInstructions/instructions.setters.js +8 -13
- package/dist/municipal/systemInstructions/instructions.setters.js.map +1 -1
- package/dist/municipal/systemInstructions/instructions.types.d.ts +3 -3
- package/dist/municipal/systemInstructions/instructions.types.d.ts.map +1 -1
- package/dist/municipal/systemInstructions/instructions.types.js +6 -6
- package/dist/municipal/tickets/index.d.ts +2 -2
- package/dist/municipal/tickets/tickets.getters.d.ts +3 -3
- package/dist/municipal/tickets/tickets.getters.d.ts.map +1 -1
- package/dist/municipal/tickets/tickets.getters.js +29 -50
- package/dist/municipal/tickets/tickets.getters.js.map +1 -1
- package/dist/municipal/tickets/tickets.types.d.ts +1 -1
- package/dist/municipal/tickets/tickets.types.d.ts.map +1 -1
- package/dist/municipal/utils/types.d.ts +1 -1
- package/dist/municipal/utils/types.d.ts.map +1 -1
- package/dist/talkpilot/agents/agents.getters.d.ts +1 -1
- package/dist/talkpilot/agents/agents.getters.js +2 -2
- package/dist/talkpilot/agents/agents.types.d.ts +2 -2
- package/dist/talkpilot/agents/index.d.ts +2 -2
- package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.d.ts +2 -2
- package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.d.ts.map +1 -1
- package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.js +1 -1
- package/dist/talkpilot/backgroundToolResults/backgroundToolResults.getters.js.map +1 -1
- package/dist/talkpilot/backgroundToolResults/backgroundToolResults.types.d.ts +2 -2
- package/dist/talkpilot/backgroundToolResults/index.d.ts +2 -2
- package/dist/talkpilot/calls/calls.getters.d.ts +3 -3
- package/dist/talkpilot/calls/calls.getters.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.getters.js +15 -19
- package/dist/talkpilot/calls/calls.getters.js.map +1 -1
- package/dist/talkpilot/calls/calls.types.d.ts +3 -3
- package/dist/talkpilot/calls/calls.types.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.types.js +2 -2
- package/dist/talkpilot/calls/index.d.ts +2 -2
- package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.d.ts +2 -2
- package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.d.ts.map +1 -1
- package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.js +2 -2
- package/dist/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.js.map +1 -1
- package/dist/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.d.ts +2 -2
- package/dist/talkpilot/clientAudioBuffers/index.d.ts +2 -2
- package/dist/talkpilot/clients/clients.getters.d.ts +2 -2
- package/dist/talkpilot/clients/clients.getters.d.ts.map +1 -1
- package/dist/talkpilot/clients/clients.getters.js +2 -5
- package/dist/talkpilot/clients/clients.getters.js.map +1 -1
- package/dist/talkpilot/clients/clients.types.d.ts +1 -1
- package/dist/talkpilot/clients/index.d.ts +2 -2
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts +2 -2
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts.map +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.js +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.js.map +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts +3 -3
- package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts.map +1 -1
- package/dist/talkpilot/clientsConfig/index.d.ts +2 -2
- package/dist/talkpilot/flows/flows.getter.d.ts +2 -2
- package/dist/talkpilot/flows/flows.getter.d.ts.map +1 -1
- package/dist/talkpilot/flows/flows.getter.js +1 -1
- package/dist/talkpilot/flows/flows.getter.js.map +1 -1
- 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 +80 -87
- package/dist/talkpilot/flows/flows.schema.js.map +1 -1
- package/dist/talkpilot/flows/flows.types.d.ts +17 -16
- package/dist/talkpilot/flows/flows.types.d.ts.map +1 -1
- package/dist/talkpilot/flows/index.d.ts +2 -2
- package/dist/talkpilot/groups/groups.getters.d.ts +2 -2
- package/dist/talkpilot/groups/groups.getters.d.ts.map +1 -1
- package/dist/talkpilot/groups/groups.getters.js +2 -2
- package/dist/talkpilot/groups/groups.getters.js.map +1 -1
- package/dist/talkpilot/groups/groups.types.d.ts +1 -1
- package/dist/talkpilot/groups/index.d.ts +3 -3
- package/dist/talkpilot/groups/phone.utils.d.ts +1 -1
- package/dist/talkpilot/groups/phone.utils.d.ts.map +1 -1
- package/dist/talkpilot/groups/phone.utils.js +2 -2
- package/dist/talkpilot/groups/phone.utils.js.map +1 -1
- package/dist/talkpilot/index.d.ts +16 -16
- package/dist/talkpilot/index.js +1 -1
- package/dist/talkpilot/leads/index.d.ts +2 -2
- package/dist/talkpilot/leads/leads.getter.d.ts +2 -2
- package/dist/talkpilot/leads/leads.getter.d.ts.map +1 -1
- package/dist/talkpilot/leads/leads.getter.js +1 -1
- package/dist/talkpilot/leads/leads.getter.js.map +1 -1
- package/dist/talkpilot/leads/leads.schema.js +16 -16
- package/dist/talkpilot/leads/leads.types.d.ts +1 -1
- package/dist/talkpilot/mongodb-client.d.ts +1 -1
- package/dist/talkpilot/mongodb-client.d.ts.map +1 -1
- package/dist/talkpilot/mongodb-client.js +29 -16
- package/dist/talkpilot/mongodb-client.js.map +1 -1
- package/dist/talkpilot/phone_numbers/index.d.ts +2 -2
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts +3 -3
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.js +13 -28
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.js.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.schema.js +9 -9
- package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts.map +1 -1
- package/dist/talkpilot/plans/index.d.ts +2 -2
- package/dist/talkpilot/plans/plans.getters.d.ts +2 -2
- package/dist/talkpilot/plans/plans.getters.d.ts.map +1 -1
- package/dist/talkpilot/plans/plans.getters.js +3 -3
- package/dist/talkpilot/plans/plans.getters.js.map +1 -1
- package/dist/talkpilot/plans/plans.types.d.ts +4 -4
- package/dist/talkpilot/plans/plans.types.d.ts.map +1 -1
- package/dist/talkpilot/plans/plans.types.js +19 -19
- package/dist/talkpilot/results/index.d.ts +2 -2
- package/dist/talkpilot/results/index.d.ts.map +1 -1
- package/dist/talkpilot/results/index.js.map +1 -1
- package/dist/talkpilot/results/results.getter.d.ts +3 -3
- package/dist/talkpilot/results/results.getter.d.ts.map +1 -1
- package/dist/talkpilot/results/results.getter.js +4 -4
- package/dist/talkpilot/results/results.getter.js.map +1 -1
- package/dist/talkpilot/results/results.schema.js +18 -18
- package/dist/talkpilot/results/results.types.d.ts +1 -1
- package/dist/talkpilot/sessions/index.d.ts +2 -2
- package/dist/talkpilot/sessions/sessions.getter.d.ts +3 -3
- package/dist/talkpilot/sessions/sessions.getter.d.ts.map +1 -1
- package/dist/talkpilot/sessions/sessions.getter.js +10 -13
- package/dist/talkpilot/sessions/sessions.getter.js.map +1 -1
- package/dist/talkpilot/sessions/sessions.schema.js +17 -17
- package/dist/talkpilot/sessions/sessions.types.d.ts +2 -2
- package/dist/talkpilot/subscriptions/index.d.ts +3 -3
- package/dist/talkpilot/subscriptions/subscriptions.getters.d.ts +2 -2
- package/dist/talkpilot/subscriptions/subscriptions.getters.d.ts.map +1 -1
- package/dist/talkpilot/subscriptions/subscriptions.getters.js +11 -11
- package/dist/talkpilot/subscriptions/subscriptions.getters.js.map +1 -1
- package/dist/talkpilot/subscriptions/subscriptions.getters.utils.d.ts +2 -2
- package/dist/talkpilot/subscriptions/subscriptions.getters.utils.d.ts.map +1 -1
- package/dist/talkpilot/subscriptions/subscriptions.getters.utils.js.map +1 -1
- package/dist/talkpilot/subscriptions/subscriptions.types.d.ts +2 -2
- package/dist/talkpilot/subscriptions/subscriptions.types.d.ts.map +1 -1
- package/dist/talkpilot/subscriptions/subscriptions.types.js +7 -7
- package/dist/talkpilot/utils/query.utils.d.ts +1 -1
- package/dist/test-utils/db-utils.d.ts +1 -1
- package/dist/test-utils/db-utils.js +2 -2
- package/dist/test-utils/factories/index.d.ts +12 -12
- package/dist/test-utils/factories/municipal/cities.d.ts +2 -2
- package/dist/test-utils/factories/municipal/cities.d.ts.map +1 -1
- package/dist/test-utils/factories/municipal/cities.js +1 -1
- package/dist/test-utils/factories/municipal/departmentsSubjects.d.ts +2 -2
- package/dist/test-utils/factories/municipal/departmentsSubjects.d.ts.map +1 -1
- package/dist/test-utils/factories/municipal/departmentsSubjects.js +1 -7
- package/dist/test-utils/factories/municipal/departmentsSubjects.js.map +1 -1
- package/dist/test-utils/factories/municipal/streets.d.ts +2 -2
- package/dist/test-utils/factories/municipal/streets.d.ts.map +1 -1
- package/dist/test-utils/factories/municipal/streets.js +1 -6
- package/dist/test-utils/factories/municipal/streets.js.map +1 -1
- package/dist/test-utils/factories/municipal/tickets.d.ts +2 -2
- package/dist/test-utils/factories/municipal/tickets.d.ts.map +1 -1
- package/dist/test-utils/factories/municipal/tickets.js +1 -7
- package/dist/test-utils/factories/municipal/tickets.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/agents.d.ts +2 -2
- package/dist/test-utils/factories/talkpilot/agents.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/agents.js +4 -4
- package/dist/test-utils/factories/talkpilot/calls.d.ts +2 -2
- package/dist/test-utils/factories/talkpilot/calls.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/calls.js +1 -1
- package/dist/test-utils/factories/talkpilot/clientAudioBuffers.d.ts +2 -2
- package/dist/test-utils/factories/talkpilot/clientAudioBuffers.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/clientAudioBuffers.js +1 -1
- package/dist/test-utils/factories/talkpilot/clientAudioBuffers.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/clientsConfig.d.ts +2 -2
- package/dist/test-utils/factories/talkpilot/clientsConfig.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/clientsConfig.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/flows.d.ts +3 -3
- package/dist/test-utils/factories/talkpilot/flows.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/flows.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/groups.d.ts +2 -2
- package/dist/test-utils/factories/talkpilot/groups.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/groups.js +9 -9
- package/dist/test-utils/factories/talkpilot/groups.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/phone_numbers.d.ts +3 -3
- package/dist/test-utils/factories/talkpilot/phone_numbers.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/phone_numbers.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/sessions.d.ts +2 -2
- package/dist/test-utils/factories/talkpilot/sessions.d.ts.map +1 -1
- package/dist/test-utils/factories/talkpilot/sessions.js +1 -1
- package/dist/utils/validation.js +2 -2
- package/dist/utils/validation.js.map +1 -1
- package/package.json +1 -3
- package/src/__tests__/setup.ts +3 -3
- package/src/connection.ts +25 -27
- package/src/index.ts +9 -9
- package/src/municipal/__tests__/validation.spec.ts +23 -35
- package/src/municipal/cities/cities.getters.ts +10 -16
- package/src/municipal/cities/cities.types.ts +1 -1
- package/src/municipal/cities/index.ts +2 -2
- package/src/municipal/departmentsSubjects/departmentsSubjects.getters.ts +44 -53
- package/src/municipal/departmentsSubjects/departmentsSubjects.types.ts +5 -5
- package/src/municipal/departmentsSubjects/index.ts +3 -2
- package/src/municipal/index.ts +10 -10
- package/src/municipal/mongodb-client.ts +26 -19
- package/src/municipal/streets/index.ts +2 -2
- package/src/municipal/streets/streets.getters.ts +23 -43
- package/src/municipal/streets/streets.types.ts +1 -1
- package/src/municipal/systemInstructions/__tests__/getters.spec.ts +52 -67
- package/src/municipal/systemInstructions/__tests__/setters.spec.ts +238 -271
- package/src/municipal/systemInstructions/index.ts +3 -7
- package/src/municipal/systemInstructions/instructions.getters.ts +18 -30
- package/src/municipal/systemInstructions/instructions.setters.ts +19 -43
- package/src/municipal/systemInstructions/instructions.types.ts +10 -10
- package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +12 -12
- package/src/municipal/tickets/index.ts +2 -2
- package/src/municipal/tickets/tickets.getters.ts +42 -69
- package/src/municipal/tickets/tickets.types.ts +2 -2
- package/src/municipal/utils/types.ts +3 -8
- package/src/talkpilot/__tests__/db.spec.ts +12 -12
- package/src/talkpilot/__tests__/mongodb-client.spec.ts +8 -7
- package/src/talkpilot/__tests__/validation.spec.ts +24 -30
- package/src/talkpilot/agents/__tests__/agents.getters.spec.ts +10 -10
- package/src/talkpilot/agents/agents.getters.ts +3 -3
- package/src/talkpilot/agents/agents.types.ts +2 -2
- package/src/talkpilot/agents/index.ts +2 -2
- package/src/talkpilot/backgroundToolResults/__tests__/backgroundToolResults.getters.spec.ts +31 -42
- package/src/talkpilot/backgroundToolResults/backgroundToolResults.getters.ts +11 -11
- package/src/talkpilot/backgroundToolResults/backgroundToolResults.types.ts +3 -2
- package/src/talkpilot/backgroundToolResults/index.ts +2 -2
- package/src/talkpilot/calls/__tests__/callStats.utils.spec.ts +27 -27
- package/src/talkpilot/calls/__tests__/calls.spec.ts +39 -79
- package/src/talkpilot/calls/calls.getters.ts +28 -48
- package/src/talkpilot/calls/calls.types.ts +16 -16
- package/src/talkpilot/calls/index.ts +2 -2
- package/src/talkpilot/clientAudioBuffers/__tests__/clientAudioBuffer.getters.spec.ts +39 -73
- package/src/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.ts +11 -18
- package/src/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.ts +2 -2
- package/src/talkpilot/clientAudioBuffers/index.ts +2 -2
- package/src/talkpilot/clients/clients.getters.ts +5 -10
- package/src/talkpilot/clients/clients.types.ts +1 -1
- package/src/talkpilot/clients/index.ts +2 -2
- package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +18 -21
- package/src/talkpilot/clientsConfig/clientsConfig.getters.ts +4 -6
- package/src/talkpilot/clientsConfig/clientsConfig.types.ts +8 -10
- package/src/talkpilot/clientsConfig/index.ts +2 -2
- package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +37 -38
- package/src/talkpilot/flows/flows.getter.ts +5 -8
- package/src/talkpilot/flows/flows.schema.ts +80 -87
- package/src/talkpilot/flows/flows.types.ts +24 -23
- package/src/talkpilot/flows/index.ts +2 -2
- package/src/talkpilot/groups/__tests__/groups.spec.ts +27 -34
- package/src/talkpilot/groups/__tests__/phone.utils.spec.ts +20 -20
- package/src/talkpilot/groups/groups.getters.ts +5 -8
- package/src/talkpilot/groups/groups.types.ts +1 -1
- package/src/talkpilot/groups/index.ts +3 -3
- package/src/talkpilot/groups/phone.utils.ts +6 -12
- package/src/talkpilot/index.ts +17 -17
- package/src/talkpilot/leads/index.ts +2 -2
- package/src/talkpilot/leads/leads.getter.ts +4 -5
- package/src/talkpilot/leads/leads.schema.ts +16 -16
- package/src/talkpilot/leads/leads.types.ts +1 -1
- package/src/talkpilot/mongodb-client.ts +33 -23
- package/src/talkpilot/phone_numbers/__tests__/phone_numbers.spec.ts +44 -84
- package/src/talkpilot/phone_numbers/index.ts +2 -2
- package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +22 -44
- package/src/talkpilot/phone_numbers/phone_numbers.schema.ts +9 -9
- package/src/talkpilot/phone_numbers/phone_numbers.types.ts +1 -1
- package/src/talkpilot/plans/__tests__/plans.spec.ts +26 -30
- package/src/talkpilot/plans/index.ts +2 -2
- package/src/talkpilot/plans/plans.getters.ts +18 -25
- package/src/talkpilot/plans/plans.types.ts +23 -27
- package/src/talkpilot/results/index.ts +2 -5
- package/src/talkpilot/results/results.getter.ts +8 -9
- package/src/talkpilot/results/results.schema.ts +18 -18
- package/src/talkpilot/results/results.types.ts +1 -1
- package/src/talkpilot/sessions/__tests__/sessions.spec.ts +41 -65
- package/src/talkpilot/sessions/index.ts +2 -2
- package/src/talkpilot/sessions/sessions.getter.ts +16 -21
- package/src/talkpilot/sessions/sessions.schema.ts +17 -17
- package/src/talkpilot/sessions/sessions.types.ts +2 -2
- package/src/talkpilot/subscriptions/__tests__/subscriptions.getters.utils.spec.ts +15 -18
- package/src/talkpilot/subscriptions/index.ts +3 -3
- package/src/talkpilot/subscriptions/subscriptions.getters.ts +33 -36
- package/src/talkpilot/subscriptions/subscriptions.getters.utils.ts +3 -10
- package/src/talkpilot/subscriptions/subscriptions.types.ts +9 -9
- package/src/talkpilot/utils/__tests__/query.utils.spec.ts +8 -8
- package/src/talkpilot/utils/query.utils.ts +2 -2
- package/src/test-utils/db-utils.ts +5 -5
- package/src/test-utils/factories/index.ts +12 -12
- package/src/test-utils/factories/municipal/cities.ts +5 -5
- package/src/test-utils/factories/municipal/departmentsSubjects.ts +25 -32
- package/src/test-utils/factories/municipal/streets.ts +5 -10
- package/src/test-utils/factories/municipal/tickets.ts +6 -12
- package/src/test-utils/factories/talkpilot/agents.ts +8 -8
- package/src/test-utils/factories/talkpilot/calls.ts +5 -5
- package/src/test-utils/factories/talkpilot/clientAudioBuffers.ts +12 -14
- package/src/test-utils/factories/talkpilot/clientsConfig.ts +8 -7
- package/src/test-utils/factories/talkpilot/flows.ts +5 -7
- package/src/test-utils/factories/talkpilot/groups.ts +13 -13
- package/src/test-utils/factories/talkpilot/phone_numbers.ts +6 -8
- package/src/test-utils/factories/talkpilot/sessions.ts +5 -5
- package/src/utils/validation.ts +4 -4
- 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
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { ObjectId } from
|
|
2
|
-
import { ObjectId as MongoObjectId } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
MIS_TOOLS,
|
|
6
|
-
QUERY_TYPES,
|
|
7
|
-
} from "./instructions.types";
|
|
8
|
-
import { getSystemInstructionsCollection } from "./instructions.getters";
|
|
1
|
+
import { ObjectId } from '../index';
|
|
2
|
+
import { ObjectId as MongoObjectId } from 'mongodb';
|
|
3
|
+
import { MIS_SystemInstruction, MIS_TOOLS, QUERY_TYPES } from './instructions.types';
|
|
4
|
+
import { getSystemInstructionsCollection } from './instructions.getters';
|
|
9
5
|
|
|
10
6
|
/**
|
|
11
7
|
* Validate system instruction data
|
|
@@ -13,21 +9,11 @@ import { getSystemInstructionsCollection } from "./instructions.getters";
|
|
|
13
9
|
* @throws Error if tool or queryType is invalid
|
|
14
10
|
*/
|
|
15
11
|
const validateInstructionData = (data: Partial<MIS_SystemInstruction>) => {
|
|
16
|
-
if (
|
|
17
|
-
data.tool
|
|
18
|
-
!(Object.values(MIS_TOOLS) as string[]).includes(data.tool)
|
|
19
|
-
) {
|
|
20
|
-
throw new Error(
|
|
21
|
-
`Invalid tool value: ${data.tool}. Allowed values are: ${Object.values(MIS_TOOLS).join(", ")}`,
|
|
22
|
-
);
|
|
12
|
+
if (data.tool && !(Object.values(MIS_TOOLS) as string[]).includes(data.tool)) {
|
|
13
|
+
throw new Error(`Invalid tool value: ${data.tool}. Allowed values are: ${Object.values(MIS_TOOLS).join(', ')}`);
|
|
23
14
|
}
|
|
24
|
-
if (
|
|
25
|
-
data.queryType
|
|
26
|
-
!(Object.values(QUERY_TYPES) as string[]).includes(data.queryType)
|
|
27
|
-
) {
|
|
28
|
-
throw new Error(
|
|
29
|
-
`Invalid queryType value: ${data.queryType}. Allowed values are: ${Object.values(QUERY_TYPES).join(", ")}`,
|
|
30
|
-
);
|
|
15
|
+
if (data.queryType && !(Object.values(QUERY_TYPES) as string[]).includes(data.queryType)) {
|
|
16
|
+
throw new Error(`Invalid queryType value: ${data.queryType}. Allowed values are: ${Object.values(QUERY_TYPES).join(', ')}`);
|
|
31
17
|
}
|
|
32
18
|
};
|
|
33
19
|
|
|
@@ -37,20 +23,16 @@ const validateInstructionData = (data: Partial<MIS_SystemInstruction>) => {
|
|
|
37
23
|
* @returns inserted system instruction id
|
|
38
24
|
*/
|
|
39
25
|
export const createSystemInstruction = async (
|
|
40
|
-
instructionData: Omit<
|
|
41
|
-
MIS_SystemInstruction,
|
|
42
|
-
"_id" | "createdAt" | "updatedAt"
|
|
43
|
-
>,
|
|
26
|
+
instructionData: Omit<MIS_SystemInstruction, '_id' | 'createdAt' | 'updatedAt'>
|
|
44
27
|
): Promise<MongoObjectId> => {
|
|
45
28
|
validateInstructionData(instructionData as Partial<MIS_SystemInstruction>);
|
|
46
|
-
const instruction: Omit<MIS_SystemInstruction,
|
|
47
|
-
//append doc metadata to user provided data
|
|
29
|
+
const instruction: Omit<MIS_SystemInstruction, '_id'> = { //append doc metadata to user provided data
|
|
48
30
|
...instructionData,
|
|
49
31
|
createdAt: new Date(),
|
|
50
32
|
updatedAt: new Date(),
|
|
51
33
|
};
|
|
52
34
|
const { insertedId } = await getSystemInstructionsCollection().insertOne(
|
|
53
|
-
instruction as MIS_SystemInstruction
|
|
35
|
+
instruction as MIS_SystemInstruction
|
|
54
36
|
);
|
|
55
37
|
return insertedId;
|
|
56
38
|
};
|
|
@@ -63,13 +45,13 @@ export const createSystemInstruction = async (
|
|
|
63
45
|
*/
|
|
64
46
|
export const updateSystemInstruction = async (
|
|
65
47
|
id: string,
|
|
66
|
-
data: Partial<Omit<MIS_SystemInstruction,
|
|
48
|
+
data: Partial<Omit<MIS_SystemInstruction, '_id' | 'createdAt' | 'updatedAt'>>
|
|
67
49
|
): Promise<MIS_SystemInstruction | null> => {
|
|
68
50
|
validateInstructionData(data as Partial<MIS_SystemInstruction>);
|
|
69
51
|
const result = await getSystemInstructionsCollection().findOneAndUpdate(
|
|
70
52
|
{ _id: new ObjectId(id) },
|
|
71
53
|
{ $set: { ...data, updatedAt: new Date() } },
|
|
72
|
-
{ returnDocument:
|
|
54
|
+
{ returnDocument: 'after' }
|
|
73
55
|
);
|
|
74
56
|
return result || null;
|
|
75
57
|
};
|
|
@@ -80,9 +62,7 @@ export const updateSystemInstruction = async (
|
|
|
80
62
|
* @returns true if deleted, false otherwise
|
|
81
63
|
*/
|
|
82
64
|
export const deleteSystemInstruction = async (id: string): Promise<boolean> => {
|
|
83
|
-
const result = await getSystemInstructionsCollection().deleteOne({
|
|
84
|
-
_id: new ObjectId(id),
|
|
85
|
-
});
|
|
65
|
+
const result = await getSystemInstructionsCollection().deleteOne({ _id: new ObjectId(id) });
|
|
86
66
|
return result.deletedCount > 0;
|
|
87
67
|
};
|
|
88
68
|
/**
|
|
@@ -91,13 +71,11 @@ export const deleteSystemInstruction = async (id: string): Promise<boolean> => {
|
|
|
91
71
|
* @param id system instruction id
|
|
92
72
|
* @returns true on success, false otherwise
|
|
93
73
|
*/
|
|
94
|
-
export const activateSystemInstruction = async (
|
|
95
|
-
id: string,
|
|
96
|
-
): Promise<boolean> => {
|
|
74
|
+
export const activateSystemInstruction = async (id: string): Promise<boolean> => {
|
|
97
75
|
const result = await getSystemInstructionsCollection().findOneAndUpdate(
|
|
98
76
|
{ _id: new ObjectId(id) },
|
|
99
77
|
{ $set: { isActive: true } },
|
|
100
|
-
{ returnDocument:
|
|
78
|
+
{ returnDocument: 'after' }
|
|
101
79
|
);
|
|
102
80
|
return Boolean(result);
|
|
103
81
|
};
|
|
@@ -107,13 +85,11 @@ export const activateSystemInstruction = async (
|
|
|
107
85
|
* @param id system instruction id
|
|
108
86
|
* @returns true on success, false otherwise
|
|
109
87
|
*/
|
|
110
|
-
export const deactivateSystemInstruction = async (
|
|
111
|
-
id: string,
|
|
112
|
-
): Promise<boolean> => {
|
|
88
|
+
export const deactivateSystemInstruction = async (id: string): Promise<boolean> => {
|
|
113
89
|
const result = await getSystemInstructionsCollection().findOneAndUpdate(
|
|
114
90
|
{ _id: new ObjectId(id) },
|
|
115
91
|
{ $set: { isActive: false } },
|
|
116
|
-
|
|
92
|
+
{returnDocument: 'after'}
|
|
117
93
|
);
|
|
118
94
|
return Boolean(result);
|
|
119
|
-
}
|
|
95
|
+
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { ObjectId } from
|
|
1
|
+
import { ObjectId } from 'mongodb';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {CityName} from "../utils/types";
|
|
4
4
|
|
|
5
5
|
export const MIS_TOOLS = {
|
|
6
|
-
findStreet:
|
|
7
|
-
findSubject:
|
|
6
|
+
findStreet: 'findStreet',
|
|
7
|
+
findSubject: 'findSubject'
|
|
8
8
|
} as const;
|
|
9
9
|
|
|
10
10
|
export const QUERY_TYPES = {
|
|
11
|
-
exactlyOne:
|
|
12
|
-
any:
|
|
13
|
-
all:
|
|
14
|
-
none:
|
|
11
|
+
exactlyOne: 'exactlyOne',
|
|
12
|
+
any: 'any',
|
|
13
|
+
all: 'all',
|
|
14
|
+
none: 'none'
|
|
15
15
|
} as const;
|
|
16
16
|
|
|
17
|
-
export type MIS_Tool =
|
|
18
|
-
export type QueryType =
|
|
17
|
+
export type MIS_Tool = typeof MIS_TOOLS[keyof typeof MIS_TOOLS];
|
|
18
|
+
export type QueryType = typeof QUERY_TYPES[keyof typeof QUERY_TYPES];
|
|
19
19
|
|
|
20
20
|
export type MIS_SystemInstruction = {
|
|
21
21
|
_id: ObjectId;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { findTicketsByCallSid } from
|
|
2
|
-
import { setDb } from
|
|
3
|
-
import { Db, Collection } from
|
|
4
|
-
import { createTicket } from
|
|
1
|
+
import { findTicketsByCallSid } from '../tickets.getters';
|
|
2
|
+
import { setDb } from '../../index';
|
|
3
|
+
import { Db, Collection } from 'mongodb';
|
|
4
|
+
import { createTicket } from '../../../test-utils/factories';
|
|
5
5
|
|
|
6
|
-
describe(
|
|
6
|
+
describe('tickets getters', () => {
|
|
7
7
|
let mockDb: Partial<Db>;
|
|
8
8
|
let mockCollection: Partial<Collection>;
|
|
9
9
|
|
|
10
10
|
beforeEach(() => {
|
|
11
|
-
const mockTicket = createTicket({ callSid:
|
|
11
|
+
const mockTicket = createTicket({ callSid: '123' });
|
|
12
12
|
mockCollection = {
|
|
13
13
|
find: jest.fn().mockReturnValue({
|
|
14
14
|
toArray: jest.fn().mockResolvedValue([mockTicket]),
|
|
@@ -20,11 +20,11 @@ describe("tickets getters", () => {
|
|
|
20
20
|
setDb(mockDb as Db);
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
it(
|
|
24
|
-
const result = await findTicketsByCallSid(
|
|
25
|
-
|
|
26
|
-
expect(mockDb.collection).toHaveBeenCalledWith(
|
|
27
|
-
expect(mockCollection.find).toHaveBeenCalledWith({ callSid:
|
|
28
|
-
expect(result[0].callSid).toBe(
|
|
23
|
+
it('findTicketsByCallSid should return tickets for the given callSid', async () => {
|
|
24
|
+
const result = await findTicketsByCallSid('123');
|
|
25
|
+
|
|
26
|
+
expect(mockDb.collection).toHaveBeenCalledWith('tickets');
|
|
27
|
+
expect(mockCollection.find).toHaveBeenCalledWith({ callSid: '123' });
|
|
28
|
+
expect(result[0].callSid).toBe('123');
|
|
29
29
|
});
|
|
30
30
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export type { Ticket, TicketDoc, SubjectStatsItem } from
|
|
1
|
+
export * from './tickets.getters';
|
|
2
|
+
export type { Ticket, TicketDoc, SubjectStatsItem } from './tickets.types';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { SubjectStatsItem } from
|
|
3
|
-
import { Collection, Filter, ObjectId as MongoObjectId } from
|
|
1
|
+
import {CityName, getDb, ObjectId, Ticket} from '../index';
|
|
2
|
+
import type { SubjectStatsItem } from './tickets.types';
|
|
3
|
+
import { Collection, Filter, ObjectId as MongoObjectId } from 'mongodb';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Generate a new ticket ID as a string
|
|
@@ -11,33 +11,25 @@ export const generateTicketId = (): string => {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export const getTicketsCollection = (): Collection<Ticket> => {
|
|
14
|
-
return getDb().collection<Ticket>(
|
|
14
|
+
return getDb().collection<Ticket>('tickets');
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
export const findTickets = async (
|
|
18
|
-
filter: Filter<Ticket> = {},
|
|
19
|
-
): Promise<Ticket[]> => {
|
|
17
|
+
export const findTickets = async (filter: Filter<Ticket> = {}): Promise<Ticket[]> => {
|
|
20
18
|
return await getTicketsCollection().find(filter).toArray();
|
|
21
19
|
};
|
|
22
20
|
|
|
23
|
-
export const findTicketsByCallSid = async (
|
|
24
|
-
callSid: string,
|
|
25
|
-
): Promise<Ticket[]> => {
|
|
21
|
+
export const findTicketsByCallSid = async (callSid: string): Promise<Ticket[]> => {
|
|
26
22
|
return await getTicketsCollection().find({ callSid }).toArray();
|
|
27
23
|
};
|
|
28
24
|
|
|
29
|
-
export const getTicketById = async (
|
|
30
|
-
|
|
31
|
-
): Promise<Ticket | null> => {
|
|
32
|
-
const ticket = await getTicketsCollection().findOne({
|
|
33
|
-
_id: new ObjectId(ticketId),
|
|
34
|
-
});
|
|
25
|
+
export const getTicketById = async (ticketId: string): Promise<Ticket | null> => {
|
|
26
|
+
const ticket = await getTicketsCollection().findOne({ _id: new ObjectId(ticketId) });
|
|
35
27
|
return ticket ? ticket : null;
|
|
36
28
|
};
|
|
37
29
|
|
|
38
30
|
export const createTicket = async (
|
|
39
|
-
ticketData: Omit<Ticket,
|
|
40
|
-
ticketId?: string
|
|
31
|
+
ticketData: Omit<Ticket, '_id' | 'createdAt' | 'updatedAt'>,
|
|
32
|
+
ticketId?: string
|
|
41
33
|
): Promise<MongoObjectId> => {
|
|
42
34
|
const ticket: Ticket = {
|
|
43
35
|
_id: ticketId ? new ObjectId(ticketId) : new ObjectId(),
|
|
@@ -51,20 +43,18 @@ export const createTicket = async (
|
|
|
51
43
|
|
|
52
44
|
export const updateTicket = async (
|
|
53
45
|
ticketId: string,
|
|
54
|
-
data: Partial<Omit<Ticket,
|
|
46
|
+
data: Partial<Omit<Ticket, '_id' | 'createdAt' | 'updatedAt'>>
|
|
55
47
|
): Promise<Ticket | null> => {
|
|
56
48
|
const result = await getTicketsCollection().findOneAndUpdate(
|
|
57
49
|
{ _id: new ObjectId(ticketId) },
|
|
58
50
|
{ $set: { ...data, updatedAt: new Date() } },
|
|
59
|
-
{ returnDocument:
|
|
51
|
+
{ returnDocument: 'after' }
|
|
60
52
|
);
|
|
61
53
|
return result || null;
|
|
62
54
|
};
|
|
63
55
|
|
|
64
56
|
export const deleteTicket = async (ticketId: string): Promise<boolean> => {
|
|
65
|
-
const result = await getTicketsCollection().deleteOne({
|
|
66
|
-
_id: new ObjectId(ticketId),
|
|
67
|
-
});
|
|
57
|
+
const result = await getTicketsCollection().deleteOne({ _id: new ObjectId(ticketId) });
|
|
68
58
|
return result.deletedCount > 0;
|
|
69
59
|
};
|
|
70
60
|
|
|
@@ -76,7 +66,7 @@ export async function getTicketsCountByCityAndDateRange(
|
|
|
76
66
|
cityName: string,
|
|
77
67
|
startStr: string,
|
|
78
68
|
endStr: string,
|
|
79
|
-
timezone: string
|
|
69
|
+
timezone: string
|
|
80
70
|
): Promise<number> {
|
|
81
71
|
const doc = await getTicketsCollection()
|
|
82
72
|
.aggregate<{ n: number }>([
|
|
@@ -84,12 +74,12 @@ export async function getTicketsCountByCityAndDateRange(
|
|
|
84
74
|
{
|
|
85
75
|
$addFields: {
|
|
86
76
|
dateLocal: {
|
|
87
|
-
$dateToString: { format:
|
|
77
|
+
$dateToString: { format: '%Y-%m-%d', date: '$createdAt', timezone },
|
|
88
78
|
},
|
|
89
79
|
},
|
|
90
80
|
},
|
|
91
81
|
{ $match: { dateLocal: { $gte: startStr, $lte: endStr } } },
|
|
92
|
-
{ $count:
|
|
82
|
+
{ $count: 'n' },
|
|
93
83
|
])
|
|
94
84
|
.next();
|
|
95
85
|
return doc?.n ?? 0;
|
|
@@ -103,7 +93,7 @@ export async function getTicketsSubjectStats(
|
|
|
103
93
|
cityName: string,
|
|
104
94
|
startStr: string,
|
|
105
95
|
endStr: string,
|
|
106
|
-
timezone: string
|
|
96
|
+
timezone: string
|
|
107
97
|
): Promise<SubjectStatsItem[]> {
|
|
108
98
|
const coll = getTicketsCollection();
|
|
109
99
|
const rows = await coll
|
|
@@ -112,7 +102,7 @@ export async function getTicketsSubjectStats(
|
|
|
112
102
|
{
|
|
113
103
|
$addFields: {
|
|
114
104
|
dateLocal: {
|
|
115
|
-
$dateToString: { format:
|
|
105
|
+
$dateToString: { format: '%Y-%m-%d', date: '$createdAt', timezone },
|
|
116
106
|
},
|
|
117
107
|
},
|
|
118
108
|
},
|
|
@@ -121,11 +111,11 @@ export async function getTicketsSubjectStats(
|
|
|
121
111
|
$addFields: {
|
|
122
112
|
effectiveSubjectId: {
|
|
123
113
|
$ifNull: [
|
|
124
|
-
|
|
114
|
+
'$externalCallFields.event_subject_id',
|
|
125
115
|
{
|
|
126
116
|
$ifNull: [
|
|
127
|
-
|
|
128
|
-
|
|
117
|
+
'$externalCallFields.event_sub_subject_id',
|
|
118
|
+
'$externalCallFields.event_sub_subject_id2',
|
|
129
119
|
],
|
|
130
120
|
},
|
|
131
121
|
],
|
|
@@ -134,23 +124,19 @@ export async function getTicketsSubjectStats(
|
|
|
134
124
|
},
|
|
135
125
|
{
|
|
136
126
|
$lookup: {
|
|
137
|
-
from:
|
|
138
|
-
let: { sid:
|
|
127
|
+
from: 'departmentsSubjects',
|
|
128
|
+
let: { sid: '$effectiveSubjectId', c: cityName },
|
|
139
129
|
pipeline: [
|
|
140
130
|
{
|
|
141
131
|
$match: {
|
|
142
132
|
$expr: {
|
|
143
133
|
$and: [
|
|
144
|
-
{ $eq: [
|
|
134
|
+
{ $eq: ['$cityName', '$$c'] },
|
|
145
135
|
{
|
|
146
136
|
$or: [
|
|
147
|
-
{ $eq: [
|
|
148
|
-
{
|
|
149
|
-
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
$eq: ["$sub_subject_id2", { $ifNull: ["$$sid", ""] }],
|
|
153
|
-
},
|
|
137
|
+
{ $eq: ['$subject_id', { $ifNull: ['$$sid', ''] }] },
|
|
138
|
+
{ $eq: ['$sub_subject_id', { $ifNull: ['$$sid', ''] }] },
|
|
139
|
+
{ $eq: ['$sub_subject_id2', { $ifNull: ['$$sid', ''] }] },
|
|
154
140
|
],
|
|
155
141
|
},
|
|
156
142
|
],
|
|
@@ -159,41 +145,28 @@ export async function getTicketsSubjectStats(
|
|
|
159
145
|
},
|
|
160
146
|
{ $limit: 1 },
|
|
161
147
|
],
|
|
162
|
-
as:
|
|
148
|
+
as: 'subj',
|
|
163
149
|
},
|
|
164
150
|
},
|
|
165
151
|
{
|
|
166
152
|
$addFields: {
|
|
167
153
|
subject_id: {
|
|
168
154
|
$cond: {
|
|
169
|
-
if: { $gt: [{ $size:
|
|
170
|
-
then: {
|
|
171
|
-
|
|
172
|
-
},
|
|
173
|
-
else: "",
|
|
155
|
+
if: { $gt: [{ $size: '$subj' }, 0] },
|
|
156
|
+
then: { $ifNull: [{ $arrayElemAt: ['$subj.subject_id', 0] }, ''] },
|
|
157
|
+
else: '',
|
|
174
158
|
},
|
|
175
159
|
},
|
|
176
160
|
subject: {
|
|
177
161
|
$cond: {
|
|
178
|
-
if: { $gt: [{ $size:
|
|
179
|
-
then: {
|
|
180
|
-
|
|
181
|
-
{ $arrayElemAt: ["$subj.subjectName", 0] },
|
|
182
|
-
"Unclassified",
|
|
183
|
-
],
|
|
184
|
-
},
|
|
185
|
-
else: "Unclassified",
|
|
162
|
+
if: { $gt: [{ $size: '$subj' }, 0] },
|
|
163
|
+
then: { $ifNull: [{ $arrayElemAt: ['$subj.subjectName', 0] }, 'Unclassified'] },
|
|
164
|
+
else: 'Unclassified',
|
|
186
165
|
},
|
|
187
166
|
},
|
|
188
167
|
},
|
|
189
168
|
},
|
|
190
|
-
{
|
|
191
|
-
$group: {
|
|
192
|
-
_id: "$subject_id",
|
|
193
|
-
subject: { $first: "$subject" },
|
|
194
|
-
count: { $sum: 1 },
|
|
195
|
-
},
|
|
196
|
-
},
|
|
169
|
+
{ $group: { _id: '$subject_id', subject: { $first: '$subject' }, count: { $sum: 1 } } },
|
|
197
170
|
{ $sort: { count: -1 } },
|
|
198
171
|
])
|
|
199
172
|
.toArray();
|
|
@@ -223,21 +196,21 @@ export const updateTicketFilesByCallNumber = async (params: {
|
|
|
223
196
|
const { cityName, callNumber, image1, image2, image3 } = params;
|
|
224
197
|
|
|
225
198
|
const update: any = {};
|
|
226
|
-
if (image1) update[
|
|
227
|
-
if (image2) update[
|
|
228
|
-
if (image3) update[
|
|
199
|
+
if (image1) update['externalCallFields.image1'] = image1;
|
|
200
|
+
if (image2) update['externalCallFields.image2'] = image2;
|
|
201
|
+
if (image3) update['externalCallFields.image3'] = image3;
|
|
229
202
|
|
|
230
203
|
const result = await getTicketsCollection().updateOne(
|
|
231
204
|
{
|
|
232
205
|
cityName: cityName,
|
|
233
|
-
|
|
206
|
+
'externalCallFields.call_number': callNumber,
|
|
234
207
|
},
|
|
235
208
|
{
|
|
236
209
|
$set: {
|
|
237
210
|
...update,
|
|
238
211
|
updatedAt: new Date(),
|
|
239
212
|
},
|
|
240
|
-
}
|
|
213
|
+
}
|
|
241
214
|
);
|
|
242
215
|
|
|
243
216
|
return result.matchedCount > 0;
|
|
@@ -253,8 +226,8 @@ export const clearGuestJwtByCallNumber = async (params: {
|
|
|
253
226
|
const { cityName, callNumber } = params;
|
|
254
227
|
|
|
255
228
|
const result = await getTicketsCollection().updateOne(
|
|
256
|
-
{ cityName,
|
|
257
|
-
{ $unset: { guestJwt:
|
|
229
|
+
{ cityName, 'externalCallFields.call_number': callNumber },
|
|
230
|
+
{ $unset: { guestJwt: '' }, $set: { updatedAt: new Date() } }
|
|
258
231
|
);
|
|
259
232
|
|
|
260
233
|
return result.matchedCount > 0;
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* City name type for municipal data
|
|
3
5
|
*/
|
|
4
|
-
export type CityName =
|
|
5
|
-
| "ashdod"
|
|
6
|
-
| "maltar"
|
|
7
|
-
| "billit"
|
|
8
|
-
| "hashkelon"
|
|
9
|
-
| "eilat"
|
|
10
|
-
| "tests"
|
|
11
|
-
| string;
|
|
6
|
+
export type CityName = 'ashdod' | 'maltar' | 'billit' | 'hashkelon' | 'eilat' | 'tests' | string;
|
|
@@ -8,25 +8,25 @@ import {
|
|
|
8
8
|
ObjectId,
|
|
9
9
|
getPlansCollection,
|
|
10
10
|
getSubscriptionsCollection,
|
|
11
|
-
} from
|
|
11
|
+
} from '../index';
|
|
12
12
|
|
|
13
|
-
import { ObjectId as MongoObjectId } from
|
|
13
|
+
import { ObjectId as MongoObjectId } from 'mongodb';
|
|
14
14
|
|
|
15
|
-
describe(
|
|
15
|
+
describe('talkpilot core/db', () => {
|
|
16
16
|
it.each([
|
|
17
|
-
[
|
|
18
|
-
[
|
|
19
|
-
[
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
24
|
-
[
|
|
17
|
+
['flows', getFlowsCollection],
|
|
18
|
+
['sessions', getSessionsCollection],
|
|
19
|
+
['results', getResultsCollection],
|
|
20
|
+
['leads', getLeadsCollection],
|
|
21
|
+
['phone_numbers', getPhoneNumbersCollection],
|
|
22
|
+
['clients', getClientsCollection],
|
|
23
|
+
['plans', getPlansCollection],
|
|
24
|
+
['subscriptions', getSubscriptionsCollection],
|
|
25
25
|
])('%s collection helper returns a "%s" collection', (name, getter) => {
|
|
26
26
|
expect(getter().collectionName).toBe(name);
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
it(
|
|
29
|
+
it('ObjectId re-export behaves like mongodb.ObjectId', () => {
|
|
30
30
|
expect(ObjectId).toBe(MongoObjectId);
|
|
31
31
|
|
|
32
32
|
const id = new ObjectId();
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mongodbClient } from '../mongodb-client';
|
|
2
|
+
import { getDb } from '../index';
|
|
2
3
|
|
|
3
|
-
describe(
|
|
4
|
-
it(
|
|
4
|
+
describe('MongoDBClient', () => {
|
|
5
|
+
it('should have a connected database instance from global setup', () => {
|
|
5
6
|
const db = getDb();
|
|
6
7
|
expect(db).toBeDefined();
|
|
7
|
-
expect(db.databaseName).toBe(
|
|
8
|
+
expect(db.databaseName).toBe('test'); // Based on our setup.ts
|
|
8
9
|
});
|
|
9
10
|
|
|
10
|
-
it(
|
|
11
|
+
it('should report as connected', async () => {
|
|
11
12
|
// Note: mongodbClient.connect() was called in global setup
|
|
12
13
|
// but through setDb, not necessarily through the client singleton instance
|
|
13
14
|
// since initTestDb calls setDb directly.
|
|
14
|
-
|
|
15
|
+
|
|
15
16
|
// In a real scenario, you'd use the client.
|
|
16
|
-
expect(true).toBe(true);
|
|
17
|
+
expect(true).toBe(true);
|
|
17
18
|
});
|
|
18
19
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { mongodbClient } from
|
|
2
|
-
import { MongoClient } from
|
|
1
|
+
import { mongodbClient } from '../mongodb-client';
|
|
2
|
+
import { MongoClient } from 'mongodb';
|
|
3
3
|
|
|
4
|
-
describe(
|
|
4
|
+
describe('MongoDBClient Validation', () => {
|
|
5
5
|
const originalEnv = process.env;
|
|
6
6
|
|
|
7
7
|
beforeEach(() => {
|
|
@@ -9,7 +9,7 @@ describe("MongoDBClient Validation", () => {
|
|
|
9
9
|
delete process.env.MONGO_URI;
|
|
10
10
|
delete process.env.MONGODB_URI;
|
|
11
11
|
delete process.env.MONGODB_DB_NAME;
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
// Force reset singleton state
|
|
14
14
|
(mongodbClient as any).client = null;
|
|
15
15
|
(mongodbClient as any).db = null;
|
|
@@ -21,47 +21,41 @@ describe("MongoDBClient Validation", () => {
|
|
|
21
21
|
await mongodbClient.disconnect();
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
it(
|
|
24
|
+
it('should throw error if no URI is provided', async () => {
|
|
25
25
|
await expect(mongodbClient.connect()).rejects.toThrow(
|
|
26
|
-
"[core-db] Configuration Error: 'MONGO_URI' is missing"
|
|
26
|
+
"[core-db] Configuration Error: 'MONGO_URI' is missing"
|
|
27
27
|
);
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
it(
|
|
31
|
-
await expect(mongodbClient.connect(
|
|
32
|
-
"[core-db] Connection Error: The provided MongoDB URI is invalid"
|
|
30
|
+
it('should throw error if an invalid URI format is provided', async () => {
|
|
31
|
+
await expect(mongodbClient.connect('not-a-mongo-uri')).rejects.toThrow(
|
|
32
|
+
"[core-db] Connection Error: The provided MongoDB URI is invalid"
|
|
33
33
|
);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
it(
|
|
36
|
+
it('should throw error if URI is valid but database name is missing', async () => {
|
|
37
37
|
// We mock the actual MongoClient connection so it doesn't try to hit a real network
|
|
38
|
-
const connectSpy = jest
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const uriWithoutDb = "mongodb://127.0.0.1:27017";
|
|
38
|
+
const connectSpy = jest.spyOn(MongoClient.prototype, 'connect').mockResolvedValue({} as any);
|
|
39
|
+
|
|
40
|
+
const uriWithoutDb = 'mongodb://127.0.0.1:27017';
|
|
43
41
|
await expect(mongodbClient.connect(uriWithoutDb)).rejects.toThrow(
|
|
44
|
-
"[core-db] Database name not specified"
|
|
42
|
+
"[core-db] Database name not specified"
|
|
45
43
|
);
|
|
46
|
-
|
|
44
|
+
|
|
47
45
|
connectSpy.mockRestore();
|
|
48
46
|
});
|
|
49
47
|
|
|
50
|
-
it(
|
|
51
|
-
const mockDb = { databaseName:
|
|
52
|
-
const connectSpy = jest
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
.spyOn(MongoClient.prototype, "db")
|
|
57
|
-
.mockReturnValue(mockDb as any);
|
|
58
|
-
|
|
59
|
-
const validUri = "mongodb://127.0.0.1:27017/my-db";
|
|
48
|
+
it('should succeed when valid URI and DB name are provided', async () => {
|
|
49
|
+
const mockDb = { databaseName: 'my-db' };
|
|
50
|
+
const connectSpy = jest.spyOn(MongoClient.prototype, 'connect').mockResolvedValue({} as any);
|
|
51
|
+
const dbSpy = jest.spyOn(MongoClient.prototype, 'db').mockReturnValue(mockDb as any);
|
|
52
|
+
|
|
53
|
+
const validUri = 'mongodb://127.0.0.1:27017/my-db';
|
|
60
54
|
await mongodbClient.connect(validUri);
|
|
61
|
-
|
|
55
|
+
|
|
62
56
|
expect(mongodbClient.getDb()).toBeDefined();
|
|
63
|
-
expect(mongodbClient.getDb().databaseName).toBe(
|
|
64
|
-
|
|
57
|
+
expect(mongodbClient.getDb().databaseName).toBe('my-db');
|
|
58
|
+
|
|
65
59
|
connectSpy.mockRestore();
|
|
66
60
|
dbSpy.mockRestore();
|
|
67
61
|
});
|