Skip to content

Commit

Permalink
create explicit elastic index mappings, address PPR review
Browse files Browse the repository at this point in the history
  • Loading branch information
rikukissa committed Jan 14, 2025
1 parent b338446 commit 106287a
Show file tree
Hide file tree
Showing 14 changed files with 293 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ export function useEventConfigurations() {
return config
}

export function getAllFields(configuration: EventConfig) {
return configuration.actions
.flatMap((action) => action.forms.filter((form) => form.active))
.flatMap((form) => form.pages.flatMap((page) => page.fields))
}

/**
* Fetches configured events and finds a matching event
* @param eventIdentifier e.g. 'birth', 'death', 'marriage' or any configured event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import { useTypedParams } from 'react-router-typesafe-routes/dom'
import {
ActionDocument,
EventIndex,
getAllFields,
SummaryConfig
} from '@opencrvs/commons/client'
import { Content, ContentSize } from '@opencrvs/components/lib/Content'
import { IconWithName } from '@client/v2-events/components/IconWithName'
import { ROUTES } from '@client/v2-events/routes'

import {
getAllFields,
useEventConfiguration,
useEventConfigurations
} from '@client/v2-events/features/events/useEventConfiguration'
Expand Down
8 changes: 5 additions & 3 deletions packages/commons/src/events/DeduplicationConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ const FuzzyMatcher = Matcher.extend({
type: z.literal('fuzzy'),
options: z
.object({
// Names of length of 3 or less characters = 0 edits allowed
// Names of length of 4 - 6 characters = 1 edit allowed
// Names of length of >7 characters = 2 edits allowed
/**
* Names of length 3 or less characters = 0 edits allowed
* Names of length 4 - 6 characters = 1 edit allowed
* Names of length >7 characters = 2 edits allowed
*/
fuzziness: z
.union([z.string(), z.number()])
.optional()
Expand Down
8 changes: 7 additions & 1 deletion packages/commons/src/events/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { TranslationConfig } from './TranslationConfig'

import { EventMetadataKeys, eventMetadataLabelMap } from './EventMetadata'
import { flattenDeep } from 'lodash'
import { EventConfigInput } from './EventConfig'
import { EventConfig, EventConfigInput } from './EventConfig'
import { SummaryConfigInput } from './SummaryConfig'
import { WorkqueueConfigInput } from './WorkqueueConfig'
import { FieldType } from './FieldConfig'
Expand Down Expand Up @@ -100,3 +100,9 @@ export const resolveFieldLabels = ({
})
}
}

export function getAllFields(configuration: EventConfig) {
return configuration.actions
.flatMap((action) => action.forms.filter((form) => form.active))
.flatMap((form) => form.pages.flatMap((page) => page.fields))
}
2 changes: 1 addition & 1 deletion packages/events/src/router/events.get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test('Returns multiple events', async () => {
expect(events).toHaveLength(10)
})

test('Returns aggregated event with updated status and values', async () => {
test.only('Returns aggregated event with updated status and values', async () => {
const initialData = { name: 'John Doe', favouriteFruit: 'Banana' }
const event = await client.event.create(generator.event.create())
await client.event.actions.declare(
Expand Down
19 changes: 16 additions & 3 deletions packages/events/src/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ import {
setLocations
} from '@events/service/locations/locations'
import { Context, middleware } from './middleware/middleware'
import { getIndexedEvents } from '@events/service/indexing/indexing'
import {
ensureIndexExists,
getIndexedEvents
} from '@events/service/indexing/indexing'
import { EventConfig, getUUID } from '@opencrvs/commons'
import {
DeclareActionInput,
Expand Down Expand Up @@ -79,14 +82,24 @@ export const appRouter = router({
}),
event: router({
create: publicProcedure.input(EventInput).mutation(async (options) => {
const config = await getEventConfigurations(options.ctx.token)
const eventIds = config.map((c) => c.id)
const configurations = await getEventConfigurations(options.ctx.token)
const eventIds = configurations.map((c) => c.id)

validateEventType({
eventTypes: eventIds,
eventInputType: options.input.type
})

const configuration = configurations.find(
(c) => c.id === options.input.type
)

if (!configuration) {
throw new Error(`Event configuration not found ${options.input.type}`)
}

await ensureIndexExists(options.input.type, configuration)

return createEvent({
eventInput: options.input,
createdBy: options.ctx.user.id,
Expand Down
Loading

0 comments on commit 106287a

Please sign in to comment.