@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,52 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import { ObjectId } from "mongodb";
|
|
14
|
-
|
|
15
|
-
describe("sessions", () => {
|
|
16
|
-
describe("findSessionOfIncomingCall()", () => {
|
|
17
|
-
it("returns session by incoming phone number", async () => {
|
|
18
|
-
const to = "+972500000000";
|
|
19
|
-
const from = "+972540000000";
|
|
1
|
+
import { findSessionOfIncomingCall, getSessionsCollection } from '../sessions.getter';
|
|
2
|
+
import { getFlowsCollection } from '../../flows/flows.getter';
|
|
3
|
+
import { getPhoneNumbersCollection } from '../../phone_numbers/phone_numbers.getter';
|
|
4
|
+
import { createFlow, createPhoneNumber, createSession } from '../../../test-utils/factories';
|
|
5
|
+
import { faker } from '@faker-js/faker';
|
|
6
|
+
import { ObjectId } from 'mongodb';
|
|
7
|
+
|
|
8
|
+
describe('sessions', () => {
|
|
9
|
+
describe('findSessionOfIncomingCall()', () => {
|
|
10
|
+
it('returns session by incoming phone number', async () => {
|
|
11
|
+
const to = '+972500000000';
|
|
12
|
+
const from = '+972540000000';
|
|
20
13
|
const flow = createFlow({
|
|
21
14
|
conversationSettings: {
|
|
22
15
|
interruptions: {
|
|
23
16
|
enableInterruptionDetection: true,
|
|
24
17
|
interruptionWindowSeconds: 60,
|
|
25
18
|
interruptionThresholdSeconds: 10,
|
|
26
|
-
interruptionInstruction:
|
|
27
|
-
"I am hearing background noise that makes it hard for me to focus on what you are saying. Please try to move to a quieter place or reduce the noise so I can better assist you.",
|
|
19
|
+
interruptionInstruction: 'I am hearing background noise that makes it hard for me to focus on what you are saying. Please try to move to a quieter place or reduce the noise so I can better assist you.',
|
|
28
20
|
},
|
|
29
21
|
silence: {
|
|
30
22
|
enableSilenceDetection: true,
|
|
31
23
|
firstWarningSilenceSeconds: 5,
|
|
32
|
-
firstWarningInstruction:
|
|
33
|
-
"I have not heard you for a few seconds. If you are still on the line, please say something so we can continue.",
|
|
24
|
+
firstWarningInstruction: 'I have not heard you for a few seconds. If you are still on the line, please say something so we can continue.',
|
|
34
25
|
secondWarningSilenceSeconds: 10,
|
|
35
|
-
secondWarningInstruction:
|
|
36
|
-
"I still have not heard anything from you. If you do not respond in the next few seconds, I will have to end this call.",
|
|
26
|
+
secondWarningInstruction: 'I still have not heard anything from you. If you do not respond in the next few seconds, I will have to end this call.',
|
|
37
27
|
disconnectSilenceSeconds: 30,
|
|
38
28
|
},
|
|
39
29
|
},
|
|
40
30
|
});
|
|
41
|
-
const phoneNumberData = createPhoneNumber({
|
|
42
|
-
phone_number: to,
|
|
43
|
-
flow_id: flow._id,
|
|
44
|
-
});
|
|
31
|
+
const phoneNumberData = createPhoneNumber({ phone_number: to, flow_id: flow._id });
|
|
45
32
|
const json = { [faker.lorem.word()]: faker.lorem.sentence() };
|
|
46
33
|
|
|
47
34
|
const session = createSession({
|
|
48
35
|
flow_id: flow._id,
|
|
49
|
-
phone_numbers: [{ phoneNumber: from, gender:
|
|
36
|
+
phone_numbers: [{ phoneNumber: from, gender: 'male', name: 'yakov' }],
|
|
50
37
|
json,
|
|
51
38
|
});
|
|
52
39
|
|
|
@@ -60,20 +47,15 @@ describe("sessions", () => {
|
|
|
60
47
|
expect(result?.flow_id).toEqual(flow._id);
|
|
61
48
|
});
|
|
62
49
|
|
|
63
|
-
it(
|
|
64
|
-
const toInDB =
|
|
65
|
-
const fromInDB =
|
|
50
|
+
it('works with different phone number formats (with/without plus)', async () => {
|
|
51
|
+
const toInDB = '972500000000';
|
|
52
|
+
const fromInDB = '+972540000000';
|
|
66
53
|
const flow = createFlow();
|
|
67
|
-
const phoneNumberData = createPhoneNumber({
|
|
68
|
-
phone_number: toInDB,
|
|
69
|
-
flow_id: flow._id,
|
|
70
|
-
});
|
|
54
|
+
const phoneNumberData = createPhoneNumber({ phone_number: toInDB, flow_id: flow._id });
|
|
71
55
|
|
|
72
56
|
const session = createSession({
|
|
73
57
|
flow_id: flow._id,
|
|
74
|
-
phone_numbers: [
|
|
75
|
-
{ phoneNumber: fromInDB, gender: "female", name: "sara" },
|
|
76
|
-
],
|
|
58
|
+
phone_numbers: [{ phoneNumber: fromInDB, gender: 'female', name: 'sara' }],
|
|
77
59
|
});
|
|
78
60
|
|
|
79
61
|
await getFlowsCollection().insertOne(flow);
|
|
@@ -81,28 +63,25 @@ describe("sessions", () => {
|
|
|
81
63
|
await getSessionsCollection().insertOne(session);
|
|
82
64
|
|
|
83
65
|
// Search with from WITH plus (matches + in DB), to WITH plus (matches without + in DB)
|
|
84
|
-
const result = await findSessionOfIncomingCall(
|
|
85
|
-
"+972540000000",
|
|
86
|
-
"+972500000000",
|
|
87
|
-
);
|
|
66
|
+
const result = await findSessionOfIncomingCall('+972540000000', '+972500000000');
|
|
88
67
|
expect(result).not.toBeNull();
|
|
89
68
|
expect(result?.phone_numbers[0].phoneNumber).toEqual(fromInDB);
|
|
90
69
|
});
|
|
91
70
|
|
|
92
|
-
it(
|
|
93
|
-
const to =
|
|
94
|
-
const from =
|
|
71
|
+
it('works when flow_id is string in phone_numbers and ObjectId in session', async () => {
|
|
72
|
+
const to = '+972501111111';
|
|
73
|
+
const from = '+972541111111';
|
|
95
74
|
const flowId = new ObjectId();
|
|
96
|
-
|
|
75
|
+
|
|
97
76
|
// Store flow_id as string in phone_numbers
|
|
98
|
-
const phoneNumberData = createPhoneNumber({
|
|
99
|
-
phone_number: to,
|
|
100
|
-
flow_id: flowId.toHexString() as any
|
|
77
|
+
const phoneNumberData = createPhoneNumber({
|
|
78
|
+
phone_number: to,
|
|
79
|
+
flow_id: flowId.toHexString() as any
|
|
101
80
|
});
|
|
102
81
|
|
|
103
82
|
const session = createSession({
|
|
104
83
|
flow_id: flowId, // stored as ObjectId
|
|
105
|
-
phone_numbers: [{ phoneNumber: from, gender:
|
|
84
|
+
phone_numbers: [{ phoneNumber: from, gender: 'male', name: 'isaac' }],
|
|
106
85
|
});
|
|
107
86
|
|
|
108
87
|
await getPhoneNumbersCollection().insertOne(phoneNumberData);
|
|
@@ -113,19 +92,19 @@ describe("sessions", () => {
|
|
|
113
92
|
expect(result?.flow_id?.toString()).toEqual(flowId.toHexString());
|
|
114
93
|
});
|
|
115
94
|
|
|
116
|
-
it(
|
|
117
|
-
const to =
|
|
118
|
-
const from =
|
|
95
|
+
it('works when flow_id is string in session', async () => {
|
|
96
|
+
const to = '+972502222222';
|
|
97
|
+
const from = '+972542222222';
|
|
119
98
|
const flowId = new ObjectId();
|
|
120
|
-
|
|
121
|
-
const phoneNumberData = createPhoneNumber({
|
|
122
|
-
phone_number: to,
|
|
123
|
-
flow_id: flowId
|
|
99
|
+
|
|
100
|
+
const phoneNumberData = createPhoneNumber({
|
|
101
|
+
phone_number: to,
|
|
102
|
+
flow_id: flowId
|
|
124
103
|
});
|
|
125
104
|
|
|
126
105
|
const session = createSession({
|
|
127
106
|
flow_id: flowId.toHexString(), // stored as string
|
|
128
|
-
phone_numbers: [{ phoneNumber: from, gender:
|
|
107
|
+
phone_numbers: [{ phoneNumber: from, gender: 'female', name: 'rivka' }],
|
|
129
108
|
});
|
|
130
109
|
|
|
131
110
|
await getPhoneNumbersCollection().insertOne(phoneNumberData);
|
|
@@ -136,11 +115,8 @@ describe("sessions", () => {
|
|
|
136
115
|
expect(result?.flow_id).toEqual(flowId.toHexString());
|
|
137
116
|
});
|
|
138
117
|
|
|
139
|
-
it(
|
|
140
|
-
const result = await findSessionOfIncomingCall(
|
|
141
|
-
"any-from",
|
|
142
|
-
"non-existent-to",
|
|
143
|
-
);
|
|
118
|
+
it('returns null if receiver phone number is not found', async () => {
|
|
119
|
+
const result = await findSessionOfIncomingCall('any-from', 'non-existent-to');
|
|
144
120
|
expect(result).toBeNull();
|
|
145
121
|
});
|
|
146
122
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './sessions.getter';
|
|
2
|
+
export * from './sessions.types';
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import { ObjectId } from
|
|
2
|
-
import type { Collection, WithId } from
|
|
3
|
-
import { getDb, getPhoneNumbersCollection } from
|
|
4
|
-
import type { Session } from
|
|
1
|
+
import { ObjectId } from 'mongodb';
|
|
2
|
+
import type { Collection, WithId } from 'mongodb';
|
|
3
|
+
import { getDb, getPhoneNumbersCollection } from '../index';
|
|
4
|
+
import type { Session } from './sessions.types';
|
|
5
5
|
|
|
6
6
|
export const getSessionsCollection = (): Collection<Session> =>
|
|
7
|
-
getDb().collection<Session>(
|
|
7
|
+
getDb().collection<Session>('sessions');
|
|
8
8
|
|
|
9
9
|
const buildPhoneCandidates = (phone: string): string[] => {
|
|
10
|
-
const raw = (phone ??
|
|
10
|
+
const raw = (phone ?? '').trim();
|
|
11
11
|
if (!raw) return [];
|
|
12
12
|
|
|
13
|
-
const noPlus = raw.startsWith(
|
|
14
|
-
const digitsOnly = raw.replace(/\D/g,
|
|
15
|
-
const digitsOnlyNoPlus = noPlus.replace(/\D/g,
|
|
13
|
+
const noPlus = raw.startsWith('+') ? raw.slice(1) : raw;
|
|
14
|
+
const digitsOnly = raw.replace(/\D/g, '');
|
|
15
|
+
const digitsOnlyNoPlus = noPlus.replace(/\D/g, '');
|
|
16
16
|
|
|
17
|
-
return Array.from(
|
|
18
|
-
new Set([raw, noPlus, digitsOnly, digitsOnlyNoPlus].filter(Boolean)),
|
|
19
|
-
);
|
|
17
|
+
return Array.from(new Set([raw, noPlus, digitsOnly, digitsOnlyNoPlus].filter(Boolean)));
|
|
20
18
|
};
|
|
21
19
|
|
|
22
20
|
const buildFlowIdCandidates = (flowId: unknown): Array<string | ObjectId> => {
|
|
@@ -38,12 +36,9 @@ const buildFlowIdCandidates = (flowId: unknown): Array<string | ObjectId> => {
|
|
|
38
36
|
|
|
39
37
|
export const findSessionById = (
|
|
40
38
|
sessionId: ObjectId,
|
|
41
|
-
clientId: string
|
|
39
|
+
clientId: string
|
|
42
40
|
): Promise<WithId<Session> | null> => {
|
|
43
|
-
return getSessionsCollection().findOne({
|
|
44
|
-
_id: sessionId,
|
|
45
|
-
clientId: clientId,
|
|
46
|
-
});
|
|
41
|
+
return getSessionsCollection().findOne({ _id: sessionId, clientId: clientId });
|
|
47
42
|
};
|
|
48
43
|
|
|
49
44
|
export const findSessionOfIncomingCall = async (from: string, to: string) => {
|
|
@@ -73,9 +68,9 @@ export const findSessionOfIncomingCall = async (from: string, to: string) => {
|
|
|
73
68
|
$addFields: {
|
|
74
69
|
phone_numbers: {
|
|
75
70
|
$filter: {
|
|
76
|
-
input:
|
|
77
|
-
as:
|
|
78
|
-
cond: { $in: [
|
|
71
|
+
input: '$phone_numbers',
|
|
72
|
+
as: 'pn',
|
|
73
|
+
cond: { $in: ['$$pn.phoneNumber', fromCandidates] },
|
|
79
74
|
},
|
|
80
75
|
},
|
|
81
76
|
},
|
|
@@ -85,7 +80,7 @@ export const findSessionOfIncomingCall = async (from: string, to: string) => {
|
|
|
85
80
|
.toArray();
|
|
86
81
|
|
|
87
82
|
if (!session) {
|
|
88
|
-
console.info(
|
|
83
|
+
console.info('No session found for incoming call');
|
|
89
84
|
return null;
|
|
90
85
|
}
|
|
91
86
|
return session;
|
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
export const sessionMongoSchema = {
|
|
2
|
-
bsonType:
|
|
3
|
-
required: [
|
|
2
|
+
bsonType: 'object',
|
|
3
|
+
required: ['session_name'],
|
|
4
4
|
properties: {
|
|
5
|
-
_id: { bsonType:
|
|
6
|
-
session_name: { bsonType:
|
|
7
|
-
company_name: { bsonType: [
|
|
8
|
-
flow_id: { bsonType: [
|
|
5
|
+
_id: { bsonType: 'objectId' },
|
|
6
|
+
session_name: { bsonType: 'string' },
|
|
7
|
+
company_name: { bsonType: ['string', 'null'] },
|
|
8
|
+
flow_id: { bsonType: ['objectId', 'string', 'null'] },
|
|
9
9
|
metaKeys: {
|
|
10
|
-
bsonType: [
|
|
10
|
+
bsonType: ['array', 'null'],
|
|
11
11
|
items: {
|
|
12
|
-
bsonType:
|
|
13
|
-
required: [
|
|
12
|
+
bsonType: 'object',
|
|
13
|
+
required: ['key'],
|
|
14
14
|
properties: {
|
|
15
|
-
key: { bsonType:
|
|
16
|
-
value: { bsonType:
|
|
15
|
+
key: { bsonType: 'string' },
|
|
16
|
+
value: { bsonType: 'string' },
|
|
17
17
|
},
|
|
18
18
|
},
|
|
19
19
|
},
|
|
20
20
|
phone_numbers: {
|
|
21
|
-
bsonType:
|
|
21
|
+
bsonType: 'array',
|
|
22
22
|
items: {
|
|
23
|
-
bsonType:
|
|
24
|
-
required: [
|
|
23
|
+
bsonType: 'object',
|
|
24
|
+
required: ['name', 'phoneNumber'],
|
|
25
25
|
properties: {
|
|
26
|
-
name: { bsonType:
|
|
27
|
-
phoneNumber: { bsonType:
|
|
26
|
+
name: { bsonType: 'string' },
|
|
27
|
+
phoneNumber: { bsonType: 'string' },
|
|
28
28
|
},
|
|
29
29
|
},
|
|
30
30
|
},
|
|
31
|
-
voice: { bsonType: [
|
|
31
|
+
voice: { bsonType: ['string', 'null'] },
|
|
32
32
|
},
|
|
33
33
|
additionalProperties: false,
|
|
34
34
|
} as const;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ObjectId } from
|
|
1
|
+
import { ObjectId } from 'mongodb';
|
|
2
2
|
|
|
3
3
|
export type Session = {
|
|
4
4
|
_id?: ObjectId;
|
|
@@ -16,7 +16,7 @@ export type Session = {
|
|
|
16
16
|
phone_numbers: Array<{
|
|
17
17
|
name: string;
|
|
18
18
|
phoneNumber: string;
|
|
19
|
-
gender:
|
|
19
|
+
gender: 'male' | 'female';
|
|
20
20
|
}>;
|
|
21
21
|
|
|
22
22
|
voice?: string | null;
|
|
@@ -1,40 +1,37 @@
|
|
|
1
|
-
import { ObjectId } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
buildDateRangeFilter,
|
|
5
|
-
} from "../subscriptions.getters.utils";
|
|
6
|
-
import { SimpleSubscriptionFilter } from "../subscriptions.types";
|
|
1
|
+
import { ObjectId } from 'mongodb';
|
|
2
|
+
import { buildSimpleQuery, buildDateRangeFilter } from '../subscriptions.getters.utils';
|
|
3
|
+
import { SimpleSubscriptionFilter } from '../subscriptions.types';
|
|
7
4
|
|
|
8
|
-
describe(
|
|
9
|
-
describe(
|
|
10
|
-
it(
|
|
5
|
+
describe('subscriptions.getters.utils', () => {
|
|
6
|
+
describe('buildSimpleQuery', () => {
|
|
7
|
+
it('returns empty query when filter is empty', () => {
|
|
11
8
|
const filter: SimpleSubscriptionFilter = {};
|
|
12
9
|
const result = buildSimpleQuery(filter);
|
|
13
10
|
expect(result).toEqual({});
|
|
14
11
|
});
|
|
15
12
|
|
|
16
|
-
it(
|
|
17
|
-
const id =
|
|
13
|
+
it('converts _id string to ObjectId', () => {
|
|
14
|
+
const id = '507f1f77bcf86cd799439011';
|
|
18
15
|
const filter: SimpleSubscriptionFilter = { _id: id };
|
|
19
16
|
const result = buildSimpleQuery(filter);
|
|
20
17
|
expect(result._id).toBeInstanceOf(ObjectId);
|
|
21
18
|
expect((result._id as ObjectId).toHexString()).toBe(id);
|
|
22
19
|
});
|
|
23
20
|
|
|
24
|
-
it(
|
|
21
|
+
it('includes valid simple fields', () => {
|
|
25
22
|
const filter: SimpleSubscriptionFilter = {
|
|
26
|
-
clientId:
|
|
23
|
+
clientId: 'abc',
|
|
27
24
|
isActive: true,
|
|
28
25
|
};
|
|
29
26
|
const result = buildSimpleQuery(filter);
|
|
30
|
-
expect(result).toEqual({ clientId:
|
|
27
|
+
expect(result).toEqual({ clientId: 'abc', isActive: true });
|
|
31
28
|
});
|
|
32
29
|
});
|
|
33
30
|
|
|
34
|
-
describe(
|
|
35
|
-
it(
|
|
36
|
-
const from = new Date(
|
|
37
|
-
const to = new Date(
|
|
31
|
+
describe('buildDateRangeFilter', () => {
|
|
32
|
+
it('returns a mongo date range filter', () => {
|
|
33
|
+
const from = new Date('2023-01-01');
|
|
34
|
+
const to = new Date('2023-01-02');
|
|
38
35
|
const result = buildDateRangeFilter(from, to);
|
|
39
36
|
expect(result).toEqual({
|
|
40
37
|
$gte: from,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from './subscriptions.types';
|
|
2
|
+
export * from './subscriptions.getters';
|
|
3
|
+
export * from './subscriptions.getters.utils';
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {getDb} from '../index';
|
|
2
2
|
import {
|
|
3
3
|
SimpleSubscriptionFilter,
|
|
4
4
|
Subscription,
|
|
5
5
|
SubscriptionDoc,
|
|
6
6
|
SubscriptionFilter,
|
|
7
7
|
SubscriptionQueryOptions,
|
|
8
|
-
} from
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
8
|
+
} from './subscriptions.types';
|
|
9
|
+
import {Filter, ObjectId} from 'mongodb';
|
|
10
|
+
import {buildSimpleQuery} from './subscriptions.getters.utils';
|
|
11
|
+
import {applyQueryOptions} from '../utils/query.utils';
|
|
12
12
|
|
|
13
13
|
export const getSubscriptionsCollection = () => {
|
|
14
|
-
return getDb().collection<Subscription>(
|
|
14
|
+
return getDb().collection<Subscription>('subscriptions');
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -20,7 +20,7 @@ export const getSubscriptionsCollection = () => {
|
|
|
20
20
|
|
|
21
21
|
export const findSubscriptions = async (
|
|
22
22
|
filter?: SubscriptionFilter,
|
|
23
|
-
options?: SubscriptionQueryOptions
|
|
23
|
+
options?: SubscriptionQueryOptions
|
|
24
24
|
): Promise<SubscriptionDoc[]> => {
|
|
25
25
|
let query: Filter<Subscription> = {};
|
|
26
26
|
|
|
@@ -51,14 +51,12 @@ export const findSubscriptions = async (
|
|
|
51
51
|
return await applyQueryOptions(cursor, options).toArray();
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
export const countSubscriptions = async (
|
|
55
|
-
query: Filter<Subscription>,
|
|
56
|
-
): Promise<number> => {
|
|
54
|
+
export const countSubscriptions = async (query: Filter<Subscription>): Promise<number> => {
|
|
57
55
|
return getSubscriptionsCollection().countDocuments(query);
|
|
58
56
|
};
|
|
59
57
|
|
|
60
58
|
export const createSubscriptionDoc = async (
|
|
61
|
-
subscriptionData: Omit<Subscription,
|
|
59
|
+
subscriptionData: Omit<Subscription, 'createdAt' | 'updatedAt'>
|
|
62
60
|
): Promise<SubscriptionDoc> => {
|
|
63
61
|
const now = new Date();
|
|
64
62
|
const result = await getSubscriptionsCollection().insertOne({
|
|
@@ -68,14 +66,13 @@ export const createSubscriptionDoc = async (
|
|
|
68
66
|
});
|
|
69
67
|
|
|
70
68
|
const subscriptions = await findSubscriptions({ _id: result.insertedId });
|
|
71
|
-
if (!subscriptions[0])
|
|
72
|
-
throw new Error("Failed to retrieve created subscription");
|
|
69
|
+
if (!subscriptions[0]) throw new Error('Failed to retrieve created subscription');
|
|
73
70
|
return subscriptions[0];
|
|
74
71
|
};
|
|
75
72
|
|
|
76
73
|
export const updateSubscriptionDoc = async (
|
|
77
74
|
subscriptionId: ObjectId,
|
|
78
|
-
updates: Partial<Subscription
|
|
75
|
+
updates: Partial<Subscription>
|
|
79
76
|
): Promise<SubscriptionDoc | null> => {
|
|
80
77
|
return await getSubscriptionsCollection().findOneAndUpdate(
|
|
81
78
|
{ _id: subscriptionId },
|
|
@@ -86,61 +83,61 @@ export const updateSubscriptionDoc = async (
|
|
|
86
83
|
},
|
|
87
84
|
},
|
|
88
85
|
{
|
|
89
|
-
returnDocument:
|
|
90
|
-
}
|
|
86
|
+
returnDocument: 'after',
|
|
87
|
+
}
|
|
91
88
|
);
|
|
92
89
|
};
|
|
93
90
|
|
|
94
91
|
export const incrementSubscriptionUsage = async (
|
|
95
92
|
subscriptionId: ObjectId,
|
|
96
|
-
amount: number = 1
|
|
93
|
+
amount: number = 1
|
|
97
94
|
): Promise<SubscriptionDoc | null> => {
|
|
98
|
-
const fieldToIncrement =
|
|
95
|
+
const fieldToIncrement = 'cycles.$[activeCycle].usage.usedCalls';
|
|
99
96
|
return await getSubscriptionsCollection().findOneAndUpdate(
|
|
100
|
-
{ _id: subscriptionId,
|
|
97
|
+
{ _id: subscriptionId, 'cycles.isActive': true },
|
|
101
98
|
{
|
|
102
99
|
$inc: { [fieldToIncrement]: amount },
|
|
103
100
|
$set: { updatedAt: new Date() },
|
|
104
101
|
},
|
|
105
102
|
{
|
|
106
|
-
arrayFilters: [{
|
|
107
|
-
returnDocument:
|
|
108
|
-
}
|
|
103
|
+
arrayFilters: [{ 'activeCycle.isActive': true }],
|
|
104
|
+
returnDocument: 'after',
|
|
105
|
+
}
|
|
109
106
|
);
|
|
110
107
|
};
|
|
111
108
|
|
|
112
109
|
export const deactivateCurrentSubscriptionCycle = async (
|
|
113
110
|
subscriptionId: ObjectId,
|
|
114
|
-
nextRenewalDate: Date
|
|
111
|
+
nextRenewalDate: Date
|
|
115
112
|
): Promise<void> => {
|
|
116
113
|
await getSubscriptionsCollection().updateOne(
|
|
117
|
-
{ _id: subscriptionId,
|
|
114
|
+
{ _id: subscriptionId, 'cycles.isActive': true },
|
|
118
115
|
{
|
|
119
116
|
$set: {
|
|
120
|
-
|
|
117
|
+
'cycles.$[activeCycle].isActive': false,
|
|
121
118
|
nextRenewalDate: nextRenewalDate,
|
|
122
119
|
updatedAt: new Date(),
|
|
123
120
|
},
|
|
124
121
|
},
|
|
125
122
|
{
|
|
126
|
-
arrayFilters: [{
|
|
127
|
-
}
|
|
123
|
+
arrayFilters: [{ 'activeCycle.isActive': true }],
|
|
124
|
+
}
|
|
128
125
|
);
|
|
129
126
|
};
|
|
130
127
|
|
|
131
128
|
export const pushNewSubscriptionCycle = async (
|
|
132
129
|
subscriptionId: ObjectId,
|
|
133
|
-
newCycle: Subscription[
|
|
130
|
+
newCycle: Subscription['cycles'][number]
|
|
134
131
|
): Promise<SubscriptionDoc | null> => {
|
|
135
132
|
return await getSubscriptionsCollection().findOneAndUpdate(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
133
|
+
{_id: subscriptionId},
|
|
134
|
+
{
|
|
135
|
+
$push: {
|
|
136
|
+
cycles: newCycle,
|
|
137
|
+
},
|
|
140
138
|
},
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
},
|
|
139
|
+
{
|
|
140
|
+
returnDocument: 'after',
|
|
141
|
+
}
|
|
145
142
|
);
|
|
146
143
|
};
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
import { ObjectId, Filter } from
|
|
2
|
-
import {
|
|
3
|
-
Subscription,
|
|
4
|
-
SimpleSubscriptionFilter,
|
|
5
|
-
simpleFields,
|
|
6
|
-
SimpleField,
|
|
7
|
-
} from "../index";
|
|
1
|
+
import { ObjectId, Filter } from 'mongodb';
|
|
2
|
+
import { Subscription, SimpleSubscriptionFilter, simpleFields, SimpleField } from '../index';
|
|
8
3
|
|
|
9
|
-
export const buildSimpleQuery = (
|
|
10
|
-
filter: SimpleSubscriptionFilter,
|
|
11
|
-
): Filter<Subscription> => {
|
|
4
|
+
export const buildSimpleQuery = (filter: SimpleSubscriptionFilter): Filter<Subscription> => {
|
|
12
5
|
const query: Filter<Subscription> = {};
|
|
13
6
|
|
|
14
7
|
if (filter._id) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Filter, ObjectId, WithId, Sort } from
|
|
2
|
-
import { PlanDoc } from
|
|
1
|
+
import { Filter, ObjectId, WithId, Sort } from 'mongodb';
|
|
2
|
+
import { PlanDoc } from '../plans/plans.types';
|
|
3
3
|
|
|
4
4
|
export type SubscriptionCycle = {
|
|
5
5
|
usage: {
|
|
@@ -29,13 +29,13 @@ export type Subscriptions = SubscriptionDoc[];
|
|
|
29
29
|
|
|
30
30
|
// Define which Subscription fields we allow in a simple filter
|
|
31
31
|
export const simpleFields = [
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
'clientId',
|
|
33
|
+
'planId',
|
|
34
|
+
'startDate',
|
|
35
|
+
'endDate',
|
|
36
|
+
'isActive',
|
|
37
|
+
'createdAt',
|
|
38
|
+
'nextRenewalDate',
|
|
39
39
|
] as const;
|
|
40
40
|
export type SimpleField = (typeof simpleFields)[number];
|
|
41
41
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { applyQueryOptions } from
|
|
1
|
+
import { applyQueryOptions } from '../query.utils';
|
|
2
2
|
|
|
3
|
-
describe(
|
|
4
|
-
describe(
|
|
3
|
+
describe('query.utils', () => {
|
|
4
|
+
describe('applyQueryOptions()', () => {
|
|
5
5
|
let mockCursor: any;
|
|
6
6
|
|
|
7
7
|
beforeEach(() => {
|
|
@@ -12,13 +12,13 @@ describe("query.utils", () => {
|
|
|
12
12
|
};
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
it(
|
|
15
|
+
it('should return cursor if no options provided', () => {
|
|
16
16
|
const result = applyQueryOptions(mockCursor);
|
|
17
17
|
expect(result).toBe(mockCursor);
|
|
18
18
|
expect(mockCursor.sort).not.toHaveBeenCalled();
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
it(
|
|
21
|
+
it('should apply sort, skip, and limit', () => {
|
|
22
22
|
const options = {
|
|
23
23
|
sort: { name: 1 },
|
|
24
24
|
skip: 10,
|
|
@@ -26,20 +26,20 @@ describe("query.utils", () => {
|
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
const result = applyQueryOptions(mockCursor, options);
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
expect(result).toBe(mockCursor);
|
|
31
31
|
expect(mockCursor.sort).toHaveBeenCalledWith({ name: 1 });
|
|
32
32
|
expect(mockCursor.skip).toHaveBeenCalledWith(10);
|
|
33
33
|
expect(mockCursor.limit).toHaveBeenCalledWith(5);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
it(
|
|
36
|
+
it('should apply only sort if skip and limit are missing', () => {
|
|
37
37
|
const options = {
|
|
38
38
|
sort: { name: 1 },
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
const result = applyQueryOptions(mockCursor, options);
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
expect(result).toBe(mockCursor);
|
|
44
44
|
expect(mockCursor.sort).toHaveBeenCalledWith({ name: 1 });
|
|
45
45
|
expect(mockCursor.skip).not.toHaveBeenCalled();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FindCursor } from
|
|
1
|
+
import { FindCursor } from 'mongodb';
|
|
2
2
|
|
|
3
3
|
export type QueryOptions = {
|
|
4
4
|
sort?: any;
|
|
@@ -8,7 +8,7 @@ export type QueryOptions = {
|
|
|
8
8
|
|
|
9
9
|
export const applyQueryOptions = <T>(
|
|
10
10
|
cursor: FindCursor<T>,
|
|
11
|
-
options?: QueryOptions
|
|
11
|
+
options?: QueryOptions
|
|
12
12
|
): FindCursor<T> => {
|
|
13
13
|
if (!options) return cursor;
|
|
14
14
|
|