O'Reilly logo

Hands-On Full Stack Web Development with Aurelia by Erikson Haziz Murrugarra Sifuentes, Diego Jose Arguelles Rojas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The async/await instruction

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required