From 94fb9bc60ad8549b940611d79009f7613007e4a8 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 20 Dec 2023 12:04:51 +0000 Subject: [PATCH] feat: add webhook v3 condition check --- packages/nocodb/src/helpers/webhookHelpers.ts | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/nocodb/src/helpers/webhookHelpers.ts b/packages/nocodb/src/helpers/webhookHelpers.ts index 44118a8729..48261d83d6 100644 --- a/packages/nocodb/src/helpers/webhookHelpers.ts +++ b/packages/nocodb/src/helpers/webhookHelpers.ts @@ -303,7 +303,21 @@ export async function invokeWebhook( if (hook.condition && !testHook) { if (isBulkOperation) { const filteredData = []; - for (const data of newData) { + for (let i = 0; i < newData.length; i++) { + const data = newData[i]; + const prevData = prevData ? prevData[i] : null; + + if (hook.version === 'v3' && prevData) { + // if condition is satisfied for prevData then return + if ( + await validateCondition( + testFilters || (await hook.getFilters()), + prevData, + ) + ) { + continue; + } + } if ( await validateCondition( testFilters || (await hook.getFilters()), @@ -312,12 +326,23 @@ export async function invokeWebhook( ) { filteredData.push(data); } - if (!filteredData.length) { + } + if (!filteredData.length) { + return; + } + newData = filteredData; + } else { + if (hook.version === 'v3' && prevData) { + // if condition is satisfied for prevData then return + if ( + await validateCondition( + testFilters || (await hook.getFilters()), + prevData, + ) + ) { return; } - newData = filteredData; } - } else { if ( !(await validateCondition( testFilters || (await hook.getFilters()),