diff --git a/docs/quiz/quiz-schema.yaml b/docs/quiz/quiz-schema.yaml index 94f72e687..74edde354 100644 --- a/docs/quiz/quiz-schema.yaml +++ b/docs/quiz/quiz-schema.yaml @@ -10,17 +10,7 @@ definitions: type: string items: type: array - items: - type: object - properties: - question: - type: string - answers: - type: array - items: - type: object - text: string - isCorrect: boolean + ref: '#/components/question' author: type: string ref: '#/components/user' @@ -57,17 +47,7 @@ definitions: type: string items: type: array - items: - type: object - properties: - question: - type: string - answers: - type: array - items: - type: object - text: string - isCorrect: boolean + ref: '#/components/question' author: type: string ref: '#/components/user' diff --git a/models/quiz.js b/models/quiz.js index ae4a4e5e1..2591fd38a 100644 --- a/models/quiz.js +++ b/models/quiz.js @@ -1,5 +1,5 @@ const { Schema, model } = require('mongoose') -const { QUIZ, USER } = require('~/consts/models') +const { QUIZ, USER, QUESTION } = require('~/consts/models') const { FIELD_CANNOT_BE_EMPTY, FIELD_CANNOT_BE_LONGER, FIELD_CANNOT_BE_SHORTER } = require('~/consts/errors') const quizSchema = new Schema( @@ -10,33 +10,11 @@ const quizSchema = new Schema( minLength: [1, FIELD_CANNOT_BE_SHORTER('title', 1)], maxLength: [100, FIELD_CANNOT_BE_LONGER('title', 100)] }, - items: [ - { - _id: false, - question: { - type: String, - required: [true, FIELD_CANNOT_BE_EMPTY('question')], - minLength: [1, FIELD_CANNOT_BE_SHORTER('question', 1)], - maxLength: [150, FIELD_CANNOT_BE_LONGER('question', 150)] - }, - answers: [ - { - _id: false, - text: { - type: String, - required: [true, FIELD_CANNOT_BE_EMPTY('answer')], - minLength: [1, FIELD_CANNOT_BE_SHORTER('answer', 1)], - maxLength: [150, FIELD_CANNOT_BE_LONGER('answer', 150)] - }, - isCorrect: { - type: Boolean, - default: false, - required: true - } - } - ] - } - ], + items: { + type: [Schema.Types.ObjectId], + ref: QUESTION, + required: true + }, author: { type: Schema.Types.ObjectId, ref: USER,