From 6939d35eaf72e1bdcefabadaca74d3c07476d4e2 Mon Sep 17 00:00:00 2001 From: flaviuvsp Date: Wed, 11 Dec 2024 15:11:27 +0200 Subject: [PATCH] Fix issue when sending account steward event --- .../ViewModels/LegacyPlanningViewModel.swift | 18 ++++++------------ .../LegacyPlanningDataSourceInterface.swift | 6 +++--- .../LegacyPlanningRepository.swift | 2 +- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/Permanent/Modules/LegacyPlanning/ViewModels/LegacyPlanningViewModel.swift b/Permanent/Modules/LegacyPlanning/ViewModels/LegacyPlanningViewModel.swift index cb4fb0ac..3c453460 100644 --- a/Permanent/Modules/LegacyPlanning/ViewModels/LegacyPlanningViewModel.swift +++ b/Permanent/Modules/LegacyPlanning/ViewModels/LegacyPlanningViewModel.swift @@ -59,6 +59,7 @@ class LegacyPlanningViewModel: ViewModelInterface { case .success(let steward): self?.selectedSteward = LegacyPlanningSteward(id: steward.directiveId, name: name, email: email, status: .pending, type: .archive) self?.stewardWasUpdated?(true) + self?.trackUpdateEvents(action: DirectiveEventAction.create, entityId: steward.directiveId) } self?.isLoading?(false) @@ -73,9 +74,10 @@ class LegacyPlanningViewModel: ViewModelInterface { if let error = error as? APIError { self?.showError?(error) } - case .success: - self?.selectedSteward = LegacyPlanningSteward(name: name, email: email, status: .pending, type: .account) + case .success(let steward): + self?.selectedSteward = LegacyPlanningSteward(id: steward.legacyContactId, name: steward.name, email: steward.email, status: .pending, type: .account) self?.stewardWasUpdated?(true) + self?.trackUpdateEvents(action: LegacyContactEventAction.create, entityId: self?.selectedSteward?.id) } self?.isLoading?(false) @@ -159,11 +161,7 @@ class LegacyPlanningViewModel: ViewModelInterface { self?.showError?(error) } case .success(let steward): - if(self?.selectedSteward == nil) { - self?.trackUpdateEvents(action: DirectiveEventAction.create, entityId: steward.directiveId) - } else { - self?.trackUpdateEvents(action: DirectiveEventAction.update, entityId: steward.directiveId) - } + self?.trackUpdateEvents(action: DirectiveEventAction.update, entityId: steward.directiveId) self?.selectedSteward = LegacyPlanningSteward(id: steward.directiveId, name: name, email: email, status: .pending, type: .archive) self?.stewardWasUpdated?(true) } @@ -181,11 +179,7 @@ class LegacyPlanningViewModel: ViewModelInterface { self?.showError?(error) } case .success: - if(self?.selectedSteward == nil) { - self?.trackUpdateEvents(action: LegacyContactEventAction.create, entityId: self?.selectedSteward?.id) - } else { - self?.trackUpdateEvents(action: LegacyContactEventAction.update, entityId: self?.selectedSteward?.id) - } + self?.trackUpdateEvents(action: LegacyContactEventAction.update, entityId: self?.selectedSteward?.id) self?.selectedSteward = LegacyPlanningSteward(id: self?.selectedSteward?.id ?? "", name: name ?? "", email: stewardEmail ?? "", status: .pending, type: .account) self?.stewardWasUpdated?(true) } diff --git a/Permanent/Services/Repositories/Datasources/Remote/LegacyPlanningDataSourceInterface.swift b/Permanent/Services/Repositories/Datasources/Remote/LegacyPlanningDataSourceInterface.swift index d5c7a0fb..725dd6b2 100644 --- a/Permanent/Services/Repositories/Datasources/Remote/LegacyPlanningDataSourceInterface.swift +++ b/Permanent/Services/Repositories/Datasources/Remote/LegacyPlanningDataSourceInterface.swift @@ -11,7 +11,7 @@ protocol LegacyPlanningDataSourceInterface { func setArchiveSteward(archiveId: Int, stewardEmail: String, note: String, completion: @escaping (Result) -> Void) func updateArchiveSteward(directiveId: String, stewardEmail: String, note: String, completion: @escaping (Result) -> Void) func getLegacyContact(completion: @escaping (Result<[AccountSteward]?, Error>) -> Void) - func setAccountSteward(name: String, stewardEmail: String, completion: @escaping (Result) -> Void) + func setAccountSteward(name: String, stewardEmail: String, completion: @escaping (Result) -> Void) func updateAccountSteward(legacyContactId: String, name: String?, stewardEmail: String?, completion: @escaping (Result) -> Void) } @@ -86,7 +86,7 @@ class LegacyPlanningDataSource: LegacyPlanningDataSourceInterface { } } - func setAccountSteward(name: String, stewardEmail: String, completion: @escaping (Result) -> Void) { + func setAccountSteward(name: String, stewardEmail: String, completion: @escaping (Result) -> Void) { let setAccountStewardOperation = APIOperation(LegacyPlanningEndpoint.setAccountSteward(name: name, stewardEmail: stewardEmail)) setAccountStewardOperation.execute(in: APIRequestDispatcher()) { result in switch result { @@ -95,7 +95,7 @@ class LegacyPlanningDataSource: LegacyPlanningDataSourceInterface { completion(.failure(APIError.invalidResponse)) return } - completion(.success(true)) + completion(.success(model)) return case .error(let error, _): completion(.failure(error ?? APIError.invalidResponse)) diff --git a/Permanent/Services/Repositories/LegacyPlanningRepository.swift b/Permanent/Services/Repositories/LegacyPlanningRepository.swift index 47c67596..1bf7994d 100644 --- a/Permanent/Services/Repositories/LegacyPlanningRepository.swift +++ b/Permanent/Services/Repositories/LegacyPlanningRepository.swift @@ -26,7 +26,7 @@ class LegacyPlanningRepository { remoteDataSource.setArchiveSteward(archiveId: archiveId, stewardEmail: stewardEmail, note: note, completion: completion) } - func setAccountSteward(name: String, stewardEmail: String, completion: @escaping (Result) -> Void) { + func setAccountSteward(name: String, stewardEmail: String, completion: @escaping (Result) -> Void) { remoteDataSource.setAccountSteward(name: name, stewardEmail: stewardEmail, completion: completion) }