.post((req, res) => { const isValid = Room.validate(req.body); if (!isValid) { res.sendStatus(400); } else { const userId = res.locals.user.userId; Room.save({ ...req.body, userId }) .then(newRoomId => res.status(201).json(newRoomId)) .catch(err => res.status(500).send({ err })); } });
.patch((req, res) => { const isValid = Room.validate(req.body); if (!isValid) { res.sendStatus(400); } else { Room.findByIdAndUpdate(req.params.room_id, req.body) .then(rowsAffected => { if (rowsAffected < 1) { res.sendStatus(404); } else { res.sendStatus(204); } }) .catch(err => res.status(500).send({ err })); } })