From 07cdae8899af6b170dfa09edc67350c34c4f1e96 Mon Sep 17 00:00:00 2001 From: Maciej Ziarkowski Date: Fri, 17 Jul 2020 16:27:40 +0200 Subject: [PATCH] Only detect deletions where attribute set to null For fields where an empty value is represented by null, it is easy to detect deletions. For other fields e.g. arrays, more complex logic needs to be developed later --- app/src/api/dataAccess/__mocks__/editHistory.ts | 2 +- app/src/api/dataAccess/editHistory.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/api/dataAccess/__mocks__/editHistory.ts b/app/src/api/dataAccess/__mocks__/editHistory.ts index 7c2320b7..735e71c1 100644 --- a/app/src/api/dataAccess/__mocks__/editHistory.ts +++ b/app/src/api/dataAccess/__mocks__/editHistory.ts @@ -18,7 +18,7 @@ mockEditHistory.__setHistory = function(mockHistoryData: EditHistoryEntry[]) { }; function hasDeletions(json) { - return Object.values(json).some(x => x === null || (Array.isArray(x) && x.length === 0)) + return Object.values(json).some(x => x === null); } mockEditHistory.getHistoryAfterId = function(id: string, count: number, filterDeletions: boolean): Promise { diff --git a/app/src/api/dataAccess/editHistory.ts b/app/src/api/dataAccess/editHistory.ts index 215c3bb4..eba1cfa1 100644 --- a/app/src/api/dataAccess/editHistory.ts +++ b/app/src/api/dataAccess/editHistory.ts @@ -14,7 +14,7 @@ const baseQuery = ` JOIN users ON logs.user_id = users.user_id`; const deletionCondition = ` - EXISTS (SELECT * from jsonb_each(forward_patch) WHERE value IN ('null', '[]')) + EXISTS (SELECT * from jsonb_each(forward_patch) WHERE value = 'null' ) `; export function getHistoryAfterId(id: string, count: number, filterDeletions: boolean = false): Promise {