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
@@ -1,3 +1,5 @@
|
||||
{"user_id":2,"car_id":"VKKPOAVqTuz84yEa","_id":"3LIJhKAqQwGy900g"}
|
||||
{"user_id":2,"car_id":"DxpP3rVTymsW4Zsd","_id":"lcNcdJPQky8MYMbi"}
|
||||
{"user_id":2,"car_id":"2gdpmzYo0D3kQPWu","_id":"3mhqPX3J4yZDDYvN"}
|
||||
{"user_id":2,"car_id":"ILJYjEqkiMuIqjWL","_id":"HJ7xXCTl8hyNP3W5"}
|
||||
{"user_id":2,"car_id":"DxpP3rVTymsW4Zsd","_id":"JUTgHyLKjrj8eihk"}
|
||||
{"user_id":2,"car_id":"rpO881mPXDqGMLFX","_id":"nQArHJx10blxgheV"}
|
||||
{"user_id":1,"car_id":"2gdpmzYo0D3kQPWu","_id":"q9Fb66vM1I3B47yg"}
|
||||
+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("/");
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<td>{{uszkodzony}}</td>
|
||||
<td>{{naped4x4}}</td>
|
||||
<td style="text-align: center;">
|
||||
<button>Remove</button>
|
||||
<button onclick="window.location = `/unfav?id={{_id}}&return=favourites`">UNFAV</button>
|
||||
</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
|
||||
@@ -27,7 +27,11 @@
|
||||
</td>
|
||||
{{#if (gte ../privilege_level 1)}}
|
||||
<td>
|
||||
<button onclick="window.location = `/fav?id={{_id}}`">FAV</button>
|
||||
{{#if inFavs}}
|
||||
<button onclick="window.location = `/unfav?id={{_id}}`">UNFAV</button>
|
||||
{{else}}
|
||||
<button onclick="window.location = `/fav?id={{_id}}`">FAV</button>
|
||||
{{/if}}
|
||||
</td>
|
||||
{{/if}}
|
||||
</tr>
|
||||
|
||||
Reference in new issue
Block a user