Skip to content

Instantly share code, notes, and snippets.

@bmelnychuk
Last active August 16, 2018 08:11
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/f18343bbb803a479d27e4d95827bfec3 to your computer and use it in GitHub Desktop.
Save bmelnychuk/f18343bbb803a479d27e4d95827bfec3 to your computer and use it in GitHub Desktop.
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