April 2020
Intermediate to advanced
716 pages
18h 55m
English
For the implementation of the create expense API that will allow creating new expenses in the database, we will first add a POST route, as shown in the following code.
mern-expense-tracker/server/routes/expense.routes.js:
router.route('/api/expenses') .post(authCtrl.requireSignin, expenseCtrl.create)
A POST request to this route at /api/expenses will first ensure that the requesting user is signed in with the requireSignin method from the auth controllers, before invoking the create method to add a new expense record in the database. This create method is defined in the following code.
mern-expense-tracker/server/controllers/expense.controller.js:
const create = async (req, res) = { try { req.body.recorded_by = req.auth._id ...Read now
Unlock full access