diff --git a/OPassData/General/DateInRegionTransform.swift b/OPassData/General/DateInRegionTransform.swift index 33e79332..c5feca61 100644 --- a/OPassData/General/DateInRegionTransform.swift +++ b/OPassData/General/DateInRegionTransform.swift @@ -17,6 +17,6 @@ struct StringToDate: TransformFunction { struct IntToDate: TransformFunction { static func transform(_ time: Int) -> DateInRegion { - return DateInRegion(seconds: TimeInterval(time), region: Region.current) + return DateInRegion(seconds: .init(time), region: .current) } } diff --git a/OPassData/Model/Attendee.swift b/OPassData/Model/Attendee.swift index da181d2a..73e11cb6 100644 --- a/OPassData/Model/Attendee.swift +++ b/OPassData/Model/Attendee.swift @@ -20,7 +20,7 @@ struct Attendee: Hashable, Codable, Identifiable { @Transform var scenarios: OrderedDictionary private enum CodingKeys: String, CodingKey { - case id + case id = "_id" case eventId = "event_id" case userId = "user_id" case token diff --git a/OPassData/Model/Scenario.swift b/OPassData/Model/Scenario.swift index 534676ff..193f1d89 100644 --- a/OPassData/Model/Scenario.swift +++ b/OPassData/Model/Scenario.swift @@ -30,6 +30,23 @@ struct Scenario: Hashable, Codable, Identifiable { case attributes = "attr" case used } + + init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + self.id = try container.decode(String.self, forKey: .id) + self.order = try container.decode(Int.self, forKey: .order) + self.title = try container.decode(LocalizedCodeString.self, forKey: .title) + self.disabled = try container.decodeIfPresent(String.self, forKey: .disabled) + self._available = try container.decode(Transform.self, forKey: .available) + self._expire = try container.decode(Transform.self, forKey: .expire) + self.countdown = try container.decode(Int.self, forKey: .countdown) + self.attributes = try container.decode([String : String].self, forKey: .attributes) + if let used = try? container.decode(Int.self, forKey: .used) { + self.used = .init(seconds: .init(used), region: .current) + } else if let used = try? container.decode(DateInRegion.self, forKey: .used) { + self.used = used + } else { self.used = nil } + } } extension Scenario {