bkmdfg
This commit is contained in:
@@ -83,7 +83,7 @@ export default router => {
|
||||
});
|
||||
|
||||
group.post(/\/excluded_tags/, lib.loggedin, async (req, res) => {
|
||||
const tagname = req.post.tagname;
|
||||
const tagname = req.post?.tagname || req.body?.tagname;
|
||||
if (!tagname) return res.json({ success: false, msg: 'No tag provided' }, 400);
|
||||
|
||||
const tag = (await db`select id, tag, normalized from tags where normalized = slugify(${tagname})`)[0];
|
||||
@@ -92,10 +92,17 @@ export default router => {
|
||||
|
||||
await db`
|
||||
update user_options
|
||||
set excluded_tags = array_append(excluded_tags, ${tag.id})
|
||||
where user_id = ${+req.session.id} and not (${tag.id} = any(excluded_tags))
|
||||
set excluded_tags = array_append(coalesce(excluded_tags, '{}'), ${tag.id})
|
||||
where user_id = ${+req.session.id} and not (${tag.id} = any(coalesce(excluded_tags, '{}')))
|
||||
`;
|
||||
|
||||
if (req.session) {
|
||||
if (!req.session.excluded_tags) req.session.excluded_tags = [];
|
||||
if (!req.session.excluded_tags.includes(tag.id)) {
|
||||
req.session.excluded_tags.push(tag.id);
|
||||
}
|
||||
}
|
||||
|
||||
// Return updated list
|
||||
const tags = await db`
|
||||
select t.id, t.tag, t.normalized
|
||||
@@ -114,10 +121,14 @@ export default router => {
|
||||
|
||||
await db`
|
||||
update user_options
|
||||
set excluded_tags = array_remove(excluded_tags, ${tag.id})
|
||||
set excluded_tags = array_remove(coalesce(excluded_tags, '{}'), ${tag.id})
|
||||
where user_id = ${+req.session.id}
|
||||
`;
|
||||
|
||||
if (req.session && req.session.excluded_tags) {
|
||||
req.session.excluded_tags = req.session.excluded_tags.filter(id => id !== tag.id);
|
||||
}
|
||||
|
||||
const tags = await db`
|
||||
select t.id, t.tag, t.normalized
|
||||
from unnest((select excluded_tags from user_options where user_id = ${+req.session.id})) as et(id)
|
||||
|
||||
Reference in New Issue
Block a user