Skip to content

Commit 5d1b25d

Browse files
committed
command to debug. Split event handler
1 parent b03020d commit 5d1b25d

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Command } from '@boostercloud/framework-core'
2+
import { Register, UUID } from '@boostercloud/framework-types'
3+
import { QuestionCreated } from '../events/question-created';
4+
5+
@Command({
6+
authorize: 'all' // Specify authorized roles here. Use 'all' to authorize anyone
7+
})
8+
export class PostQuestion {
9+
public constructor(
10+
readonly conferenceId: UUID,
11+
readonly text: string,
12+
) {}
13+
14+
public static async handle(command: PostQuestion , register: Register): Promise<void> {
15+
register.events(new QuestionCreated(command.text, UUID.generate(), command.conferenceId))
16+
}
17+
}
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import { QuestionCreated } from '../events/question-created'
2+
import { WordPicked } from '../events/word-picked'
23
import { EventHandler } from '@boostercloud/framework-core'
3-
import { Register } from '@boostercloud/framework-types'
4+
import { Register, UUID } from '@boostercloud/framework-types'
45

56
@EventHandler(QuestionCreated)
67
export class SplitQuestionsIntoWords {
7-
public static async handle(event: QuestionCreated, register: Register): Promise<void> {}
8+
public static async handle(event: QuestionCreated, register: Register): Promise<void> {
9+
const words = event.text.split(' ')
10+
for (const word in words) {
11+
register.events(new WordPicked(word, UUID.generate(), event.id, event.conferenceId))
12+
}
13+
}
814
}

0 commit comments

Comments
 (0)