From 9b333235eaddc31d9620f4a4cbb55d78844d433c Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 27 Mar 2023 20:43:05 +0800 Subject: [PATCH] refactor(nocodb): change deleted_rows to rows --- .../src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts | 4 ++-- .../nocodb/src/lib/meta/helpers/populateSamplePayload.ts | 6 ++---- packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts | 4 +--- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts index 23fa267665..b738a5b26b 100644 --- a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts +++ b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts @@ -2161,7 +2161,7 @@ class BaseModelSqlv2 { let noOfDeletedRecords = data; if (!isBulkAllOperation) { noOfDeletedRecords = data.length; - await this.handleHooks('after.delete', data, null, req); + await this.handleHooks('after.delete', null, data, req); } await Audit.insert({ @@ -2256,7 +2256,7 @@ class BaseModelSqlv2 { ip: req?.clientIp, user: req?.user?.email, }); - await this.handleHooks('after.delete', data, null, req); + await this.handleHooks('after.delete', null, data, req); } private async handleHooks(hookName, prevData, newData, req): Promise { diff --git a/packages/nocodb/src/lib/meta/helpers/populateSamplePayload.ts b/packages/nocodb/src/lib/meta/helpers/populateSamplePayload.ts index 96a7591d91..8d13135f15 100644 --- a/packages/nocodb/src/lib/meta/helpers/populateSamplePayload.ts +++ b/packages/nocodb/src/lib/meta/helpers/populateSamplePayload.ts @@ -94,10 +94,8 @@ export async function populateSamplePayloadV2( samplePayload.data = { ...samplePayload.data, - ...(prevRows && { - [operation === 'delete' ? 'deleted_rows' : 'previous_rows']: [prevRows], - }), - ...(operation !== 'delete' && rows && { rows: [rows] }), + ...(prevRows && { previous_rows: [prevRows] }), + ...(rows && { rows: [rows] }), }; return samplePayload; diff --git a/packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts b/packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts index 9dda9fc594..49b3b944eb 100644 --- a/packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts +++ b/packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts @@ -149,9 +149,7 @@ export function constructWebHookData(hook, model, view, prevData, newData) { view_id: view.id, view_name: view.title, ...(prevData && { - [hook.operation === 'delete' ? 'deleted_rows' : 'previous_rows']: [ - prevData, - ], + previous_rows: [prevData], }), ...(newData && { rows: [newData] }), },