Browse Source

feat(nocodb): add handleHooks to afterBulkUpdate

pull/5349/head
Wing-Kam Wong 2 years ago
parent
commit
cadddebfbb
  1. 16
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

16
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

@ -1982,13 +1982,11 @@ class BaseModelSqlv2 {
continue; continue;
} }
const wherePk = await this._wherePk(pkValues); const wherePk = await this._wherePk(pkValues);
const response = await transaction(this.tnPath) await transaction(this.tnPath).update(d).where(wherePk);
.update(d) res.push(wherePk);
.where(wherePk);
res.push(response);
} }
await this.afterBulkUpdate(updateDatas.length, this.dbDriver, cookie); await this.afterBulkUpdate(res, this.dbDriver, cookie);
transaction.commit(); transaction.commit();
return res; return res;
@ -2041,7 +2039,7 @@ class BaseModelSqlv2 {
} }
const count = queryResponse ?? 0; const count = queryResponse ?? 0;
await this.afterBulkUpdate(count, this.dbDriver, cookie); await this.afterBulkUpdate(queryResponse, this.dbDriver, cookie);
return count; return count;
} catch (e) { } catch (e) {
@ -2146,13 +2144,15 @@ class BaseModelSqlv2 {
// } // }
} }
public async afterBulkUpdate(count: number, _trx: any, req): Promise<void> { public async afterBulkUpdate(data: any, _trx: any, req): Promise<void> {
await this.handleHooks('After.update', null, data, req);
await Audit.insert({ await Audit.insert({
fk_model_id: this.model.id, fk_model_id: this.model.id,
op_type: AuditOperationTypes.DATA, op_type: AuditOperationTypes.DATA,
op_sub_type: AuditOperationSubTypes.BULK_UPDATE, op_sub_type: AuditOperationSubTypes.BULK_UPDATE,
description: DOMPurify.sanitize( description: DOMPurify.sanitize(
`${count} records bulk updated in ${this.model.title}` `${data.length} records bulk updated in ${this.model.title}`
), ),
// details: JSON.stringify(data), // details: JSON.stringify(data),
ip: req?.clientIp, ip: req?.clientIp,

Loading…
Cancel
Save