Skip to content

Instantly share code, notes, and snippets.

@bmelnychuk
Last active August 16, 2018 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmelnychuk/6efe66f5863a74e7e17d5f054d4dc18c to your computer and use it in GitHub Desktop.
Save bmelnychuk/6efe66f5863a74e7e17d5f054d4dc18c to your computer and use it in GitHub Desktop.
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