From 6af27545608d3adc1f3b5be17f1c0bfb6a5965a3 Mon Sep 17 00:00:00 2001 From: Bek Date: Mon, 29 May 2023 14:27:58 +0500 Subject: [PATCH] support for jsonb filtering (#155) --- src/buildVariables/buildGetListVariables.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/buildVariables/buildGetListVariables.ts b/src/buildVariables/buildGetListVariables.ts index c9e7a2a..f20042a 100644 --- a/src/buildVariables/buildGetListVariables.ts +++ b/src/buildVariables/buildGetListVariables.ts @@ -110,7 +110,16 @@ export const buildGetListVariables: BuildGetListVariables = ? `%${obj[key]}%` : obj[key], }; - filter = set({}, keyName.split(SPLIT_TOKEN), operator); + break; + case 'jsonb': + try { + const parsedJSONQuery = JSON.parse(obj[key]); + if (parsedJSONQuery) { + operator = { + [operation || '_contains']: parsedJSONQuery + }; + } + } catch (ex) {} break; default: if (!operator) @@ -119,7 +128,6 @@ export const buildGetListVariables: BuildGetListVariables = ? `%${obj[key]}%` : obj[key], }; - filter = set({}, keyName.split(SPLIT_TOKEN), operator); } } else { // Else block runs when the field is not found in Graphql schema. @@ -131,8 +139,8 @@ export const buildGetListVariables: BuildGetListVariables = ? `%${obj[key]}%` : obj[key], }; - filter = set({}, keyName.split(SPLIT_TOKEN), operator); } + filter = set({}, keyName.split(SPLIT_TOKEN), operator); } return [...acc, filter]; };