Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modificate update question endpoint #617

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions controllers/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,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
Loading