From 5df8ed16689bac9e35c507cbc29a71fe94f9fee5 Mon Sep 17 00:00:00 2001 From: Wan <495709+wa0x6e@users.noreply.github.com> Date: Sat, 19 Oct 2024 13:05:18 +0400 Subject: [PATCH] feat: add filter to search proposals by labels (#948) * feat: add filter to search proposals by labels * fix: ignore empty labels filters --- src/graphql/operations/proposals.ts | 5 +++++ src/graphql/schema.gql | 1 + 2 files changed, 6 insertions(+) diff --git a/src/graphql/operations/proposals.ts b/src/graphql/operations/proposals.ts index e3409f19..d02b9f4e 100644 --- a/src/graphql/operations/proposals.ts +++ b/src/graphql/operations/proposals.ts @@ -72,6 +72,11 @@ export default async function (parent, args) { searchSql += ' AND p.flagged = 0'; } + if (where?.labels_in?.length) { + searchSql += ' AND JSON_OVERLAPS(p.labels, ?)'; + params.push(JSON.stringify(where.labels_in)); + } + let orderBy = args.orderBy || 'created'; let orderDirection = args.orderDirection || 'desc'; if (!['created', 'start', 'end'].includes(orderBy)) orderBy = 'created'; diff --git a/src/graphql/schema.gql b/src/graphql/schema.gql index dd6ee209..c4823f34 100644 --- a/src/graphql/schema.gql +++ b/src/graphql/schema.gql @@ -221,6 +221,7 @@ input ProposalWhere { end_lte: Int scores_state: String scores_state_in: [String] + labels_in: [String] state: String space_verified: Boolean flagged: Boolean