Skip to content

Commit

Permalink
modify quiz model
Browse files Browse the repository at this point in the history
  • Loading branch information
Mav-Ivan committed Sep 13, 2023
1 parent 9376b32 commit 69af3fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 50 deletions.
24 changes: 2 additions & 22 deletions docs/quiz/quiz-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
34 changes: 6 additions & 28 deletions models/quiz.js
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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,
Expand Down

0 comments on commit 69af3fc

Please sign in to comment.