Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
const questionGenerationPolicy = new RandomNextQuestionPolicy();
const answerValidationPolicy = new TextEqualityAnswerValidationPolicy();
const questionRepository = new QuestionStoreRepository();
const getNextQuestionUseCase = new GetNextQuestion(
questionRepository, questionGenerationPolicy
const answerQuestionUseCase = new AnswerQuestion(
questionRepository, answerValidationPolicy
export async function getNextQuestion(categoryId: string): Promise<{ id: string, question: string, answer: string}> {
const question = await getNextQuestionUseCase.invoke(categoryId);
return {
question: question.body,
answer: question.answer
export async function answerQuestion(questionId: string, userAnswer: string): Promise<{ correctAnswer: string, isValid: boolean}> {
const answerResult = await answerQuestionUseCase.invoke(questionId, userAnswer);
return {
correctAnswer: answerResult.correctAnswer,
isValid: answerResult.isValid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.