@talkpilot/core-db 1.1.3 → 1.1.5
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 +21 -24
- 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 +8 -4
- 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 +30 -22
- 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 +13 -25
- 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 +19 -9
- 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 +10 -4
- 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 +13 -8
- 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 +50 -29
- 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 +19 -15
- 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 +5 -2
- 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 +9 -2
- 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.map +1 -1
- package/dist/talkpilot/flows/flows.schema.js +87 -79
- package/dist/talkpilot/flows/flows.schema.js.map +1 -1
- package/dist/talkpilot/flows/flows.types.d.ts +16 -16
- 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 +16 -29
- 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 +28 -13
- 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 +13 -10
- 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/subscriptions/subscriptions.utils.d.ts +4 -0
- package/dist/talkpilot/subscriptions/subscriptions.utils.d.ts.map +1 -0
- package/dist/talkpilot/subscriptions/subscriptions.utils.js +20 -0
- package/dist/talkpilot/subscriptions/subscriptions.utils.js.map +1 -0
- 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 +7 -1
- 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 +6 -1
- 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 +7 -1
- 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 +3 -1
- package/src/__tests__/setup.ts +3 -3
- package/src/connection.ts +27 -25
- package/src/index.ts +9 -9
- package/src/municipal/__tests__/validation.spec.ts +35 -23
- package/src/municipal/cities/cities.getters.ts +16 -10
- package/src/municipal/cities/cities.types.ts +1 -1
- package/src/municipal/cities/index.ts +2 -2
- package/src/municipal/departmentsSubjects/departmentsSubjects.getters.ts +53 -44
- package/src/municipal/departmentsSubjects/departmentsSubjects.types.ts +5 -5
- package/src/municipal/departmentsSubjects/index.ts +2 -3
- package/src/municipal/index.ts +10 -10
- package/src/municipal/mongodb-client.ts +19 -26
- package/src/municipal/streets/index.ts +2 -2
- package/src/municipal/streets/streets.getters.ts +43 -23
- package/src/municipal/streets/streets.types.ts +1 -1
- package/src/municipal/systemInstructions/__tests__/getters.spec.ts +67 -52
- package/src/municipal/systemInstructions/__tests__/setters.spec.ts +271 -238
- package/src/municipal/systemInstructions/index.ts +7 -3
- package/src/municipal/systemInstructions/instructions.getters.ts +30 -18
- package/src/municipal/systemInstructions/instructions.setters.ts +43 -19
- 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 +69 -42
- package/src/municipal/tickets/tickets.types.ts +2 -2
- package/src/municipal/utils/types.ts +8 -3
- package/src/talkpilot/__tests__/db.spec.ts +12 -12
- package/src/talkpilot/__tests__/mongodb-client.spec.ts +7 -8
- package/src/talkpilot/__tests__/validation.spec.ts +30 -24
- 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 +42 -31
- package/src/talkpilot/backgroundToolResults/backgroundToolResults.getters.ts +11 -11
- package/src/talkpilot/backgroundToolResults/backgroundToolResults.types.ts +2 -3
- 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 +79 -39
- package/src/talkpilot/calls/calls.getters.ts +48 -28
- 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 +73 -39
- package/src/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.ts +18 -11
- package/src/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.ts +2 -2
- package/src/talkpilot/clientAudioBuffers/index.ts +2 -2
- package/src/talkpilot/clients/clients.getters.ts +10 -5
- 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 +21 -18
- package/src/talkpilot/clientsConfig/clientsConfig.getters.ts +6 -4
- package/src/talkpilot/clientsConfig/clientsConfig.types.ts +17 -7
- package/src/talkpilot/clientsConfig/index.ts +2 -2
- package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +38 -34
- package/src/talkpilot/flows/flows.getter.ts +8 -5
- package/src/talkpilot/flows/flows.schema.ts +87 -79
- package/src/talkpilot/flows/flows.types.ts +23 -23
- package/src/talkpilot/flows/index.ts +2 -2
- package/src/talkpilot/groups/__tests__/groups.spec.ts +34 -27
- package/src/talkpilot/groups/__tests__/phone.utils.spec.ts +20 -20
- package/src/talkpilot/groups/groups.getters.ts +8 -5
- package/src/talkpilot/groups/groups.types.ts +1 -1
- package/src/talkpilot/groups/index.ts +3 -3
- package/src/talkpilot/groups/phone.utils.ts +12 -6
- package/src/talkpilot/index.ts +17 -17
- package/src/talkpilot/leads/index.ts +2 -2
- package/src/talkpilot/leads/leads.getter.ts +5 -4
- package/src/talkpilot/leads/leads.schema.ts +16 -16
- package/src/talkpilot/leads/leads.types.ts +1 -1
- package/src/talkpilot/mongodb-client.ts +23 -33
- package/src/talkpilot/phone_numbers/__tests__/phone_numbers.spec.ts +84 -44
- package/src/talkpilot/phone_numbers/index.ts +2 -2
- package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +44 -22
- 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 +30 -26
- package/src/talkpilot/plans/index.ts +2 -2
- package/src/talkpilot/plans/plans.getters.ts +25 -18
- package/src/talkpilot/plans/plans.types.ts +27 -23
- package/src/talkpilot/results/index.ts +5 -2
- package/src/talkpilot/results/results.getter.ts +9 -8
- 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 +65 -41
- package/src/talkpilot/sessions/index.ts +2 -2
- package/src/talkpilot/sessions/sessions.getter.ts +21 -16
- 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 +18 -15
- package/src/talkpilot/subscriptions/index.ts +3 -3
- package/src/talkpilot/subscriptions/subscriptions.getters.ts +36 -33
- package/src/talkpilot/subscriptions/subscriptions.getters.utils.ts +10 -3
- 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 +32 -25
- package/src/test-utils/factories/municipal/streets.ts +10 -5
- package/src/test-utils/factories/municipal/tickets.ts +12 -6
- 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 +14 -12
- package/src/test-utils/factories/talkpilot/clientsConfig.ts +7 -8
- package/src/test-utils/factories/talkpilot/flows.ts +7 -5
- package/src/test-utils/factories/talkpilot/groups.ts +13 -13
- package/src/test-utils/factories/talkpilot/phone_numbers.ts +8 -6
- package/src/test-utils/factories/talkpilot/sessions.ts +5 -5
- package/src/utils/validation.ts +4 -4
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Collection, Filter } from
|
|
3
|
-
import { VectorSearchResult } from
|
|
1
|
+
import { CityName, DepartmentSubject, getDb } from "../index";
|
|
2
|
+
import { Collection, Filter } from "mongodb";
|
|
3
|
+
import { VectorSearchResult } from "./departmentsSubjects.types";
|
|
4
4
|
|
|
5
|
-
export const getDepartmentsSubjectsCollection =
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export const getDepartmentsSubjectsCollection =
|
|
6
|
+
(): Collection<DepartmentSubject> => {
|
|
7
|
+
return getDb().collection<DepartmentSubject>("departmentsSubjects");
|
|
8
|
+
};
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Get all departments subjects for a given city.
|
|
@@ -16,7 +17,7 @@ export const getDepartmentsSubjectsCollection = (): Collection<DepartmentSubject
|
|
|
16
17
|
*/
|
|
17
18
|
export const getAllDepartmentsSubjectsByCity = async (
|
|
18
19
|
cityName: CityName,
|
|
19
|
-
withEmbeddings: boolean = false
|
|
20
|
+
withEmbeddings: boolean = false,
|
|
20
21
|
): Promise<DepartmentSubject[]> => {
|
|
21
22
|
const collection = getDepartmentsSubjectsCollection();
|
|
22
23
|
const query = collection.find({ cityName });
|
|
@@ -42,17 +43,17 @@ export const vectorSearchDepartmentsSubjects = async (
|
|
|
42
43
|
queryVector: number[],
|
|
43
44
|
cityName: CityName,
|
|
44
45
|
limit: number = 5,
|
|
45
|
-
numCandidates: number = 800
|
|
46
|
+
numCandidates: number = 800,
|
|
46
47
|
): Promise<VectorSearchResult[]> => {
|
|
47
48
|
const collection = getDepartmentsSubjectsCollection();
|
|
48
|
-
const indexName =
|
|
49
|
+
const indexName = "subjectTreesIndex";
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
return await collection
|
|
51
52
|
.aggregate<VectorSearchResult>([
|
|
52
53
|
{
|
|
53
54
|
$vectorSearch: {
|
|
54
55
|
index: indexName,
|
|
55
|
-
path:
|
|
56
|
+
path: "embedding",
|
|
56
57
|
queryVector,
|
|
57
58
|
numCandidates,
|
|
58
59
|
limit,
|
|
@@ -63,23 +64,21 @@ export const vectorSearchDepartmentsSubjects = async (
|
|
|
63
64
|
$project: {
|
|
64
65
|
_id: 0,
|
|
65
66
|
subjectName: 1,
|
|
66
|
-
subject_id: { $toInt:
|
|
67
|
+
subject_id: { $toInt: "$subject_id" }, // Convert string to number
|
|
67
68
|
sub_subject_name: 1,
|
|
68
69
|
sub_subject_id: 1,
|
|
69
70
|
descriptions: 1,
|
|
70
71
|
guidelines: 1,
|
|
71
|
-
score: { $meta:
|
|
72
|
+
score: { $meta: "vectorSearchScore" },
|
|
72
73
|
},
|
|
73
74
|
},
|
|
74
75
|
])
|
|
75
76
|
.toArray();
|
|
76
|
-
|
|
77
|
-
return results;
|
|
78
77
|
};
|
|
79
78
|
|
|
80
79
|
export const addDepartmentSubjectInstruction = async (
|
|
81
80
|
filter: Filter<DepartmentSubject>,
|
|
82
|
-
instructionText: string
|
|
81
|
+
instructionText: string,
|
|
83
82
|
): Promise<DepartmentSubject | null> => {
|
|
84
83
|
const newInstruction = {
|
|
85
84
|
id: Date.now(),
|
|
@@ -92,7 +91,7 @@ export const addDepartmentSubjectInstruction = async (
|
|
|
92
91
|
$push: { instructions: newInstruction },
|
|
93
92
|
$set: { updatedAt: new Date() },
|
|
94
93
|
},
|
|
95
|
-
{ returnDocument:
|
|
94
|
+
{ returnDocument: "after" },
|
|
96
95
|
);
|
|
97
96
|
|
|
98
97
|
return result || null;
|
|
@@ -101,12 +100,17 @@ export const addDepartmentSubjectInstruction = async (
|
|
|
101
100
|
export const updateDepartmentSubjectInstruction = async (
|
|
102
101
|
filter: Filter<DepartmentSubject>,
|
|
103
102
|
instructionId: number,
|
|
104
|
-
newInstructionText: string
|
|
103
|
+
newInstructionText: string,
|
|
105
104
|
): Promise<DepartmentSubject | null> => {
|
|
106
105
|
const result = await getDepartmentsSubjectsCollection().findOneAndUpdate(
|
|
107
|
-
{ ...filter,
|
|
108
|
-
{
|
|
109
|
-
|
|
106
|
+
{ ...filter, "instructions.id": instructionId },
|
|
107
|
+
{
|
|
108
|
+
$set: {
|
|
109
|
+
"instructions.$.instruction": newInstructionText,
|
|
110
|
+
updatedAt: new Date(),
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
{ returnDocument: "after" },
|
|
110
114
|
);
|
|
111
115
|
|
|
112
116
|
return result || null;
|
|
@@ -114,7 +118,7 @@ export const updateDepartmentSubjectInstruction = async (
|
|
|
114
118
|
|
|
115
119
|
export const removeDepartmentSubjectInstruction = async (
|
|
116
120
|
filter: Filter<DepartmentSubject>,
|
|
117
|
-
instructionId: number
|
|
121
|
+
instructionId: number,
|
|
118
122
|
): Promise<DepartmentSubject | null> => {
|
|
119
123
|
const result = await getDepartmentsSubjectsCollection().findOneAndUpdate(
|
|
120
124
|
filter,
|
|
@@ -122,7 +126,7 @@ export const removeDepartmentSubjectInstruction = async (
|
|
|
122
126
|
$pull: { instructions: { id: instructionId } },
|
|
123
127
|
$set: { updatedAt: new Date() },
|
|
124
128
|
},
|
|
125
|
-
{ returnDocument:
|
|
129
|
+
{ returnDocument: "after" },
|
|
126
130
|
);
|
|
127
131
|
|
|
128
132
|
return result || null;
|
|
@@ -131,18 +135,22 @@ export const removeDepartmentSubjectInstruction = async (
|
|
|
131
135
|
export const addDepartmentSubjectCommunication = async (
|
|
132
136
|
filter: Filter<DepartmentSubject>,
|
|
133
137
|
communication: {
|
|
134
|
-
type:
|
|
138
|
+
type: "free_text_sms" | "upload_url_sms";
|
|
135
139
|
message_text?: string;
|
|
136
140
|
template_id?: string;
|
|
137
141
|
to?: string;
|
|
138
|
-
}
|
|
142
|
+
},
|
|
139
143
|
): Promise<DepartmentSubject | null> => {
|
|
140
144
|
const newCommunication = {
|
|
141
145
|
id: Date.now(),
|
|
142
146
|
type: communication.type,
|
|
143
|
-
...(communication.message_text !== undefined && {
|
|
147
|
+
...(communication.message_text !== undefined && {
|
|
148
|
+
message_text: communication.message_text,
|
|
149
|
+
}),
|
|
144
150
|
is_deleted: false,
|
|
145
|
-
...(communication.template_id !== undefined && {
|
|
151
|
+
...(communication.template_id !== undefined && {
|
|
152
|
+
template_id: communication.template_id,
|
|
153
|
+
}),
|
|
146
154
|
...(communication.to !== undefined && { to: communication.to }),
|
|
147
155
|
};
|
|
148
156
|
|
|
@@ -152,7 +160,7 @@ export const addDepartmentSubjectCommunication = async (
|
|
|
152
160
|
$push: { communications: newCommunication },
|
|
153
161
|
$set: { updatedAt: new Date() },
|
|
154
162
|
},
|
|
155
|
-
{ returnDocument:
|
|
163
|
+
{ returnDocument: "after" },
|
|
156
164
|
);
|
|
157
165
|
|
|
158
166
|
return result || null;
|
|
@@ -162,27 +170,28 @@ export const updateDepartmentSubjectCommunication = async (
|
|
|
162
170
|
filter: Filter<DepartmentSubject>,
|
|
163
171
|
communicationId: number,
|
|
164
172
|
updates: {
|
|
165
|
-
type?:
|
|
173
|
+
type?: "free_text_sms" | "upload_url_sms";
|
|
166
174
|
message_text?: string | null;
|
|
167
175
|
template_id?: string | null;
|
|
168
176
|
to?: string | null;
|
|
169
177
|
is_deleted?: boolean | null;
|
|
170
|
-
}
|
|
178
|
+
},
|
|
171
179
|
): Promise<DepartmentSubject | null> => {
|
|
172
180
|
const setFields: Record<string, unknown> = { updatedAt: new Date() };
|
|
173
|
-
if (updates.type !== undefined)
|
|
181
|
+
if (updates.type !== undefined)
|
|
182
|
+
setFields["communications.$.type"] = updates.type;
|
|
174
183
|
if (updates.message_text !== undefined)
|
|
175
|
-
setFields[
|
|
184
|
+
setFields["communications.$.message_text"] = updates.message_text;
|
|
176
185
|
if (updates.template_id !== undefined)
|
|
177
|
-
setFields[
|
|
178
|
-
if (updates.to !== undefined) setFields[
|
|
186
|
+
setFields["communications.$.template_id"] = updates.template_id;
|
|
187
|
+
if (updates.to !== undefined) setFields["communications.$.to"] = updates.to;
|
|
179
188
|
if (updates.is_deleted !== undefined)
|
|
180
|
-
setFields[
|
|
189
|
+
setFields["communications.$.is_deleted"] = updates.is_deleted;
|
|
181
190
|
|
|
182
191
|
const result = await getDepartmentsSubjectsCollection().findOneAndUpdate(
|
|
183
|
-
{ ...filter,
|
|
192
|
+
{ ...filter, "communications.id": communicationId },
|
|
184
193
|
{ $set: setFields },
|
|
185
|
-
{ returnDocument:
|
|
194
|
+
{ returnDocument: "after" },
|
|
186
195
|
);
|
|
187
196
|
|
|
188
197
|
return result || null;
|
|
@@ -190,7 +199,7 @@ export const updateDepartmentSubjectCommunication = async (
|
|
|
190
199
|
|
|
191
200
|
export const removeDepartmentSubjectCommunication = async (
|
|
192
201
|
filter: Filter<DepartmentSubject>,
|
|
193
|
-
communicationId: number
|
|
202
|
+
communicationId: number,
|
|
194
203
|
): Promise<DepartmentSubject | null> => {
|
|
195
204
|
const result = await getDepartmentsSubjectsCollection().findOneAndUpdate(
|
|
196
205
|
filter,
|
|
@@ -198,7 +207,7 @@ export const removeDepartmentSubjectCommunication = async (
|
|
|
198
207
|
$pull: { communications: { id: communicationId } },
|
|
199
208
|
$set: { updatedAt: new Date() },
|
|
200
209
|
},
|
|
201
|
-
{ returnDocument:
|
|
210
|
+
{ returnDocument: "after" },
|
|
202
211
|
);
|
|
203
212
|
|
|
204
213
|
return result || null;
|
|
@@ -214,7 +223,7 @@ export const removeDepartmentSubjectCommunication = async (
|
|
|
214
223
|
export const getDepartmentSubjectBySubjectIds = async (
|
|
215
224
|
subjectId: string,
|
|
216
225
|
subSubjectId: string,
|
|
217
|
-
cityName: CityName
|
|
226
|
+
cityName: CityName,
|
|
218
227
|
): Promise<DepartmentSubject | null> => {
|
|
219
228
|
const collection = getDepartmentsSubjectsCollection();
|
|
220
229
|
|
|
@@ -240,13 +249,13 @@ export const getDepartmentSubjectBySubjectIds = async (
|
|
|
240
249
|
*/
|
|
241
250
|
export const updateDepartmentSubjectGuidelines = async (
|
|
242
251
|
filter: Filter<DepartmentSubject>,
|
|
243
|
-
guidelines: string
|
|
252
|
+
guidelines: string,
|
|
244
253
|
): Promise<DepartmentSubject | null> => {
|
|
245
254
|
// $set will create the field if it doesn't exist
|
|
246
255
|
const result = await getDepartmentsSubjectsCollection().findOneAndUpdate(
|
|
247
256
|
filter,
|
|
248
257
|
{ $set: { guidelines, updatedAt: new Date() } },
|
|
249
|
-
{ returnDocument:
|
|
258
|
+
{ returnDocument: "after" },
|
|
250
259
|
);
|
|
251
260
|
return result || null;
|
|
252
261
|
};
|
|
@@ -257,13 +266,13 @@ export const updateDepartmentSubjectGuidelines = async (
|
|
|
257
266
|
* @returns Updated DepartmentSubject document or null if not found
|
|
258
267
|
*/
|
|
259
268
|
export const deleteDepartmentSubjectGuidelines = async (
|
|
260
|
-
filter: Filter<DepartmentSubject
|
|
269
|
+
filter: Filter<DepartmentSubject>,
|
|
261
270
|
): Promise<DepartmentSubject | null> => {
|
|
262
271
|
// $set clears the field by setting it to null (keeps the field in the document)
|
|
263
272
|
const result = await getDepartmentsSubjectsCollection().findOneAndUpdate(
|
|
264
273
|
filter,
|
|
265
274
|
{ $set: { guidelines: null, updatedAt: new Date() } },
|
|
266
|
-
{ returnDocument:
|
|
275
|
+
{ returnDocument: "after" },
|
|
267
276
|
);
|
|
268
277
|
return result || null;
|
|
269
278
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {ObjectId, WithId} from
|
|
2
|
-
import {Request} from
|
|
3
|
-
import {ClientConfigDoc, Products} from
|
|
4
|
-
import {CityName} from "../utils/types";
|
|
1
|
+
import { ObjectId, WithId } from "mongodb";
|
|
2
|
+
import { Request } from "express";
|
|
3
|
+
import { ClientConfigDoc, Products } from "../../talkpilot";
|
|
4
|
+
import { CityName } from "../utils/types";
|
|
5
5
|
|
|
6
6
|
export type DepartmentSubject = {
|
|
7
7
|
_id: ObjectId;
|
|
@@ -57,7 +57,7 @@ export type VectorSearchResult = {
|
|
|
57
57
|
score?: number;
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
export type CommunicationType =
|
|
60
|
+
export type CommunicationType = "free_text_sms" | "upload_url_sms";
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* Extended Express Request type with client configuration
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./departmentsSubjects.getters";
|
|
2
2
|
export type {
|
|
3
3
|
DepartmentSubject,
|
|
4
4
|
DepartmentSubjectDoc,
|
|
@@ -6,5 +6,4 @@ export type {
|
|
|
6
6
|
RequestWithClientConfig,
|
|
7
7
|
Communication,
|
|
8
8
|
Instruction,
|
|
9
|
-
} from
|
|
10
|
-
|
|
9
|
+
} from "./departmentsSubjects.types";
|
package/src/municipal/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Db, ObjectId as MongoObjectId } from
|
|
1
|
+
import { Db, ObjectId as MongoObjectId } from "mongodb";
|
|
2
2
|
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export {CityName} from "./utils/types";
|
|
10
|
-
export { municipalDataMongodbClient } from
|
|
3
|
+
export * from "./cities";
|
|
4
|
+
export * from "./streets";
|
|
5
|
+
export * from "./departmentsSubjects";
|
|
6
|
+
export * from "./tickets";
|
|
7
|
+
export * from "./systemInstructions";
|
|
8
|
+
export * from "./utils/types";
|
|
9
|
+
export { CityName } from "./utils/types";
|
|
10
|
+
export { municipalDataMongodbClient } from "./mongodb-client";
|
|
11
11
|
|
|
12
12
|
let db: Db;
|
|
13
13
|
export const setDb = (d: Db) => {
|
|
@@ -15,7 +15,7 @@ export const setDb = (d: Db) => {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export const getDb = (): Db => {
|
|
18
|
-
if (!db) throw new Error(
|
|
18
|
+
if (!db) throw new Error("Municipal Data DB not initialised");
|
|
19
19
|
return db;
|
|
20
20
|
};
|
|
21
21
|
export const ObjectId = MongoObjectId;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { MongoClient, Db } from
|
|
2
|
-
import { setDb } from
|
|
3
|
-
import { validateConfig, validateMongoUri } from
|
|
1
|
+
import { MongoClient, Db } from "mongodb";
|
|
2
|
+
import { setDb } from "./index";
|
|
3
|
+
import { validateConfig, validateMongoUri } from "../utils/validation";
|
|
4
4
|
|
|
5
5
|
class MunicipalDataMongoDBClient {
|
|
6
6
|
private client: MongoClient | null = null;
|
|
7
7
|
private db: Db | null = null;
|
|
8
|
-
private readonly defaultDbName =
|
|
8
|
+
private readonly defaultDbName = "municipal-data";
|
|
9
9
|
|
|
10
10
|
async connect(uri?: string, dbName?: string): Promise<void> {
|
|
11
11
|
if (this.client) {
|
|
@@ -13,39 +13,32 @@ class MunicipalDataMongoDBClient {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
const mongodbUri = uri || process.env.MONGO_URI || process.env.MONGODB_URI;
|
|
16
|
-
validateConfig(
|
|
16
|
+
validateConfig("MONGO_URI", mongodbUri);
|
|
17
17
|
validateMongoUri(mongodbUri!);
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
} catch (error) {
|
|
27
|
-
console.error('[core-db] Municipal connection failed', error as Error);
|
|
28
|
-
throw error;
|
|
29
|
-
}
|
|
19
|
+
this.client = new MongoClient(mongodbUri!);
|
|
20
|
+
await this.client.connect();
|
|
21
|
+
const targetDbName =
|
|
22
|
+
dbName || process.env.MUNICIPAL_DB_NAME || this.defaultDbName;
|
|
23
|
+
this.db = this.client.db(targetDbName);
|
|
24
|
+
setDb(this.db);
|
|
25
|
+
console.info(`[core-db] Municipal MongoDB connected: ${targetDbName}`);
|
|
30
26
|
}
|
|
31
27
|
|
|
32
28
|
async disconnect(): Promise<void> {
|
|
33
29
|
if (this.client) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
console.info('Municipal Data MongoDB disconnected successfully');
|
|
39
|
-
} catch (error) {
|
|
40
|
-
console.error('Error disconnecting from Municipal Data MongoDB', error as Error);
|
|
41
|
-
throw error;
|
|
42
|
-
}
|
|
30
|
+
await this.client.close();
|
|
31
|
+
this.client = null;
|
|
32
|
+
this.db = null;
|
|
33
|
+
console.info("Municipal Data MongoDB disconnected successfully");
|
|
43
34
|
}
|
|
44
35
|
}
|
|
45
36
|
|
|
46
37
|
getDb(): Db {
|
|
47
38
|
if (!this.db) {
|
|
48
|
-
throw new Error(
|
|
39
|
+
throw new Error(
|
|
40
|
+
"Municipal Data database not initialized. Call connect() first.",
|
|
41
|
+
);
|
|
49
42
|
}
|
|
50
43
|
return this.db;
|
|
51
44
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export type { Street, StreetDoc, StreetHint } from
|
|
1
|
+
export * from "./streets.getters";
|
|
2
|
+
export type { Street, StreetDoc, StreetHint } from "./streets.types";
|
|
@@ -1,25 +1,38 @@
|
|
|
1
|
-
import {CityName, getDb, ObjectId, Street} from
|
|
2
|
-
import type { StreetHint } from
|
|
3
|
-
import { Collection, Filter, ObjectId as MongoObjectId } from
|
|
1
|
+
import { CityName, getDb, ObjectId, Street } from "../index";
|
|
2
|
+
import type { StreetHint } from "./streets.types";
|
|
3
|
+
import { Collection, Filter, ObjectId as MongoObjectId } from "mongodb";
|
|
4
4
|
|
|
5
5
|
export const getStreetsCollection = (): Collection<Street> => {
|
|
6
|
-
return getDb().collection<Street>(
|
|
6
|
+
return getDb().collection<Street>("streets");
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
export const findStreets = async (
|
|
9
|
+
export const findStreets = async (
|
|
10
|
+
filter: Filter<Street> = {},
|
|
11
|
+
): Promise<Street[]> => {
|
|
10
12
|
return await getStreetsCollection().find(filter).toArray();
|
|
11
13
|
};
|
|
12
14
|
|
|
13
|
-
export const getStreetById = async (
|
|
14
|
-
|
|
15
|
+
export const getStreetById = async (
|
|
16
|
+
streetId: string,
|
|
17
|
+
): Promise<Street | null> => {
|
|
18
|
+
const street = await getStreetsCollection().findOne({
|
|
19
|
+
_id: new ObjectId(streetId),
|
|
20
|
+
});
|
|
15
21
|
return street ? street : null;
|
|
16
22
|
};
|
|
17
23
|
|
|
18
|
-
export const getStreetsByCityName = async (
|
|
19
|
-
|
|
24
|
+
export const getStreetsByCityName = async (
|
|
25
|
+
cityName: CityName,
|
|
26
|
+
): Promise<Street[]> => {
|
|
27
|
+
return await getStreetsCollection()
|
|
28
|
+
.find({ cityName })
|
|
29
|
+
.sort({ name: 1 })
|
|
30
|
+
.toArray();
|
|
20
31
|
};
|
|
21
32
|
|
|
22
|
-
export const getStreetByStreetId = async (
|
|
33
|
+
export const getStreetByStreetId = async (
|
|
34
|
+
streetId: string,
|
|
35
|
+
): Promise<Street | null> => {
|
|
23
36
|
const street = await getStreetsCollection().findOne({ id: streetId });
|
|
24
37
|
return street ? street : null;
|
|
25
38
|
};
|
|
@@ -27,32 +40,37 @@ export const getStreetByStreetId = async (streetId: string): Promise<Street | nu
|
|
|
27
40
|
/** Get street by business id and city. Use this when the client's city is known so the same id in another city is not returned. */
|
|
28
41
|
export const getStreetByStreetIdAndCity = async (
|
|
29
42
|
streetId: string,
|
|
30
|
-
cityName: CityName
|
|
43
|
+
cityName: CityName,
|
|
31
44
|
): Promise<Street | null> => {
|
|
32
|
-
const street = await getStreetsCollection().findOne({
|
|
45
|
+
const street = await getStreetsCollection().findOne({
|
|
46
|
+
id: streetId,
|
|
47
|
+
cityName,
|
|
48
|
+
});
|
|
33
49
|
return street ? street : null;
|
|
34
50
|
};
|
|
35
51
|
|
|
36
52
|
export const createStreet = async (
|
|
37
|
-
streetData: Omit<Street,
|
|
53
|
+
streetData: Omit<Street, "_id" | "createdAt" | "updatedAt">,
|
|
38
54
|
): Promise<MongoObjectId> => {
|
|
39
|
-
const street: Omit<Street,
|
|
55
|
+
const street: Omit<Street, "_id"> = {
|
|
40
56
|
...streetData,
|
|
41
57
|
createdAt: new Date(),
|
|
42
58
|
updatedAt: new Date(),
|
|
43
59
|
};
|
|
44
|
-
const { insertedId } = await getStreetsCollection().insertOne(
|
|
60
|
+
const { insertedId } = await getStreetsCollection().insertOne(
|
|
61
|
+
street as Street,
|
|
62
|
+
);
|
|
45
63
|
return insertedId;
|
|
46
64
|
};
|
|
47
65
|
|
|
48
66
|
export const updateStreet = async (
|
|
49
67
|
streetId: string,
|
|
50
|
-
data: Partial<Omit<Street,
|
|
68
|
+
data: Partial<Omit<Street, "_id" | "createdAt" | "updatedAt">>,
|
|
51
69
|
): Promise<Street | null> => {
|
|
52
70
|
const result = await getStreetsCollection().findOneAndUpdate(
|
|
53
71
|
{ _id: new ObjectId(streetId) },
|
|
54
72
|
{ $set: { ...data, updatedAt: new Date() } },
|
|
55
|
-
{ returnDocument:
|
|
73
|
+
{ returnDocument: "after" },
|
|
56
74
|
);
|
|
57
75
|
return result || null;
|
|
58
76
|
};
|
|
@@ -63,7 +81,7 @@ export const updateStreet = async (
|
|
|
63
81
|
*/
|
|
64
82
|
export const upsertStreetHintOnStreet = async (
|
|
65
83
|
street: Street,
|
|
66
|
-
hint: Partial<StreetHint> & Pick<StreetHint,
|
|
84
|
+
hint: Partial<StreetHint> & Pick<StreetHint, "text">,
|
|
67
85
|
): Promise<Street | null> => {
|
|
68
86
|
const text = hint.text.trim();
|
|
69
87
|
if (!text) return null;
|
|
@@ -71,7 +89,7 @@ export const upsertStreetHintOnStreet = async (
|
|
|
71
89
|
const hints = street.hints || [];
|
|
72
90
|
let updatedHints: StreetHint[];
|
|
73
91
|
|
|
74
|
-
if (hint.id != null && hint.id !==
|
|
92
|
+
if (hint.id != null && hint.id !== "") {
|
|
75
93
|
const hintIndex = hints.findIndex((h) => String(h.id) === String(hint.id));
|
|
76
94
|
if (hintIndex === -1) return null;
|
|
77
95
|
updatedHints = [...hints];
|
|
@@ -86,20 +104,22 @@ export const upsertStreetHintOnStreet = async (
|
|
|
86
104
|
/** Remove a hint from a street. streetId is the street business id (e.g. "703"). Updates document updatedAt. */
|
|
87
105
|
export const deleteStreetHint = async (
|
|
88
106
|
streetId: string,
|
|
89
|
-
hintId: string
|
|
107
|
+
hintId: string,
|
|
90
108
|
): Promise<Street | null> => {
|
|
91
109
|
const result = await getStreetsCollection().findOneAndUpdate(
|
|
92
110
|
{ id: streetId },
|
|
93
111
|
{ $pull: { hints: { id: hintId } }, $set: { updatedAt: new Date() } },
|
|
94
|
-
{ returnDocument:
|
|
112
|
+
{ returnDocument: "after" },
|
|
95
113
|
);
|
|
96
114
|
if (result) {
|
|
97
|
-
console.info(
|
|
115
|
+
console.info("Street hint deleted", { streetId, hintId });
|
|
98
116
|
}
|
|
99
117
|
return result || null;
|
|
100
118
|
};
|
|
101
119
|
|
|
102
120
|
export const deleteStreet = async (streetId: string): Promise<boolean> => {
|
|
103
|
-
const result = await getStreetsCollection().deleteOne({
|
|
121
|
+
const result = await getStreetsCollection().deleteOne({
|
|
122
|
+
_id: new ObjectId(streetId),
|
|
123
|
+
});
|
|
104
124
|
return result.deletedCount > 0;
|
|
105
125
|
};
|