Skip to content

Commit

Permalink
Added category field to models
Browse files Browse the repository at this point in the history
  • Loading branch information
TetianaDeresh committed Sep 12, 2023
1 parent b3b1454 commit acecf8a
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 54 deletions.
3 changes: 2 additions & 1 deletion docs/attachments/attachment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ paths:
link: 'https://english-b2-test.com'
description: This is basic B2 level English test.
size: 230
category: [3da8767c9ad4c9a0b0eacd3]
createdAt: 2023-02-14T23:44:21.334Z
updatedAt: 2023-02-14T23:44:21.334Z
401:
Expand Down Expand Up @@ -126,4 +127,4 @@ paths:
example:
status: 404
code: DOCUMENT_NOT_FOUND
message: Attachment with the specified id was not found.
message: Attachment with the specified id was not found.
9 changes: 9 additions & 0 deletions docs/attachments/attachments-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ definitions:
type: string
size:
type: number
category:
type: array
ref: '#/components/category'
createdAt:
type: string
format: date-time
Expand All @@ -31,6 +34,9 @@ definitions:
type: string
size:
type: number
category:
type: array
ref: '#/components/category'
attachment:
type: object
properties:
Expand All @@ -44,6 +50,9 @@ definitions:
type: string
size:
type: number
category:
type: array
ref: '#/components/category'
createdAt:
type: string
format: date-time
Expand Down
5 changes: 4 additions & 1 deletion docs/lesson/lesson-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ definitions:
attachments:
type: array
$ref: '#/components/attachments'
category:
type: string
ref: '#/components/category'
required:
- title
- description
- description
15 changes: 9 additions & 6 deletions docs/lesson/lesson.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ paths:
title: Colors in English
description: With this lesson you will learn all about colors in English.
author: 63da8767c9ad4c9a0b0eacd3
attachments: [ 63ed1cd25e9d781cdb6a6b15 ]
attachments: [63ed1cd25e9d781cdb6a6b15]
category: [3da8767c9ad4c9a0b0eacd3]
_id: 63ec1cd51e9d781cdb6f4b14
createdAt: 2023-02-14T23:44:21.334Z
updatedAt: 2023-02-14T23:44:21.334Z
Expand Down Expand Up @@ -84,7 +85,8 @@ paths:
title: Colors in English
description: With this lesson you will learn all about colors in English.
author: 63da8767c9ad4c9a0b0eacd3
attachments: [ 63ed1cd25e9d781cdb6a6b15 ]
attachments: [63ed1cd25e9d781cdb6a6b15]
category: [3da8767c9ad4c9a0b0eacd3]
responses:
201:
description: Created
Expand All @@ -96,7 +98,8 @@ paths:
title: Colors in English
description: With this lesson you will learn all about colors in English.
author: 63da8767c9ad4c9a0b0eacd3
attachments: [ 63ed1cd25e9d781cdb6a6b15 ]
attachments: [63ed1cd25e9d781cdb6a6b15]
category: [3da8767c9ad4c9a0b0eacd3]
_id: 63ec1cd51e9d781cdb6f4b14
createdAt: 2023-02-14T23:44:21.334Z
updatedAt: 2023-02-14T23:44:21.334Z
Expand Down Expand Up @@ -147,7 +150,7 @@ paths:
title: Title of the lesson
description: Some information about this lesson
author: 64a33e71eea95284f397a6ee
attachments: [ 63ed1cd25e9d781cdb6a6b15 ]
attachments: [63ed1cd25e9d781cdb6a6b15]
_id: 93ec1cd51e9d781cdb6f5b56
createdAt: 2023-02-14T23:44:21.334Z
updatedAt: 2023-02-14T23:44:21.334Z
Expand Down Expand Up @@ -252,7 +255,7 @@ paths:
message: Lesson with the specified id was not found.
delete:
security:
- bearerAuth: [ ]
- bearerAuth: []
tags:
- Lessons
summary: Delete lesson by ID
Expand Down Expand Up @@ -307,4 +310,4 @@ paths:
example:
status: 404
code: DOCUMENT_NOT_FOUND
message: Lesson with the specified id was not found.
message: Lesson with the specified id was not found.
82 changes: 44 additions & 38 deletions docs/quiz/quiz-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ definitions:
title:
type: string
items:
type: array
items:
type: object
properties:
question:
type: string
answers:
type: array
items:
type: object
text: string
isCorrect: boolean
type: array
items:
type: object
properties:
question:
type: string
answers:
type: array
items:
type: object
text: string
isCorrect: boolean
author:
type: string
ref: '#/components/user'
category:
type: string
ref: '#/components/category'
createdAt:
type: string
format: date-time
Expand All @@ -36,18 +39,18 @@ definitions:
title:
type: string
items:
type: array
items:
type: object
properties:
question:
type: string
answers:
type: array
items:
type: object
text: string
isCorrect: boolean
type: array
items:
type: object
properties:
question:
type: string
answers:
type: array
items:
type: object
text: string
isCorrect: boolean
quiz:
type: object
properties:
Expand All @@ -56,24 +59,27 @@ definitions:
title:
type: string
items:
type: array
items:
type: object
properties:
question:
type: string
answers:
type: array
items:
type: object
text: string
isCorrect: boolean
type: array
items:
type: object
properties:
question:
type: string
answers:
type: array
items:
type: object
text: string
isCorrect: boolean
author:
type: string
ref: '#/components/user',
category:
type: string
ref: '#/components/user'
ref: '#/components/category'
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time
format: date-time
5 changes: 4 additions & 1 deletion docs/quiz/quiz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ paths:
- text: Yes, of course,
isCorrect: true
author: '6477007a6fa4d05e1a800ce5'
category: '63bed9ef260f18d04ab15da'
- _id: 64ca5932b57f2442403394a9
title: Chemistry
items:
Expand All @@ -61,6 +62,7 @@ paths:
- text: H2O2
isCorrect: true
author: '6477007a6fa4d05e1a800ce5'
category: '63bed9ef260f18d04ab15da'
count: 2
401:
description: Unauthorized
Expand Down Expand Up @@ -178,7 +180,8 @@ paths:
isCorrect: false
- text: Yes, of course,
isCorrect: true
author: '6477007a6fa4d05e1a800ce5'
author: '6477007a6fa4d05e1a800ce5',
category: '63bed9ef260f18d04ab15da'
401:
description: Unauthorized
content:
Expand Down
6 changes: 5 additions & 1 deletion models/attachment.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { ATTACHMENT, USER } = require('~/consts/models')
const { ATTACHMENT, USER, CATEGORY } = require('~/consts/models')
const { Schema, model } = require('mongoose')
const { FIELD_CANNOT_BE_EMPTY, FIELD_CANNOT_BE_SHORTER, FIELD_CANNOT_BE_LONGER } = require('~/consts/errors')

Expand Down Expand Up @@ -30,6 +30,10 @@ const attachmentSchema = new Schema(
size: {
type: Number,
required: [true, FIELD_CANNOT_BE_EMPTY('size')]
},
category: {
type: [Schema.Types.ObjectId],
ref: CATEGORY
}
},
{
Expand Down
6 changes: 5 additions & 1 deletion models/lesson.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { Schema, model } = require('mongoose')
const { FIELD_CANNOT_BE_EMPTY, FIELD_CANNOT_BE_SHORTER, FIELD_CANNOT_BE_LONGER } = require('~/consts/errors')
const { USER, LESSON, ATTACHMENT } = require('~/consts/models')
const { USER, LESSON, ATTACHMENT, CATEGORY } = require('~/consts/models')
const lessonSchema = new Schema(
{
author: {
Expand All @@ -25,6 +25,10 @@ const lessonSchema = new Schema(
attachments: {
type: [Schema.Types.ObjectId],
ref: ATTACHMENT
},
category: {
type: [Schema.Types.ObjectId],
ref: CATEGORY
}
},
{
Expand Down
6 changes: 5 additions & 1 deletion 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, CATEGORY } = require('~/consts/models')
const { FIELD_CANNOT_BE_EMPTY, FIELD_CANNOT_BE_LONGER, FIELD_CANNOT_BE_SHORTER } = require('~/consts/errors')

const quizSchema = new Schema(
Expand Down Expand Up @@ -41,6 +41,10 @@ const quizSchema = new Schema(
type: Schema.Types.ObjectId,
ref: USER,
required: [true, FIELD_CANNOT_BE_EMPTY('author')]
},
category: {
type: [Schema.Types.ObjectId],
ref: CATEGORY
}
},
{ timestamps: true, versionKey: false }
Expand Down
4 changes: 2 additions & 2 deletions services/lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const { DOCUMENT_NOT_FOUND } = require('~/consts/errors')

const lessonService = {
createLesson: async (author, data) => {
const { title, description, attachments } = data
const { title, description, attachments, category } = data

return await Lesson.create({ author, title, description, attachments })
return await Lesson.create({ author, title, description, attachments, category })
},

getLessons: async (match, sort, skip, limit) => {
Expand Down
3 changes: 2 additions & 1 deletion services/quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ const quizService = {
},

createQuiz: async (author, data) => {
const { title, items } = data
const { title, category, items } = data

return await Quiz.create({
title,
author,
category,
items
})
}
Expand Down
5 changes: 4 additions & 1 deletion test/integration/controllers/lesson.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const nonExistingLessonId = '64a51e41de4debbccf0b39b0'
const testLesson = {
title: 'title',
description: 'description',
attachments: ['65bed8ef260f18d04ab22da3', '65bed9ef260f19d05ab25bc6']
attachments: ['65bed8ef260f18d04ab22da3', '65bed9ef260f19d05ab25bc6'],
category: ['63bed9ef260f18d04ab15da']
}

let tutorUser = {
Expand Down Expand Up @@ -74,6 +75,7 @@ describe('Lesson controller', () => {
expect(testLessonResponse.body).toMatchObject({
title: 'title',
description: 'description',
category: testLesson.category,
attachments: expect.any(Array)
})
})
Expand Down Expand Up @@ -196,6 +198,7 @@ describe('Lesson controller', () => {
author: expect.any(String),
title: 'title',
description: 'description',
category: testLesson.category,
attachments: expect.any(Array),
createdAt: expect.any(String),
updatedAt: expect.any(String)
Expand Down
4 changes: 4 additions & 0 deletions test/integration/controllers/quiz.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const endpointUrl = '/quizzes/'

const testQuizData = {
title: 'Assembly',
category: ['63bed9ef260f18d04ab15da'],
items: [
{
question: 'Is it the best programming language?',
Expand Down Expand Up @@ -73,6 +74,7 @@ describe('Quiz controller', () => {
createdAt: expect.any(String),
updatedAt: expect.any(String),
author: currentUser.id,
category: testQuizData.category,
...testQuizData
})
})
Expand Down Expand Up @@ -106,6 +108,7 @@ describe('Quiz controller', () => {
author: currentUser.id,
createdAt: expect.any(String),
updatedAt: expect.any(String),
category: testQuizData.category,
...testQuizData
}
],
Expand Down Expand Up @@ -134,6 +137,7 @@ describe('Quiz controller', () => {
expect(response.body).toMatchObject({
_id: expect.any(String),
author: currentUser.id,
category: testQuizData.category,
createdAt: expect.any(String),
updatedAt: expect.any(String),
...testQuizData
Expand Down

0 comments on commit acecf8a

Please sign in to comment.