W pełni działające ulubione (do zrobienia wyszukiwanie)
This commit is contained in:
1 parent
b3be59a011
commit
d137fec731
4 files changed
+34
-3
No files matched your search
@@ -1,3 +1,5 @@
|
|||||||
{"user_id":2,"car_id":"VKKPOAVqTuz84yEa","_id":"3LIJhKAqQwGy900g"}
|
{"user_id":2,"car_id":"2gdpmzYo0D3kQPWu","_id":"3mhqPX3J4yZDDYvN"}
|
||||||
{"user_id":2,"car_id":"DxpP3rVTymsW4Zsd","_id":"lcNcdJPQky8MYMbi"}
|
{"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":2,"car_id":"rpO881mPXDqGMLFX","_id":"nQArHJx10blxgheV"}
|
||||||
|
{"user_id":1,"car_id":"2gdpmzYo0D3kQPWu","_id":"q9Fb66vM1I3B47yg"}
|
||||||
@@ -168,10 +168,20 @@ app.get("/list", get_privileges, function (req, res) {
|
|||||||
car: []
|
car: []
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// sprawdz czy id jest w faworytach dla danego userid
|
// 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);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/favourites", get_privileges, function (req, res) {
|
app.get("/favourites", get_privileges, function (req, res) {
|
||||||
@@ -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) {
|
app.post("/delete", get_privileges, function (req, res) {
|
||||||
if (req.privilege_level < 2) {
|
if (req.privilege_level < 2) {
|
||||||
return res.redirect("/");
|
return res.redirect("/");
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
<td>{{uszkodzony}}</td>
|
<td>{{uszkodzony}}</td>
|
||||||
<td>{{naped4x4}}</td>
|
<td>{{naped4x4}}</td>
|
||||||
<td style="text-align: center;">
|
<td style="text-align: center;">
|
||||||
<button>Remove</button>
|
<button onclick="window.location = `/unfav?id={{_id}}&return=favourites`">UNFAV</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|||||||
@@ -27,7 +27,11 @@
|
|||||||
</td>
|
</td>
|
||||||
{{#if (gte ../privilege_level 1)}}
|
{{#if (gte ../privilege_level 1)}}
|
||||||
<td>
|
<td>
|
||||||
|
{{#if inFavs}}
|
||||||
|
<button onclick="window.location = `/unfav?id={{_id}}`">UNFAV</button>
|
||||||
|
{{else}}
|
||||||
<button onclick="window.location = `/fav?id={{_id}}`">FAV</button>
|
<button onclick="window.location = `/fav?id={{_id}}`">FAV</button>
|
||||||
|
{{/if}}
|
||||||
</td>
|
</td>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
Reference in new issue
Block a user