favorites beta
This commit is contained in:
@@ -190,6 +190,32 @@ export default (router, tpl) => {
|
||||
})});
|
||||
});
|
||||
|
||||
group.get(/\/admin\/togglefav\/\d+$/, auth, async (req, res) => {
|
||||
const itemid = +req.url.split[4];
|
||||
|
||||
let favs = await sql('favorites').select('user_id').where('item_id', itemid);
|
||||
|
||||
if(Object.values(favs).filter(u => u.user_id === req.session.id)[0]) {
|
||||
// del fav
|
||||
await sql('favorites').where('user_id', req.session.id).andWhere('item_id', itemid).del();
|
||||
}
|
||||
else {
|
||||
// add fav
|
||||
await sql('favorites').insert({
|
||||
item_id: itemid,
|
||||
user_id: req.session.id
|
||||
});
|
||||
}
|
||||
|
||||
favs = await sql('favorites').select('user_id').where('item_id', itemid);
|
||||
|
||||
res.reply({ body: JSON.stringify({
|
||||
success: true,
|
||||
itemid: itemid,
|
||||
favs: favs
|
||||
})});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
return router;
|
||||
|
||||
Reference in New Issue
Block a user