|
|
@ -1864,7 +1864,7 @@ class BaseModelSqlv2 { |
|
|
|
await this.execAndParse(query); |
|
|
|
await this.execAndParse(query); |
|
|
|
|
|
|
|
|
|
|
|
const newData = await this.readByPk(id); |
|
|
|
const newData = await this.readByPk(id); |
|
|
|
await this.afterUpdate(prevData, newData, trx, cookie); |
|
|
|
await this.afterUpdate(prevData, newData, trx, cookie, updateObj); |
|
|
|
return newData; |
|
|
|
return newData; |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
console.log(e); |
|
|
|
console.log(e); |
|
|
@ -2296,7 +2296,7 @@ class BaseModelSqlv2 { |
|
|
|
op_type: AuditOperationTypes.DATA, |
|
|
|
op_type: AuditOperationTypes.DATA, |
|
|
|
op_sub_type: AuditOperationSubTypes.INSERT, |
|
|
|
op_sub_type: AuditOperationSubTypes.INSERT, |
|
|
|
description: DOMPurify.sanitize( |
|
|
|
description: DOMPurify.sanitize( |
|
|
|
`${id} inserted into ${this.model.title}` |
|
|
|
`Record with ID ${id} has been inserted into Table ${this.model.title}` |
|
|
|
), |
|
|
|
), |
|
|
|
// details: JSON.stringify(data),
|
|
|
|
// details: JSON.stringify(data),
|
|
|
|
ip: req?.clientIp, |
|
|
|
ip: req?.clientIp, |
|
|
@ -2322,7 +2322,9 @@ class BaseModelSqlv2 { |
|
|
|
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( |
|
|
|
`${noOfUpdatedRecords} records bulk updated in ${this.model.title}` |
|
|
|
`${noOfUpdatedRecords} ${ |
|
|
|
|
|
|
|
noOfUpdatedRecords > 1 ? 'records have' : 'record has' |
|
|
|
|
|
|
|
} been bulk updated in ${this.model.title}` |
|
|
|
), |
|
|
|
), |
|
|
|
// details: JSON.stringify(data),
|
|
|
|
// details: JSON.stringify(data),
|
|
|
|
ip: req?.clientIp, |
|
|
|
ip: req?.clientIp, |
|
|
@ -2347,7 +2349,9 @@ class BaseModelSqlv2 { |
|
|
|
op_type: AuditOperationTypes.DATA, |
|
|
|
op_type: AuditOperationTypes.DATA, |
|
|
|
op_sub_type: AuditOperationSubTypes.BULK_DELETE, |
|
|
|
op_sub_type: AuditOperationSubTypes.BULK_DELETE, |
|
|
|
description: DOMPurify.sanitize( |
|
|
|
description: DOMPurify.sanitize( |
|
|
|
`${noOfDeletedRecords} records bulk deleted in ${this.model.title}` |
|
|
|
`${noOfDeletedRecords} ${ |
|
|
|
|
|
|
|
noOfDeletedRecords > 1 ? 'records have' : 'record has' |
|
|
|
|
|
|
|
} been bulk deleted in ${this.model.title}` |
|
|
|
), |
|
|
|
), |
|
|
|
// details: JSON.stringify(data),
|
|
|
|
// details: JSON.stringify(data),
|
|
|
|
ip: req?.clientIp, |
|
|
|
ip: req?.clientIp, |
|
|
@ -2363,7 +2367,9 @@ class BaseModelSqlv2 { |
|
|
|
op_type: AuditOperationTypes.DATA, |
|
|
|
op_type: AuditOperationTypes.DATA, |
|
|
|
op_sub_type: AuditOperationSubTypes.BULK_INSERT, |
|
|
|
op_sub_type: AuditOperationSubTypes.BULK_INSERT, |
|
|
|
description: DOMPurify.sanitize( |
|
|
|
description: DOMPurify.sanitize( |
|
|
|
`${data.length} records bulk inserted into ${this.model.title}` |
|
|
|
`${data.length} ${ |
|
|
|
|
|
|
|
data.length > 1 ? 'records have' : 'record has' |
|
|
|
|
|
|
|
} been bulk inserted in ${this.model.title}` |
|
|
|
), |
|
|
|
), |
|
|
|
// details: JSON.stringify(data),
|
|
|
|
// details: JSON.stringify(data),
|
|
|
|
ip: req?.clientIp, |
|
|
|
ip: req?.clientIp, |
|
|
@ -2387,16 +2393,32 @@ class BaseModelSqlv2 { |
|
|
|
prevData: any, |
|
|
|
prevData: any, |
|
|
|
newData: any, |
|
|
|
newData: any, |
|
|
|
_trx: any, |
|
|
|
_trx: any, |
|
|
|
req |
|
|
|
req, |
|
|
|
|
|
|
|
updateObj?: Record<string, any> |
|
|
|
): Promise<void> { |
|
|
|
): Promise<void> { |
|
|
|
const id = this._extractPksValues(newData); |
|
|
|
const id = this._extractPksValues(newData); |
|
|
|
|
|
|
|
let desc = `Record with ID ${id} has been updated in Table ${this.model.title}.`; |
|
|
|
|
|
|
|
if (updateObj) { |
|
|
|
|
|
|
|
updateObj = await this.model.mapColumnToAlias(updateObj); |
|
|
|
|
|
|
|
for (const k of Object.keys(updateObj)) { |
|
|
|
|
|
|
|
const prevValue = |
|
|
|
|
|
|
|
typeof prevData[k] === 'object' |
|
|
|
|
|
|
|
? JSON.stringify(prevData[k]) |
|
|
|
|
|
|
|
: prevData[k]; |
|
|
|
|
|
|
|
const newValue = |
|
|
|
|
|
|
|
typeof newData[k] === 'object' |
|
|
|
|
|
|
|
? JSON.stringify(newData[k]) |
|
|
|
|
|
|
|
: newData[k]; |
|
|
|
|
|
|
|
desc += `\n`; |
|
|
|
|
|
|
|
desc += `Column "${k}" got changed from "${prevValue}" to "${newValue}"`; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
await Audit.insert({ |
|
|
|
await Audit.insert({ |
|
|
|
fk_model_id: this.model.id, |
|
|
|
fk_model_id: this.model.id, |
|
|
|
row_id: id, |
|
|
|
row_id: id, |
|
|
|
op_type: AuditOperationTypes.DATA, |
|
|
|
op_type: AuditOperationTypes.DATA, |
|
|
|
op_sub_type: AuditOperationSubTypes.UPDATE, |
|
|
|
op_sub_type: AuditOperationSubTypes.UPDATE, |
|
|
|
description: DOMPurify.sanitize(`${id} updated in ${this.model.title}`), |
|
|
|
description: DOMPurify.sanitize(desc), |
|
|
|
// details: JSON.stringify(data),
|
|
|
|
// details: JSON.stringify(data),
|
|
|
|
ip: req?.clientIp, |
|
|
|
ip: req?.clientIp, |
|
|
|
user: req?.user?.email, |
|
|
|
user: req?.user?.email, |
|
|
@ -2424,7 +2446,9 @@ class BaseModelSqlv2 { |
|
|
|
row_id: id, |
|
|
|
row_id: id, |
|
|
|
op_type: AuditOperationTypes.DATA, |
|
|
|
op_type: AuditOperationTypes.DATA, |
|
|
|
op_sub_type: AuditOperationSubTypes.DELETE, |
|
|
|
op_sub_type: AuditOperationSubTypes.DELETE, |
|
|
|
description: DOMPurify.sanitize(`${id} deleted from ${this.model.title}`), |
|
|
|
description: DOMPurify.sanitize( |
|
|
|
|
|
|
|
`Record with ID ${id} has been deleted in Table ${this.model.title}` |
|
|
|
|
|
|
|
), |
|
|
|
// details: JSON.stringify(data),
|
|
|
|
// details: JSON.stringify(data),
|
|
|
|
ip: req?.clientIp, |
|
|
|
ip: req?.clientIp, |
|
|
|
user: req?.user?.email, |
|
|
|
user: req?.user?.email, |
|
|
@ -2695,7 +2719,7 @@ class BaseModelSqlv2 { |
|
|
|
op_sub_type: AuditOperationSubTypes.LINK_RECORD, |
|
|
|
op_sub_type: AuditOperationSubTypes.LINK_RECORD, |
|
|
|
row_id: rowId, |
|
|
|
row_id: rowId, |
|
|
|
description: DOMPurify.sanitize( |
|
|
|
description: DOMPurify.sanitize( |
|
|
|
`Record [id:${childId}] record linked with record [id:${rowId}] record in ${this.model.title}` |
|
|
|
`Record [id:${childId}] has been linked with record [id:${rowId}] in ${this.model.title}` |
|
|
|
), |
|
|
|
), |
|
|
|
// details: JSON.stringify(data),
|
|
|
|
// details: JSON.stringify(data),
|
|
|
|
ip: req?.clientIp, |
|
|
|
ip: req?.clientIp, |
|
|
@ -2797,7 +2821,7 @@ class BaseModelSqlv2 { |
|
|
|
op_sub_type: AuditOperationSubTypes.UNLINK_RECORD, |
|
|
|
op_sub_type: AuditOperationSubTypes.UNLINK_RECORD, |
|
|
|
row_id: rowId, |
|
|
|
row_id: rowId, |
|
|
|
description: DOMPurify.sanitize( |
|
|
|
description: DOMPurify.sanitize( |
|
|
|
`Record [id:${childId}] record unlinked with record [id:${rowId}] record in ${this.model.title}` |
|
|
|
`Record [id:${childId}] has been unlinked with record [id:${rowId}] in ${this.model.title}` |
|
|
|
), |
|
|
|
), |
|
|
|
// details: JSON.stringify(data),
|
|
|
|
// details: JSON.stringify(data),
|
|
|
|
ip: req?.clientIp, |
|
|
|
ip: req?.clientIp, |
|
|
|