Skip to content

Commit

Permalink
command to debug. Split event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
davidverdu committed Mar 25, 2021
1 parent b03020d commit 5d1b25d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
17 changes: 17 additions & 0 deletions asker-analytics/backend/src/commands/post-question.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Command } from '@boostercloud/framework-core'
import { Register, UUID } from '@boostercloud/framework-types'
import { QuestionCreated } from '../events/question-created';

@Command({
authorize: 'all' // Specify authorized roles here. Use 'all' to authorize anyone
})
export class PostQuestion {
public constructor(
readonly conferenceId: UUID,
readonly text: string,
) {}

public static async handle(command: PostQuestion , register: Register): Promise<void> {
register.events(new QuestionCreated(command.text, UUID.generate(), command.conferenceId))
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { QuestionCreated } from '../events/question-created'
import { WordPicked } from '../events/word-picked'
import { EventHandler } from '@boostercloud/framework-core'
import { Register } from '@boostercloud/framework-types'
import { Register, UUID } from '@boostercloud/framework-types'

@EventHandler(QuestionCreated)
export class SplitQuestionsIntoWords {
public static async handle(event: QuestionCreated, register: Register): Promise<void> {}
public static async handle(event: QuestionCreated, register: Register): Promise<void> {
const words = event.text.split(' ')
for (const word in words) {
register.events(new WordPicked(word, UUID.generate(), event.id, event.conferenceId))
}
}
}

0 comments on commit 5d1b25d

Please sign in to comment.