Media update API

To allow users to update media details, we will set up a media update API that accepts a PUT request at '/api/media/:mediaId' with the updated details in the request body.

mern-mediastream/server/routes/media.routes.js:

router.route('/api/media/:mediaId')        .put(authCtrl.requireSignin,                 mediaCtrl.isPoster,                     mediaCtrl.update)

When this request is received, the server will first ensure the signed-in user is the original poster of the media content by calling the isPoster controller method.

mern-mediastream/server/controllers/media.controller.js:

const isPoster = (req, res, next) => {  let isPoster = req.media && req.auth   && req.media.postedBy._id == req.auth._id  if(!isPoster){    return res.status('403').json({ error: "User is not ...

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.