Skip to content

Commit

Permalink
modificate update question endpoint (#617)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tolik170 authored Nov 7, 2023
1 parent 93403b9 commit 13c4546
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
5 changes: 3 additions & 2 deletions controllers/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ const updateQuestion = async (req, res) => {
const { id } = req.params
const { id: currentUserId } = req.user
const data = req.body
await questionService.updateQuestion(id, currentUserId, data)

res.status(204).end()
const updatedQuestion = await questionService.updateQuestion(id, currentUserId, data)

res.status(200).json(updatedQuestion)
}

module.exports = {
Expand Down
26 changes: 22 additions & 4 deletions docs/questions/question.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ paths:
- bearerAuth: []
tags:
- Questions
summary: Update question by id.
description: Updates question by id.
summary: Updates question by id and return it.
description: Updates question by id and return it.
produces:
- application/json
parameters:
Expand All @@ -166,8 +166,26 @@ paths:
example:
title: WebAssembly
responses:
204:
description: No content
200:
description: OK
content:
application/json:
schema:
$ref: '#definitions/question'
example:
_id: 63ec1cd51e9d781cdb6f4b14
title: WebAssembly
text: What is the chemical symbol for water?
answers:
- text: First answer
isCorrect: true
- text: Second answer
isCorrect: false
type: multipleChoice
author: 63da8767c9ad4c9a0b0eacd3
category: { _id: 6477007a6fa4d05e1a800ce1, name: Science }
createdAt: 2023-02-14T23:44:21.334Z
updatedAt: 2023-02-14T23:44:21.334Z
401:
description: Unauthorized
content:
Expand Down
2 changes: 2 additions & 0 deletions services/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ const questionService = {
for (let field in data) {
question[field] = data[field]
}

await question.save()
return question.populate({ path: 'category', select: '_id name' })
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/controllers/question.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('Question controller', () => {
.patch(endpointUrl + testQuestionId)
.send(updateData)
.set('Authorization', `Bearer ${accessToken}`)
expect(response.statusCode).toBe(204)
expect(response.statusCode).toBe(200)

const updatedQuestion = await Question.findById(testQuestionId)

Expand Down

0 comments on commit 13c4546

Please sign in to comment.