1

I am trying to make an update through a service. If I use postman with the same link as in the service, the update works fine.

Here is my code:

myservice.service.ts:

updateUser(userid){
    let headers = new Headers();
    headers.append('Content-Type','application/json');
    console.log('http://localhost:3000/users/update/'+ userid);
    return this.http.put('http://localhost:3000/users/update/'+ userid, 
{headers: headers}).map(res => res.json());
}

inside routes/users.js

router.put('/update/:id', (req, res) => {
User.findByIdAndUpdate(req.params.id, {
$set: {
  participates: true}
}, 
{
  new: true
},
function(err, updatedUser){
  if(err){
    res.send("Error updating user");
  } else{
    res.json(updatedUser);
  }
}
);
});

I do not get an error, but it does not seem to enter the router.put. What am i missing?

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Ivett
  • 111
  • 1
  • 3

1 Answers1

0

here you have used this url : 'http://localhost:3000/users/update/'+ userid

but in routes you have used : /update/:id,

you have /users is not there in your routes, just use the same url as you mentioned in service would be good to use in routes, so replace your url in routes with /users/update/:id , then it will work perfectly..