Skip to content

Commit

Permalink
Merge branch 'develop' into feature/561/add-category-field-to-lesson,…
Browse files Browse the repository at this point in the history
…attachment,quiz-models
  • Loading branch information
TetianaDeresh authored Sep 12, 2023
2 parents acecf8a + e8d82f5 commit 30d1d34
Show file tree
Hide file tree
Showing 32 changed files with 878 additions and 83 deletions.
4 changes: 4 additions & 0 deletions consts/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ const errors = {
code: 'FORBIDDEN',
message: 'You do not have permission to perform this action.'
},
BAD_REQUEST: {
code: 'BAD_REQUEST',
message: 'The request could not be processed due to invalid or missing parameters.'
},
BAD_CONFIRM_TOKEN: {
code: 'BAD_CONFIRM_TOKEN',
message: 'The confirm token is either invalid or has expired.'
Expand Down
3 changes: 2 additions & 1 deletion consts/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const refs = {
COURSE: 'Course',
QUIZ: 'Quiz',
FINISHED_QUIZ: 'FinishedQuiz',
ATTACHMENT: 'Attachment'
ATTACHMENT: 'Attachment',
QUESTION: 'Question'
}

module.exports = refs
22 changes: 22 additions & 0 deletions controllers/attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ const getAttachments = async (req, res) => {
res.status(200).json(attachments)
}

const createAttachments = async (req, res) => {
const { id: author } = req.user
const { description } = req.body
const files = req.files

const attachments = await attachmentService.createAttachments({ author, files, description })

res.status(201).json(attachments)
}

const updateAttachment = async (req, res) => {
const { id } = req.params
const { id: currentUser } = req.user
const { fileName } = req.body

await attachmentService.updateAttachment(id, currentUser, fileName)

res.status(204).end()
}

const deleteAttachment = async (req, res) => {
const { id } = req.params
const { id: currentUser } = req.user
Expand All @@ -27,5 +47,7 @@ const deleteAttachment = async (req, res) => {

module.exports = {
getAttachments,
createAttachments,
updateAttachment,
deleteAttachment
}
13 changes: 12 additions & 1 deletion controllers/quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,19 @@ const createQuiz = async (req, res) => {
res.status(201).send(newQuiz)
}

const updateQuiz = async (req, res) => {
const { id } = req.params
const { id: currentUserId } = req.user
const updateData = req.body

await quizService.updateQuiz(id, currentUserId, updateData)

res.status(204).end()
}

module.exports = {
getQuizzes,
getQuizById,
createQuiz
createQuiz,
updateQuiz
}
126 changes: 125 additions & 1 deletion docs/attachments/attachment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ paths:
author: 648afee884936e09a37deaaa
fileName: EnglishB2Level
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
Expand All @@ -69,7 +68,132 @@ paths:
status: 403
code: FORBIDDEN
message: You do not have permission to perform this action.
post:
security:
- bearerAuth: []
tags:
- Attachments
summary: Create new attachments.
description: Saves new attachments to the database.
consumes:
- multipart/form-data
parameters:
- in: formData
name: files
type: file
description: Array of files to upload
required: true
- in: formData
name: description
type: string
description: Description for the attachment
required: false
responses:
201:
description: Created
content:
application/json:
schema:
type: array
items:
$ref: '#/definitions/attachment'
example:
- _id: 8755bc080a00adr9243df104
author: 6255bc080a75adf9223df100
fileName: attachment1.pdf
link: '154867-attachment1.pdf'
description: This is an example attachment description.
size: 1024
createdAt: '2023-08-13T12:34:56.789Z'
updatedAt: '2023-08-13T12:34:56.789Z'
400:
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/Error'
example:
status: 400
code: INVALID_REQUEST
message: Invalid request parameters.
401:
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/Error'
example:
status: 401
code: UNAUTHORIZED
message: The requested URL requires user authorization.
/attachments/{id}:
patch:
security:
- bearerAuth: []
tags:
- Attachments
summary: Finds and updates an attachment.
description: Updates an attachment by ID which is restricted only to the tutor
produces:
- application/json
requestBody:
required: true
description: Data for update the attachment.
content:
application/json:
schema:
$ref: '#/definitions/attachmentBody'
example:
fileName: File1
parameters:
- name: id
in: path
required: true
description: ID of the attachment that needs to be updated
type: string
responses:
204:
description: No Content
400:
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/Error'
example:
status: 400
code: INVALID_ID
message: ID is invalid.
401:
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/Error'
example:
status: 401
code: UNAUTHORIZED
message: The requested URL requires user authorization.
403:
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/Error'
example:
status: 403
code: FORBIDDEN
message: You do not have permission to perform this action.
404:
description: Not Found
content:
application/json:
schema:
$ref: '#/components/Error'
example:
status: 404
code: DOCUMENT_NOT_FOUND
message: Attachment with the specified id was not found.
delete:
security:
- bearerAuth: []
Expand Down
4 changes: 0 additions & 4 deletions docs/attachments/attachments-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ definitions:
type: string
link:
type: string
description:
type: string
size:
type: number
category:
Expand Down Expand Up @@ -46,8 +44,6 @@ definitions:
type: string
link:
type: string
description:
type: string
size:
type: number
category:
Expand Down
4 changes: 4 additions & 0 deletions docs/finishedQuiz/finishedQuiz.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
paths:
/finished-quizzes:
get:
security:
- bearerAuth: []
tags:
- Finished quizzes
summary: Find all finished quizzes.
description: Finds and returns an array with a list of all user finishedQuizzes.
produces:
Expand Down
3 changes: 3 additions & 0 deletions docs/lesson/lesson-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ definitions:
type: string
minLength: 1
maxLength: 100
content:
type: string
minLength: 50
description:
type: string
minLength: 1
Expand Down
13 changes: 12 additions & 1 deletion docs/lesson/lesson.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ paths:
example:
title: Colors in English
description: With this lesson you will learn all about colors in English.
content: <h1>Title</h1>
author: 63da8767c9ad4c9a0b0eacd3
attachments: [63ed1cd25e9d781cdb6a6b15]
category: [3da8767c9ad4c9a0b0eacd3]
Expand Down Expand Up @@ -84,6 +85,7 @@ paths:
example:
title: Colors in English
description: With this lesson you will learn all about colors in English.
content: <h1>Title</h1>
author: 63da8767c9ad4c9a0b0eacd3
attachments: [63ed1cd25e9d781cdb6a6b15]
category: [3da8767c9ad4c9a0b0eacd3]
Expand All @@ -97,6 +99,7 @@ paths:
example:
title: Colors in English
description: With this lesson you will learn all about colors in English.
content: <h1>Title</h1>
author: 63da8767c9ad4c9a0b0eacd3
attachments: [63ed1cd25e9d781cdb6a6b15]
category: [3da8767c9ad4c9a0b0eacd3]
Expand Down Expand Up @@ -149,8 +152,16 @@ paths:
example:
title: Title of the lesson
description: Some information about this lesson
content: <h1>Title</h1>
author: 64a33e71eea95284f397a6ee
attachments: [63ed1cd25e9d781cdb6a6b15]
attachments:
- _id: 63ec1cd51e9d781cdb6f4b14
author: 648afee884936e09a37deaaa
fileName: EnglishB2Level.pdf
link: 3302931_EnglishB2Level.pdf
size: 230
createdAt: 2023-02-14T23:44:21.334Z
updatedAt: 2023-02-14T23:44:21.334Z
_id: 93ec1cd51e9d781cdb6f5b56
createdAt: 2023-02-14T23:44:21.334Z
updatedAt: 2023-02-14T23:44:21.334Z
Expand Down
58 changes: 58 additions & 0 deletions docs/questions/questions.schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
definitions:
questions:
type: array
items:
type: object
properties:
_id:
type: string
title:
type: string
answers:
type: array
items:
type: object
text: string
isCorrect: boolean
author:
type: string
ref: '#/components/user'
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time
questionsBody:
type: object
properties:
title:
type: string
answers:
type: array
items:
type: object
text: string
isCorrect: boolean
question:
type: object
properties:
_id:
type: string
title:
type: string
answers:
type: array
items:
type: object
text: string
isCorrect: boolean
author:
type: string
ref: '#/components/user'
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time
Loading

0 comments on commit 30d1d34

Please sign in to comment.