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.