-1
Greetings dev’s my route file is like this:
const express = require('express')
const routes = express.Router()
const TodoController = require('./controllers/TodoController')
...
routes.put('/todo/:id', TodoController.alterTodo)
module.exports = routes
Among other methods that are working my controller is like this:
const TodoModel = require('../models/TodoModel')
module.exports = {
...
async alterTodo(req, res) {
try {
await TodoModel.findByIdAndUpdate(req.params.id, {
item: req.body.item,
done: req.body.done
})
res.json({
message: 'Seu TODO foi atualizado com sucesso.',
...req.body
})
} catch (e) {
res.json({
message: e
})
}
}}
I’m passing my URL this way:
While the ID of the item I want to update has nothing wrong, because my GET requests are returning this same id that I pass in the URL, and I’m always copying and pasting to avoid errors of this type.
But when trying to make this request she does not even enter my catch and returns me a 404 status with a pure string saying "Cannot PUT /all/5c7b50cb4a73110d68704251".
NOTE: I am not missing the json with the data to be updated and I am using the latest version of Mongoose(5.4.16) and Express(4.16.4)
Well, on your call you do
/todos
and in the definition isroutes.put('/todo/:id', TodoController.alterTodo)
– Sorack
My God bro, I can’t believe it was that
– Lone Tonberry