From b3ed532a182058f40131b951521bc638bd0682a0 Mon Sep 17 00:00:00 2001 From: jasati200 Date: Mon, 15 May 2023 11:18:09 -0700 Subject: [PATCH] Support for JSONB filtering --- 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 78d7d59..c2193fc 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]; };