diff --git a/SportsTime/Core/Services/PollService.swift b/SportsTime/Core/Services/PollService.swift index 6dd8821..19d864a 100644 --- a/SportsTime/Core/Services/PollService.swift +++ b/SportsTime/Core/Services/PollService.swift @@ -234,13 +234,26 @@ actor PollService { throw PollError.notPollOwner // Using this error for now - voter can only update own vote } - var updatedVote = vote - updatedVote.modifiedAt = Date() + // Fetch the existing record to get the server's changeTag + let recordID = CKRecord.ID(recordName: vote.id.uuidString) + let existingRecord: CKRecord + do { + existingRecord = try await publicDatabase.record(for: recordID) + } catch let error as CKError { + throw mapCloudKitError(error) + } catch { + throw PollError.unknown(error) + } - let ckVote = CKPollVote(vote: updatedVote) + // Update the fields on the fetched record + let now = Date() + existingRecord[CKPollVote.rankingsKey] = vote.rankings + existingRecord[CKPollVote.modifiedAtKey] = now do { - try await publicDatabase.save(ckVote.record) + try await publicDatabase.save(existingRecord) + var updatedVote = vote + updatedVote.modifiedAt = now return updatedVote } catch let error as CKError { throw mapCloudKitError(error)