Hi i don’t know what wrong.
can you help me pls?
What’s the problem? Can you tell me? I don’t know about this but I’m trying to help you.
Thank you for Reply
My problem is that I can’t find it.
Everything is normal, everything can be connected.
Run all tests through. But I’m stuck on one thing that I don’t know what it is.
This is the part that is relevant to the problem.
`
.put((req, res) => {
Message.findOne({ board: req.params.board, _id: mongoose.Types.ObjectId(req.body.thread_id) }, async (err, doc) => {
if (err) {
throw err;
}
if (!doc) {
res.send(“invalid thread ID”);
} else {
const result = doc.replies.findIndex(({ _id }) => {
return JSON.stringify(_id) === "${req.body.reply_id}"
;
});
if (isNaN(result)) {
res.send(‘invalid reply ID’);
} else {
doc.replies[result].reported = true;
await doc.save();
res.send(‘reported’);
}
}
});
})
`
The line return JSON.stringify(_id) === "${req.body.reply_id}";
should use backticks for string interpolation instead of double quotes
return JSON.stringify(_id) === `${req.body.reply_id}`;
this’s more detail error
// running tests
You can send a PUT request to /api/threads/{board} and pass along the thread_id. Returned will be the string reported. The reported value of the thread_id will be changed to true.
// tests completed
// console output
[Error: expected ‘invalid id’ to equal ‘reported’]
Thank you I tried it and it didn’t work.
You are sending invalid id
in the /api/threads/:board
PUT handler. Are you sure the body payload contains a report_id
property?
Your PUT handler for the /api/replies/:board
endpoint is crashing. If you do not see it add --watch
to the start script or add a try/catch to the code and log the error. I believe your findIndex is the cause, isNaN
does not prevent you from using -1
for the index for doc.replies
app.route(‘/api/threads/:board’)
.put((req, res) => {
Message.findOneAndUpdate({ board: req.params.board, _id: mongoose.Types.ObjectId(req.body.thread_id) }, { $set: { reported: true } }, { useFindAndModify: false }, (err, doc) => {
if (err) {
throw err;
}
if (!doc) {
res.send(‘invalid id’);
} else {
res.send(‘reported’);
}
});
})
This code adds a route handler for PUT requests to /api/threads/:board
, which retrieves the board parameter from the request URL and the thread_id parameter from the request body. The code then uses the findOneAndUpdate()
method to find the relevant Message document and update its reported
field to true
. If the operation is successful, the server sends a response of “reported”, otherwise it sends a response of “invalid id”.
done i use this from GPT LOL Thank everyone
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.