Skip to content

Commit

Permalink
Fix issue when sending account steward event
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviuvsp committed Dec 11, 2024
1 parent f5c7119 commit 6939d35
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ protocol LegacyPlanningDataSourceInterface {
func setArchiveSteward(archiveId: Int, stewardEmail: String, note: String, completion: @escaping (Result<ArchiveSteward, Error>) -> Void)
func updateArchiveSteward(directiveId: String, stewardEmail: String, note: String, completion: @escaping (Result<ArchiveSteward, Error>) -> Void)
func getLegacyContact(completion: @escaping (Result<[AccountSteward]?, Error>) -> Void)
func setAccountSteward(name: String, stewardEmail: String, completion: @escaping (Result<Bool, Error>) -> Void)
func setAccountSteward(name: String, stewardEmail: String, completion: @escaping (Result<AccountSteward, Error>) -> Void)
func updateAccountSteward(legacyContactId: String, name: String?, stewardEmail: String?, completion: @escaping (Result<AccountSteward?, Error>) -> Void)
}

Expand Down Expand Up @@ -86,7 +86,7 @@ class LegacyPlanningDataSource: LegacyPlanningDataSourceInterface {
}
}

func setAccountSteward(name: String, stewardEmail: String, completion: @escaping (Result<Bool, Error>) -> Void) {
func setAccountSteward(name: String, stewardEmail: String, completion: @escaping (Result<AccountSteward, Error>) -> Void) {
let setAccountStewardOperation = APIOperation(LegacyPlanningEndpoint.setAccountSteward(name: name, stewardEmail: stewardEmail))
setAccountStewardOperation.execute(in: APIRequestDispatcher()) { result in
switch result {
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Bool, Error>) -> Void) {
func setAccountSteward(name: String, stewardEmail: String, completion: @escaping (Result<AccountSteward, Error>) -> Void) {
remoteDataSource.setAccountSteward(name: name, stewardEmail: stewardEmail, completion: completion)
}

Expand Down

0 comments on commit 6939d35

Please sign in to comment.