From f3b64d53af05465bdf84d13bf5149f272b144a12 Mon Sep 17 00:00:00 2001 From: natsutteatsuiyone Date: Tue, 15 Nov 2022 21:33:51 +0900 Subject: [PATCH] fix: Tag Matches doesn't work for Browse by Tags --- server/graph/resolvers/page.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/server/graph/resolvers/page.js b/server/graph/resolvers/page.js index 15631a18..fc846c12 100644 --- a/server/graph/resolvers/page.js +++ b/server/graph/resolvers/page.js @@ -111,7 +111,13 @@ module.exports = { } } if (args.tags && args.tags.length > 0) { - queryBuilder.whereIn('tags.tag', args.tags.map(t => _.trim(t).toLowerCase())) + queryBuilder.whereExists(function() { + this.select('*') + .from('pageTags as pt') + .leftJoin('tags as t', 'pt.tagId', 't.id') + .whereRaw('"pt"."pageId" = "pages"."id"') + .whereIn('t.tag', args.tags.map(t => _.trim(t).toLowerCase())) + }) } const orderDir = args.orderByDirection === 'DESC' ? 'desc' : 'asc' switch (args.orderBy) { @@ -135,7 +141,8 @@ module.exports = { results = _.filter(results, r => { return WIKI.auth.checkAccess(context.req.user, ['read:pages'], { path: r.path, - locale: r.locale + locale: r.locale, + tags: r.tags }) }).map(r => ({ ...r, @@ -183,7 +190,8 @@ module.exports = { const allTags = _.filter(pages, r => { return WIKI.auth.checkAccess(context.req.user, ['read:pages'], { path: r.path, - locale: r.locale + locale: r.locale, + tags: r.tags }) }).flatMap(r => r.tags) return _.orderBy(_.uniqBy(allTags, 'id'), ['tag'], ['asc'])