Skip to content

Commit

Permalink
Merge pull request #656 from ita-social-projects/feature/643/add-sett…
Browse files Browse the repository at this point in the history
…ings-to-quiz

Added settings for quiz
  • Loading branch information
OlyaKorchan authored Dec 4, 2023
2 parents 72c4b2e + 9197208 commit 1628fff
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 3 deletions.
3 changes: 2 additions & 1 deletion consts/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const enums = {
PARAMS_ENUM: ['id', 'categoryId', 'subjectId'],
OFFER_STATUS_ENUM: ['active', 'draft', 'closed'],
NOTIFICATION_TYPE_ENUM: ['new', 'requested', 'active', 'declined', 'updated', 'closed', 'deleted'],
QUESTION_TYPE_ENUM: ['multipleChoice', 'openAnswer', 'oneAnswer']
QUESTION_TYPE_ENUM: ['multipleChoice', 'openAnswer', 'oneAnswer'],
QUIZ_VIEW_ENUM: ['Stepper', 'Scroll']
}

module.exports = {
Expand Down
49 changes: 49 additions & 0 deletions docs/quiz/quiz-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ definitions:
category:
type: string
ref: '#/definitions/resourcesCategory'
settings:
type: object
properties:
view:
type: string
enum:
- Stepper
- Scroll
shuffle:
type: boolean
pointValues:
type: boolean
scoredResponces:
type: boolean
correctAnswers:
type: boolean
createdAt:
type: string
format: date-time
Expand All @@ -38,6 +54,22 @@ definitions:
items:
type: array
ref: '#/components/question'
settings:
type: object
properties:
view:
type: string
enum:
- Stepper
- Scroll
shuffle:
type: boolean
pointValues:
type: boolean
scoredResponces:
type: boolean
correctAnswers:
type: boolean
quiz:
type: object
properties:
Expand All @@ -56,9 +88,26 @@ definitions:
category:
type: string
ref: '#/definitions/resourcesCategory'
settings:
type: object
properties:
view:
type: string
enum:
- Stepper
- Scroll
shuffle:
type: boolean
pointValues:
type: boolean
scoredResponces:
type: boolean
correctAnswers:
type: boolean
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time

28 changes: 28 additions & 0 deletions docs/quiz/quiz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,25 @@ paths:
items: [6477007a6fa4d05e1a800ce4, 6477007a6fa4d05e1a800ce6]
author: '6477007a6fa4d05e1a800ce5'
category: '63bed9ef260f18d04ab15da'
settings: {
view: Scroll,
shuffle: true,
pointValues: false,
scoredResponces: false,
correctAnswers: true
}
- _id: 64ca5932b57f2442403394a9
title: Chemistry
items: [6477007a6fa4d05e1a800ce4, 6477007a6fa4d05e1a800ce6]
author: '6477007a6fa4d05e1a800ce5'
category: '63bed9ef260f18d04ab15da'
settings: {
view: Scroll,
shuffle: true,
pointValues: false,
scoredResponces: false,
correctAnswers: true
}
count: 2
401:
description: Unauthorized
Expand Down Expand Up @@ -104,6 +118,13 @@ paths:
items: [6477007a6fa4d05e1a800ce2, 6477007a6fa4d05e1a800ce3]
category: 6477007a6fa4d05e1a800ce5
_id: 63ec1cd51e9d781cdb6f4b14
settings: {
view: Scroll,
shuffle: false,
pointValues: false,
scoredResponces: false,
correctAnswers: false
}
createdAt: 2023-02-14T23:44:21.334Z
updatedAt: 2023-02-14T23:44:21.334Z
401:
Expand Down Expand Up @@ -157,6 +178,13 @@ paths:
items: [6477007a6fa4d05e1a800ce4, 6477007a6fa4d05e1a800ce6]
author: 6477007a6fa4d05e1a800ce5,
category: 63bed9ef260f18d04ab15da
settings: {
view: Scroll,
shuffle: true,
pointValues: false,
scoredResponces: false,
correctAnswers: true
}
401:
description: Unauthorized
content:
Expand Down
31 changes: 30 additions & 1 deletion models/quiz.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const { Schema, model } = require('mongoose')
const { QUIZ, USER, RESOURCES_CATEGORY, QUESTION } = require('~/consts/models')
const { FIELD_CANNOT_BE_EMPTY, FIELD_CANNOT_BE_LONGER, FIELD_CANNOT_BE_SHORTER } = require('~/consts/errors')
const { FIELD_CANNOT_BE_EMPTY, FIELD_CANNOT_BE_LONGER, FIELD_CANNOT_BE_SHORTER, ENUM_CAN_BE_ONE_OF } = require('~/consts/errors')
const { enums: {
QUIZ_VIEW_ENUM
} } = require('~/consts/validation')

const quizSchema = new Schema(
{
Expand Down Expand Up @@ -29,6 +32,32 @@ const quizSchema = new Schema(
type: Schema.Types.ObjectId,
ref: RESOURCES_CATEGORY,
default: null
},
settings: {
view: {
type: String,
enum: {
values: QUIZ_VIEW_ENUM,
message: ENUM_CAN_BE_ONE_OF('quiz view', QUIZ_VIEW_ENUM)
},
default: QUIZ_VIEW_ENUM[1]
},
shuffle: {
type: Boolean,
default: false
},
pointValues: {
type: Boolean,
default: false
},
scoredResponces: {
type: Boolean,
default: false
},
correctAnswers: {
type: Boolean,
default: false
}
}
},
{ timestamps: true, versionKey: false }
Expand Down
8 changes: 7 additions & 1 deletion services/quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ const quizService = {
throw createForbiddenError()
}

const { settings } = updateData

for (let field in updateData) {
quiz[field] = updateData[field]
if (field === 'settings') {
Object.assign(quiz.settings, settings)
} else {
quiz[field] = updateData[field]
}
}

await quiz.save()
Expand Down

0 comments on commit 1628fff

Please sign in to comment.