Controller 

The create controller method is executed when a POST request is received at '/api/games/by/:userId' with the request body containing the new game data.

mern-vrgame/server/controllers/game.controller.js:

const create = (req, res, next) => {  const game = new Game(req.body)  game.maker= req.profile  game.save((err, result) => {    if(err) {      return res.status(400).json({        error: errorHandler.getErrorMessage(err)      })    }    res.status(200).json(result)  })}

In this create method, a new game document is created using the game schema and the data passed in the request body from the client side. Then this document is saved in the Game collection after the user reference is set as the game maker.

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.