Last active
August 16, 2018 08:11
-
-
Save bmelnychuk/f18343bbb803a479d27e4d95827bfec3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | |
id: question.id, | |
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