From 240e1d5813fa307a713b71fe6f3f22edf7b1bc2f Mon Sep 17 00:00:00 2001 From: Robyn MacCallum Date: Tue, 30 Nov 2021 22:58:40 -0500 Subject: [PATCH] Don't flag deleted users as duplicates (#181) * Don't flag deleted users as duplicates * Fix nearby linting error * Apply user filter to deleted users as well * Revert "Apply user filter to deleted users as well" This reverts commit 1633ee265fab799eb0c227dbc8a81236d5f0f1cd. * Only throw error if any duplicates are not deleted * Rename processedUsers to processedActiveUsers * Update src/services/sync.service.ts Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> * Update src/services/sync.service.ts Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> * Update src/services/sync.service.ts Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> --- src/services/sync.service.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/services/sync.service.ts b/src/services/sync.service.ts index 196b3e04..81623c85 100644 --- a/src/services/sync.service.ts +++ b/src/services/sync.service.ts @@ -114,19 +114,31 @@ export class SyncService { private removeDuplicateUsers(users: UserEntry[]) { const uniqueUsers = new Array(); - const processedUsers = new Map(); + const processedActiveUsers = new Map(); + const processedDeletedUsers = new Map(); const duplicateEmails = new Array(); // UserEntrys with the same email are ignored if their properties are the same - // UserEntrys with the same email but different properties will throw an error + // UserEntrys with the same email but different properties will throw an error, unless they are all in a deleted state. users.forEach(u => { - if (processedUsers.has(u.email)) { - if (processedUsers.get(u.email) != JSON.stringify(u)) { + if (processedActiveUsers.has(u.email)) { + if (processedActiveUsers.get(u.email) !== JSON.stringify(u)) { duplicateEmails.push(u.email); } } else { - uniqueUsers.push(u); - processedUsers.set(u.email, JSON.stringify(u)); + if (!u.deleted) { + // Check that active UserEntry does not conflict with a deleted UserEntry + if (processedDeletedUsers.has(u.email)) { + duplicateEmails.push(u.email); + } else { + processedActiveUsers.set(u.email, JSON.stringify(u)); + uniqueUsers.push(u); + } + } else { + // UserEntrys with duplicate email will not throw an error if they are all deleted. They will be synced. + processedDeletedUsers.set(u.email, JSON.stringify(u)); + uniqueUsers.push(u); + } } });