Skip to content

Commit

Permalink
Trigger internal events on journey user updates and event creation (#466
Browse files Browse the repository at this point in the history
)
  • Loading branch information
pushchris authored Apr 29, 2024
1 parent 1f813c4 commit bf268e4
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions apps/platform/src/journey/JourneyStep.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { add, addDays, addHours, addMinutes, isEqual, isFuture, isPast, parse } from 'date-fns'
import Model from '../core/Model'
import { User } from '../users/User'
import { getCampaign, getCampaignSend, triggerCampaignSend } from '../campaigns/CampaignService'
import { crossTimezoneCopy, random, snakeCase, uuid } from '../utilities'
import { Database } from '../config/database'
Expand All @@ -11,8 +10,8 @@ import Rule from '../rules/Rule'
import { check } from '../rules/RuleEngine'
import App from '../app'
import { RRule } from 'rrule'
import { createEvent } from '../users/UserEventRepository'
import { JourneyState } from './JourneyState'
import { EventPostJob, UserPatchJob } from '../jobs'

export class JourneyUserStep extends Model {
user_id!: number
Expand Down Expand Up @@ -492,9 +491,13 @@ export class JourneyUpdate extends JourneyStep {
...state.user.data,
...value,
}
await User.update(q => q.where('id', state.user.id), {
data: state.user.data,
})
await UserPatchJob.from({
project_id: state.user.project_id,
user: {
external_id: state.user.external_id,
data: value,
},
}).queue()
}
} catch (err: any) {
logger.warn({
Expand Down Expand Up @@ -537,10 +540,16 @@ export class JourneyEvent extends JourneyStep {
value = {}
}

await createEvent(state.user, {
name: this.event_name,
data: value,
})
await EventPostJob.from({
project_id: state.user.project_id,
event: {
name: this.event_name,
external_id: state.user.external_id,
anonymous_id: state.user.anonymous_id,
data: value,
},
}).queue()

userStep.type = 'completed'
}
}
Expand Down

0 comments on commit bf268e4

Please sign in to comment.