From fda5726f55e661b5e338b50a2a27256375b42496 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 27 Aug 2024 09:39:11 +0200 Subject: [PATCH] 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 ]); }