From cadddebfbbbfe99208400d96b95fc04517ee9f68 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 24 Mar 2023 13:39:34 +0800 Subject: [PATCH] feat(nocodb): add handleHooks to afterBulkUpdate --- .../db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 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 9152b1fab8..ac9de54b4d 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 @@ -1982,13 +1982,11 @@ class BaseModelSqlv2 { continue; } const wherePk = await this._wherePk(pkValues); - const response = await transaction(this.tnPath) - .update(d) - .where(wherePk); - res.push(response); + await transaction(this.tnPath).update(d).where(wherePk); + res.push(wherePk); } - await this.afterBulkUpdate(updateDatas.length, this.dbDriver, cookie); + await this.afterBulkUpdate(res, this.dbDriver, cookie); transaction.commit(); return res; @@ -2041,7 +2039,7 @@ class BaseModelSqlv2 { } const count = queryResponse ?? 0; - await this.afterBulkUpdate(count, this.dbDriver, cookie); + await this.afterBulkUpdate(queryResponse, this.dbDriver, cookie); return count; } catch (e) { @@ -2146,13 +2144,15 @@ class BaseModelSqlv2 { // } } - public async afterBulkUpdate(count: number, _trx: any, req): Promise { + public async afterBulkUpdate(data: any, _trx: any, req): Promise { + await this.handleHooks('After.update', null, data, req); + await Audit.insert({ fk_model_id: this.model.id, op_type: AuditOperationTypes.DATA, op_sub_type: AuditOperationSubTypes.BULK_UPDATE, description: DOMPurify.sanitize( - `${count} records bulk updated in ${this.model.title}` + `${data.length} records bulk updated in ${this.model.title}` ), // details: JSON.stringify(data), ip: req?.clientIp,