Skip to content

Commit

Permalink
feat: refactor quiz evaluation request structure
Browse files Browse the repository at this point in the history
  • Loading branch information
wielopolski committed Jan 13, 2025
1 parent 3cf1abd commit 8f01bb7
Show file tree
Hide file tree
Showing 9 changed files with 273 additions and 277 deletions.
33 changes: 25 additions & 8 deletions apps/api/src/lesson/lesson.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,31 @@ export const lessonForChapterSchema = Type.Array(
}),
);

export const answerQuestionsForLessonBody = Type.Object({
lessonId: UUIDSchema,
export const onlyAnswerIdSAnswerSchema = Type.Object({
answerId: UUIDSchema,
});

export const onlyValueAnswerSchema = Type.Object({
value: Type.String(),
});

export const fullAnswerSchema = Type.Object({
answerId: UUIDSchema,
value: Type.String(),
});

export const studentQuestionAnswersSchema = Type.Object({
questionId: UUIDSchema,
answers: Type.Array(
Type.Object({
questionId: UUIDSchema,
answer: Type.Array(
Type.Object({ answerId: Type.Optional(UUIDSchema), value: Type.Optional(Type.String()) }),
),
}),
Type.Union([onlyAnswerIdSAnswerSchema, onlyValueAnswerSchema, fullAnswerSchema]),
),
});

export const answerQuestionsForLessonBody = Type.Object({
lessonId: UUIDSchema,
questionsAnswers: Type.Array(studentQuestionAnswersSchema),
});

export const nextLessonSchema = Type.Union([
Type.Object({
courseId: UUIDSchema,
Expand Down Expand Up @@ -182,3 +195,7 @@ export type LessonSchema = Static<typeof lessonSchema>;
export type AnswerQuestionBody = Static<typeof answerQuestionsForLessonBody>;
export type QuestionDetails = Static<typeof questionDetails>;
export type NextLesson = Static<typeof nextLessonSchema>;
export type StudentQuestionAnswer = Static<typeof studentQuestionAnswersSchema>;
export type OnlyAnswerIdAsnwer = Static<typeof onlyAnswerIdSAnswerSchema>;
export type OnlyValueAnswer = Static<typeof onlyValueAnswerSchema>;
export type FullAnswer = Static<typeof fullAnswerSchema>;
2 changes: 1 addition & 1 deletion apps/api/src/lesson/services/lesson.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class LessonService {
const correctAnswersForQuizQuestions =
await this.questionRepository.getQuizQuestionsToEvaluation(studentQuizAnswers.lessonId);

if (correctAnswersForQuizQuestions.length !== studentQuizAnswers.answers.length) {
if (correctAnswersForQuizQuestions.length !== studentQuizAnswers.questionsAnswers.length) {
throw new ConflictException("Quiz is not completed");
}

Expand Down
Loading

0 comments on commit 8f01bb7

Please sign in to comment.