Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/analytics/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,16 @@ function convertDotKeysToUnderscore(
return newObj
}

export async function upsertAnalyticsEventActions(
async function upsertAnalyticsEventActions(
event: EventDocument,
eventConfig: EventConfig,
trx: Kysely<any>
) {
await trx
.deleteFrom('analytics.event_actions')
.where('event_id', '=', event.id)
.execute()

for (let i = 0; i < event.actions.length; i++) {
const actionsFromStartToCurrentPoint = event.actions
.sort((a, b) => {
Expand Down
20 changes: 18 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ import {
onAnyActionHandler
} from '@countryconfig/api/custom-event/handler'
import { readFileSync } from 'fs'
import { ActionType, EventDocument } from '@opencrvs/toolkit/events'
import {
ActionDocument,
ActionStatus,
ActionType,
EventDocument
} from '@opencrvs/toolkit/events'
import { Event } from './form/types/types'
import { onRegisterHandler } from './api/registration'
import { workqueueconfigHandler } from './api/workqueue/handler'
Expand Down Expand Up @@ -279,6 +284,7 @@ export async function createServer() {
server.route({
method: 'GET',
path: '/ping',
// eslint-disable-next-line no-unused-vars
handler: (request: any, h: any) => {
// Perform any health checks and return true or false for success prop
return {
Expand Down Expand Up @@ -704,10 +710,20 @@ export async function createServer() {

if (wasRequestForActionConfirmation && wasActionAcceptedImmediately) {
const event = request.payload as EventDocument

const eventWithOptimisticallyApprovedLastAction = {
...event,
actions: event.actions.map((action, index) =>
index === event.actions.length - 1
? { ...action, status: ActionStatus.Accepted }
: action
) as ActionDocument[]
}

const client = getClient()
try {
await client.transaction().execute(async (trx) => {
await importEvent(event, trx)
await importEvent(eventWithOptimisticallyApprovedLastAction, trx)
})
} catch (error) {
// eslint-disable-next-line no-console
Expand Down
Loading