From c0a23a0df82d4ea1a070df851e578a479af1c80a Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 27 Aug 2024 08:07:50 +0200 Subject: [PATCH 1/3] feat: refs #7287 First commit --- mylogger.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mylogger.js b/mylogger.js index 601dbdf..40e94be 100644 --- a/mylogger.js +++ b/mylogger.js @@ -81,7 +81,8 @@ module.exports = class MyLogger { newInstance = ?, changedModelId = ?, changedModelValue = ?, - summaryId = ?` + summaryId = ?, + reason = ?` ); logInfo.fetchStmt = await db.prepare( `SELECT id FROM ${sqlTable} -- 2.40.1 From fda5726f55e661b5e338b50a2a27256375b42496 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 27 Aug 2024 09:39:11 +0200 Subject: [PATCH 2/3] feat: refs #7287 Final commit --- config/logs.yml | 1 + lib/model-loader.js | 15 ++++++++------- mylogger.js | 7 +++++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/config/logs.yml b/config/logs.yml index 6d35364..a810a63 100644 --- a/config/logs.yml +++ b/config/logs.yml @@ -3,6 +3,7 @@ logRelation: true logMainShowField: false upperCaseTable: true userField: editorFk +reasonField: motivation rowExcludeField: logExclude excludeRegex: '__$' showFields: diff --git a/lib/model-loader.js b/lib/model-loader.js index 0c3a998..4317493 100644 --- a/lib/model-loader.js +++ b/lib/model-loader.js @@ -94,9 +94,10 @@ module.exports = class ModelLoader { ]; const globalProps = [ 'userField', - 'rowExcludeField' + 'rowExcludeField', + 'reasonField' ]; - + for (const [schema, table, tableInfo] of schemaMap) { const tableConf = tableInfo.conf; @@ -109,20 +110,19 @@ module.exports = class ModelLoader { : conf[prop]; // Fetch columns & types - + const columns = new Set(); Object.assign (tableInfo, { castTypes: new Map(), columns }); - + if (tableConf.types) for (const col in tableConf.types) tableInfo.castTypes.set(col, tableConf.types[col]); - + const [dbCols] = await db.query( - `SELECT - COLUMN_NAME \`col\`, + `SELECT COLUMN_NAME \`col\`, DATA_TYPE \`type\` FROM information_schema.\`COLUMNS\` WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?`, @@ -131,6 +131,7 @@ module.exports = class ModelLoader { const exclude = new Set(tableConf.exclude); exclude.add(tableInfo.userField); + exclude.add(tableInfo.reasonField); for (const {col, type} of dbCols) { const isExcluded = diff --git a/mylogger.js b/mylogger.js index 40e94be..d8ccfa7 100644 --- a/mylogger.js +++ b/mylogger.js @@ -98,7 +98,8 @@ module.exports = class MyLogger { creationDate = ?, oldInstance = ?, changedModelValue = ?, - summaryId = ? + summaryId = ?, + reason = ? WHERE id = ?` ); } @@ -543,6 +544,7 @@ module.exports = class MyLogger { oldInstance, modelValue, summaryId, + row[tableInfo.reasonField] ?? null, deleteRow.id ]); } @@ -559,7 +561,8 @@ module.exports = class MyLogger { newI ? JSON.stringify(newI) : null, modelId, modelValue, - summaryId + summaryId, + row[tableInfo.reasonField] ?? null ]); } -- 2.40.1 From 35c92e43ad3eb1b3ac6c63dba8c46e9811e351e7 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 27 Aug 2024 09:55:05 +0200 Subject: [PATCH 3/3] feat: refs #7287 Minor change --- mylogger.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mylogger.js b/mylogger.js index d8ccfa7..9cb7155 100644 --- a/mylogger.js +++ b/mylogger.js @@ -533,6 +533,7 @@ module.exports = class MyLogger { ); try { + const reasonField = row[tableInfo.reasonField] ?? null; if (isDelete) { [[deleteRow]] = await logInfo.fetchStmt.execute([ modelName, modelId, originFk @@ -544,7 +545,7 @@ module.exports = class MyLogger { oldInstance, modelValue, summaryId, - row[tableInfo.reasonField] ?? null, + reasonField, deleteRow.id ]); } @@ -562,7 +563,7 @@ module.exports = class MyLogger { modelId, modelValue, summaryId, - row[tableInfo.reasonField] ?? null + reasonField ]); } -- 2.40.1