May 2018
Intermediate to advanced
470 pages
13h 54m
English
The create controller method, defined in order controllers, takes the order details, creates a new order, and saves it to the Order collection in MongoDB.
mern-marketplace/server/controllers/order.controller.js:
const create = (req, res) => { req.body.order.user = req.profile const order = new Order(req.body.order) order.save((err, result) => { if (err) { return res.status(400).json({ error: errorHandler.getErrorMessage(err) }) } res.status(200).json(result) })}
With this implemented, orders can be created and stored in the backend by any signed-in user on the MERN Marketplace. Now we can set up APIs to fetch lists of orders by user, orders by shop, or read an individual order and display the fetched data to ...
Read now
Unlock full access