June 2018
Intermediate to advanced
348 pages
8h 19m
English
To update our teams, first we will need to look for an existing team in our database using the ID provided in the path. If a team is found, we apply the changes to the team object. So, let's start adding the following code:
api .route('/teams/:id') .get((req, res, next) => { ... }) .put((req, res, next) => { let id = req.params.id Team.findById(id) .then(data => { if (data == null) { throw new Error("Team not found") } return data }) .then(team => { // We found the team. // Code to update goes here! }) .catch(err => next(err)) }) .delete((req, res) => {
// TODO })...
First, we extract the id passed in the endpoint. Then, we call the findById method to look for an existing team. If a valid team is found, we will have a
Read now
Unlock full access