There are two problems I spent a lot time but can not fix it.
The first one is ValidationError. my “delete a Reply function code” and “Reporting a Reply function code” both have the same problem.
The second one is my " Reporting a Thread function code" works fine in browser and database, but can not pass the tests.
The ValidationError of delete a Reply is below, the problem is the same with Reporting a Reply, both can not save the updated data. here is my code:
app.delete(‘/api/replies/:board’, async (req, res) => {
let thread = await Thread.findById(req.body.thread_id)
if (thread) {
let reply = thread.replies.find((reply) => {
return reply.id === req.body.reply_id
})
if (reply.delete_password === req.body.delete_password) {
reply.text = '[deleted]'
} else {
return res.send('incorrect password')
}
let updatedThread = await thread.save()
if (updatedThread) {
return res.send('success')
}
} else {
return res.send('Thread not found')
}
})
this.$__.validationError = new ValidationError(this);
^
ValidationError: Thread validation failed: replies.0.reported: Path reported is required., replies.0.created_on: Path created_on is required., replies.0.delete_password: Path delete_password is required.