From a67ed66e2248f341715fcf6a72c97858d8f928d6 Mon Sep 17 00:00:00 2001 From: Nicolas Chambrier Date: Tue, 5 Sep 2017 15:47:40 +0200 Subject: [PATCH] feat(edit-logs): ensures editLog's diff is flat --- server/lib/edit-logs.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/lib/edit-logs.js b/server/lib/edit-logs.js index 761ff8cb..e58361e3 100644 --- a/server/lib/edit-logs.js +++ b/server/lib/edit-logs.js @@ -93,8 +93,8 @@ const middleware = schema => { } else { // If the model was updated, we only store a diff - const diff = deepDiff(this._original, data) - editLog.diff = diff + const changes = deepDiff(this._original, data) + editLog.diff = flattenDiff(changes) } this._elLogToBeSaved = new EditLog(editLog) @@ -129,6 +129,8 @@ const middleware = schema => { } +const flattenDiff = diffs => diffs.map(diff => Array.isArray(diff) && diff.length === 1 ? diff[0] : diff) + module.exports = { EditLogSchema,