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