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

Creating Matches

Creating a new Match is simple. We just need to import the Match model and call its built-in save method, as follows:

const express = require('express')const api = express.Router()const Match = require('../models/match')api  .route('/admin/match/:id?')  .post((req, res, next) => {      const match = new Match(req.body)      match.save()        .then(data => res.json(data))        .catch(err => next(err) )  })   .put((req, res, next) => {          // logic to update Match       })module.exports = api

First, we import the Match model. Then, in the POST method, we create a new Match object and call the save function. If the operation is successful, we send the new Match via the res.json method. To test our creation logic, we need to configure the server.js to use our ...

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