W pełni działające ulubione (do zrobienia wyszukiwanie)
This commit is contained in:
1 parent
b3be59a011
commit
d137fec731
4 files changed
+36
-5
No files matched your search
+26
-1
@@ -168,9 +168,19 @@ app.get("/list", get_privileges, function (req, res) {
|
||||
car: []
|
||||
};
|
||||
|
||||
|
||||
// sprawdz czy id jest w faworytach dla danego userid
|
||||
favDB.find({ user_id: req.signedCookies.user.id }, function (f_err, f_docs) {
|
||||
docs.forEach(doc => {
|
||||
const n_doc = doc;
|
||||
if(f_docs.find(f_doc => f_doc.car_id == doc._id)) {
|
||||
n_doc.inFavs = true;
|
||||
}
|
||||
ctx.car.push(n_doc);
|
||||
});
|
||||
|
||||
res.render('list.hbs', ctx);
|
||||
res.render('list.hbs', ctx);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -214,6 +224,21 @@ app.get("/fav", get_privileges, function (req, res) {
|
||||
});
|
||||
});
|
||||
|
||||
app.get("/unfav", get_privileges, function (req, res) {
|
||||
if (req.privilege_level < 1) {
|
||||
return res.redirect("/");
|
||||
}
|
||||
|
||||
favDB.remove({ car_id: req.query.id, user_id: req.signedCookies.user.id }, {}, function(err, numRemoved) {
|
||||
console.log("odfaworytowano " + numRemoved);
|
||||
if(req.query.return == 'favourites') {
|
||||
return res.redirect("/favourites")
|
||||
}
|
||||
res.redirect("/list");
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
app.post("/delete", get_privileges, function (req, res) {
|
||||
if (req.privilege_level < 2) {
|
||||
return res.redirect("/");
|
||||
|
||||
Reference in new issue
Block a user