Last active
August 16, 2018 08:10
-
-
Save bmelnychuk/6efe66f5863a74e7e17d5f054d4dc18c 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
class AnswerResult { | |
userAnswer: string; | |
isValid: boolean; | |
correctAnswer: string; | |
} | |
class AnswerQuestion { | |
questionRepository: QuestionRepository; | |
answerValidationPolicy: AnswerValidationPolicy; | |
async invoke(questionId: string, userAnswer: string): Promise<AnswerResult> { | |
const question = await this.questionRepository.getById(questionId); | |
const correctAnswer = question.answer; | |
const isAnswerCorrect = await this.answerValidationPolicy.isAnswerValid( | |
userAnswer, correctAnswer | |
); | |
return new AnswerResult(userAnswer, isAnswerCorrect, correctAnswer); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment