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

Updating the Scores

To update the score, we will require the ID of the match to look up for an existing one. If a valid match is found, we will apply the updates. If no match is found, we have to respond with a 404 not found HTTP response. Otherwise, we respond with a Success 200 HTTP response.

Let's start by creating the updateScore function, as shown:

...const Match = require('../models/match')const updateScore = async (matchId, teamId) => {  try {    let match = await Match.findById(matchId)    if (match == null) throw new Error("Match not found")    if (teamId == 'team_1') {      match.score.team_1++;    } else {      match.score.team_2++;    }    match = await match.save()    return match  } catch (err) {    throw err  }}api  .route('/admin/match/:id?')...

Now, let's call ...

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