From cd7acd704893508ed9ff013c46589ed7db0ff135 Mon Sep 17 00:00:00 2001 From: "mathieu J." Date: Tue, 17 Dec 2024 20:27:39 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20(AccountKit):=20Ignore=20non-up?= =?UTF-8?q?datable=20fields=20in=20Caregiver=20updates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Database/DatabaseOperations.swift | 12 +++++++++--- .../Managers/Caregivers/CaregiverManager.swift | 5 +++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Modules/AccountKit/Sources/Database/DatabaseOperations.swift b/Modules/AccountKit/Sources/Database/DatabaseOperations.swift index 8ec9fdd22..ae02418e5 100644 --- a/Modules/AccountKit/Sources/Database/DatabaseOperations.swift +++ b/Modules/AccountKit/Sources/Database/DatabaseOperations.swift @@ -143,14 +143,20 @@ public class DatabaseOperations { self.listenerRegistrations.removeAll() } - public func update(data: T, in collection: DatabaseCollection) -> AnyPublisher { + public func update(data: T, in collection: DatabaseCollection, ignoringFields: [String] = []) -> AnyPublisher { Future { promise in let docRef = self.database.collection(collection.rawValue).document(data.id!) do { - try docRef.setData(from: data, merge: true) { error in + var dataDict = try Firestore.Encoder().encode(data) + + for field in ignoringFields { + dataDict.removeValue(forKey: field) + } + + docRef.updateData(dataDict) { error in if let error { - log.error("\(error.localizedDescription)") + log.error("Update failed for document \(String(describing: data.id!)): \(error.localizedDescription)") promise(.failure(DatabaseError.customError(error.localizedDescription))) } else { log.info("Document \(String(describing: data.id!)) updated successfully in \(collection.rawValue). 🎉") diff --git a/Modules/AccountKit/Sources/Managers/Caregivers/CaregiverManager.swift b/Modules/AccountKit/Sources/Managers/Caregivers/CaregiverManager.swift index 58d951983..1029dfb6c 100644 --- a/Modules/AccountKit/Sources/Managers/Caregivers/CaregiverManager.swift +++ b/Modules/AccountKit/Sources/Managers/Caregivers/CaregiverManager.swift @@ -71,16 +71,17 @@ public class CaregiverManager { public func updateCaregiver(caregiver: inout Caregiver) { caregiver.lastEditedAt = nil - self.dbOps.update(data: caregiver, in: .caregivers) + let ignoredFields: [String] = ["root_owner_uid", "uuid", "created_at"] + self.dbOps.update(data: caregiver, in: .caregivers, ignoringFields: ignoredFields) .sink(receiveCompletion: { completion in if case let .failure(error) = completion { self.fetchError.send(error) } }, receiveValue: { [weak self] updatedCaregiver in guard let self else { return } + AnalyticsManager.logEventCaregiverEdit(caregiver: updatedCaregiver.id!) guard updatedCaregiver.id == self.currentCaregiver.value?.id else { return } self.setCurrentCaregiver(to: updatedCaregiver) - AnalyticsManager.logEventCaregiverEdit(caregiver: updatedCaregiver.id!) log.info("Caregiver successfully updated.") }) .store(in: &self.cancellables) From 1aafe8368e3780500643de6e09dd444ffc889b5d Mon Sep 17 00:00:00 2001 From: "mathieu J." Date: Wed, 18 Dec 2024 14:02:07 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=A8=20(AccountKit):=20Ignore=20non-up?= =?UTF-8?q?datable=20fields=20in=20Carereceiver?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Managers/Carereceivers/CarereceiverManager.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/AccountKit/Sources/Managers/Carereceivers/CarereceiverManager.swift b/Modules/AccountKit/Sources/Managers/Carereceivers/CarereceiverManager.swift index 667c7182f..e9abe678e 100644 --- a/Modules/AccountKit/Sources/Managers/Carereceivers/CarereceiverManager.swift +++ b/Modules/AccountKit/Sources/Managers/Carereceivers/CarereceiverManager.swift @@ -53,7 +53,8 @@ public class CarereceiverManager { public func updateCarereceiver(carereceiver: inout Carereceiver) { carereceiver.lastEditedAt = nil - self.dbOps.update(data: carereceiver, in: .carereceivers) + let ignoredFields: [String] = ["root_owner_uid", "uuid", "created_at"] + self.dbOps.update(data: carereceiver, in: .carereceivers, ignoringFields: ignoredFields) .sink(receiveCompletion: { completion in if case let .failure(error) = completion { self.fetchError.send(error) From 2522d7c784a770ca2d20c9688ab3b72ea66535c4 Mon Sep 17 00:00:00 2001 From: "mathieu J." Date: Wed, 18 Dec 2024 14:04:20 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9C=A8=20(AccountKit):=20Ignore=20non-up?= =?UTF-8?q?datable=20fields=20in=20RootAccount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Managers/RootAccounts/RootAccountManager.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/AccountKit/Sources/Managers/RootAccounts/RootAccountManager.swift b/Modules/AccountKit/Sources/Managers/RootAccounts/RootAccountManager.swift index 4d1a460e0..6a7ba6a80 100644 --- a/Modules/AccountKit/Sources/Managers/RootAccounts/RootAccountManager.swift +++ b/Modules/AccountKit/Sources/Managers/RootAccounts/RootAccountManager.swift @@ -43,7 +43,8 @@ public class RootAccountManager { public func updateRootAccount(rootAccount: inout RootAccount) { rootAccount.lastEditedAt = nil - self.dbOps.update(data: rootAccount, in: .rootAccounts) + let ignoredFields: [String] = ["root_owner_uid", "uuid", "created_at"] + self.dbOps.update(data: rootAccount, in: .rootAccounts, ignoringFields: ignoredFields) .sink( receiveCompletion: { [weak self] completion in if case let .failure(error) = completion {