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
This commit is contained in:
Maciej Ziarkowski 2020-07-17 16:27:40 +02:00
parent 63268ebca4
commit 07cdae8899
2 changed files with 2 additions and 2 deletions

View File

@ -18,7 +18,7 @@ mockEditHistory.__setHistory = function(mockHistoryData: EditHistoryEntry[]) {
}; };
function hasDeletions(json) { 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<EditHistoryEntry[]> { mockEditHistory.getHistoryAfterId = function(id: string, count: number, filterDeletions: boolean): Promise<EditHistoryEntry[]> {

View File

@ -14,7 +14,7 @@ const baseQuery = `
JOIN users ON logs.user_id = users.user_id`; JOIN users ON logs.user_id = users.user_id`;
const deletionCondition = ` 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<EditHistoryEntry[]> { export function getHistoryAfterId(id: string, count: number, filterDeletions: boolean = false): Promise<EditHistoryEntry[]> {