Skip to content
Snippets Groups Projects
Commit 3ea1b46c authored by Bilel El Yaagoubi's avatar Bilel El Yaagoubi
Browse files

you can now unlike

parent d66c2b22
No related branches found
No related tags found
1 merge request!15You can now like movies
Pipeline #42571 passed
...@@ -56,11 +56,17 @@ router.put("/unlike", async function (req, res) { ...@@ -56,11 +56,17 @@ router.put("/unlike", async function (req, res) {
const movieId = await req.body.movieId; const movieId = await req.body.movieId;
const movieOid = await MovieModel.findOne({ id: movieId }); const movieOid = await MovieModel.findOne({ id: movieId });
const user = await UserModel.findById(userId); const user = await UserModel.findById(userId);
const likedMovies = user.liked_movies.concat([movieOid._id]); const likedMovies = user.liked_movies;
const myIndex = likedMovies.indexOf(movieOid._id);
if (myIndex !== -1) {
likedMovies.splice(myIndex, 1);
await UserModel.findByIdAndUpdate(userId, { await UserModel.findByIdAndUpdate(userId, {
liked_movies: likedMovies, liked_movies: likedMovies,
}); });
res.send("Done"); res.send("Done");
} else {
res.send("This movie wasn't liked");
}
} catch (error) { } catch (error) {
console.log(error); console.log(error);
res.send("Internal problem"); res.send("Internal problem");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment