Skip to content

Commit

Permalink
chore: remove default error messsage
Browse files Browse the repository at this point in the history
  • Loading branch information
felixtanhm committed May 9, 2024
1 parent 713ca5b commit 3a44d25
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,34 @@ const Users = require("../models/users");

exports.getUser = async function (req, res, next) {
try {
const currUser = await Users.findOne({ email: "[email protected]" })
.populate("favorites")
.exec();
const currUser = await Users.findOne({
email: "[email protected]",
}).exec();

res.status(200).json(currUser);
} catch (error) {
return next(error);
next(error);
}
};

exports.updateUser = async function (req, res, next) {
try {
const { objectId, favorites } = req.body;
const updatedUser = await Users.updateOne(
{ _id: objectId },
{ $set: { favorites: favorites } }
);

if (updatedUser.acknowledged) {
res.status(200).json(updatedUser);
} else {
const error = new Error(
"Something went wrong while saving your favorites!"
);
error.status = 404;
return next(error);
}
} catch (error) {
next(error);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ const userController = require("../controllers/userController");
/* GET users listing. */
router.get("/", userController.getUser);

router.post("/", userController.updateUser);

module.exports = router;

0 comments on commit 3a44d25

Please sign in to comment.