Skip to content

Commit ae07f5b

Browse files
committed
Update outdated code example
1 parent 506bcdd commit ae07f5b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/content/4/en/part4d.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,21 @@ notesRouter.post('/', async (request, response) => {
196196
const user = await User.findById(decodedToken.id)
197197
//highlight-end
198198

199+
if (!user) {
200+
return response.status(400).json({ error: 'UserId missing or not valid' })
201+
}
202+
199203
const note = new Note({
200204
content: body.content,
201-
important: body.important === undefined ? false : body.important,
205+
important: body.important || false,
202206
user: user._id
203207
})
204208

205209
const savedNote = await note.save()
206210
user.notes = user.notes.concat(savedNote._id)
207211
await user.save()
208212

209-
response.json(savedNote)
213+
response.status(201).json(savedNote)
210214
})
211215
```
212216

src/content/4/fi/osa4d.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,21 @@ notesRouter.post('/', async (request, response) => {
164164
const user = await User.findById(decodedToken.id)
165165
//highlight-end
166166

167+
if (!user) {
168+
return response.status(400).json({ error: 'UserId missing or not valid' })
169+
}
170+
167171
const note = new Note({
168172
content: body.content,
169-
important: body.important === undefined ? false : body.important,
173+
important: body.important || false,
170174
user: user._id
171175
})
172176

173177
const savedNote = await note.save()
174178
user.notes = user.notes.concat(savedNote._id)
175179
await user.save()
176180

177-
response.json(savedNote)
181+
response.status(201).json(savedNote)
178182
})
179183
```
180184

0 commit comments

Comments
 (0)