June 2018
Intermediate to advanced
348 pages
8h 19m
English
The async and await are two instructions that come to save our life from the Promise chaos. This will allows us to write asynchronous code using asynchronous syntax. Let's organize our code to see how this works!
First, we will need to create a new function for the update process, as follows:
...const Team = require('../models/team')const updateTeam = async (id, teamBody) => { try { let team = await Team.findById(id) if (team == null) throw new Error("Team not found") team.code = teamBody.code || team.code team.name = teamBody.name || team.name team.ranking = teamBody.ranking || team.ranking team.captain = teamBody.captain || team.captain team.trainer = teamBody.trainer || team.trainer team.confederation = teamBody.confederation ...Read now
Unlock full access