You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
3.6 KiB
99 lines
3.6 KiB
// Generated by SwiftModelGenerator
|
|
// Do not modify this file manually
|
|
|
|
import Foundation
|
|
import LeStorage
|
|
|
|
public class BasePurchase: SyncedModelObject, SyncedStorable {
|
|
|
|
public static func resourceName() -> String { return "purchases" }
|
|
public static func tokenExemptedMethods() -> [HTTPMethod] { return [] }
|
|
public static var copyServerResponse: Bool = false
|
|
|
|
public var id: UInt64 = 0
|
|
public var user: String = ""
|
|
public var purchaseDate: Date = Date()
|
|
public var productId: String = ""
|
|
public var quantity: Int? = nil
|
|
public var revocationDate: Date? = nil
|
|
public var expirationDate: Date? = nil
|
|
|
|
public init(
|
|
id: UInt64 = 0,
|
|
user: String = "",
|
|
purchaseDate: Date = Date(),
|
|
productId: String = "",
|
|
quantity: Int? = nil,
|
|
revocationDate: Date? = nil,
|
|
expirationDate: Date? = nil
|
|
) {
|
|
super.init()
|
|
self.id = id
|
|
self.user = user
|
|
self.purchaseDate = purchaseDate
|
|
self.productId = productId
|
|
self.quantity = quantity
|
|
self.revocationDate = revocationDate
|
|
self.expirationDate = expirationDate
|
|
}
|
|
required public override init() {
|
|
super.init()
|
|
}
|
|
|
|
public enum CodingKeys: String, CodingKey {
|
|
case id = "id"
|
|
case user = "user"
|
|
case purchaseDate = "purchaseDate"
|
|
case productId = "productId"
|
|
case quantity = "quantity"
|
|
case revocationDate = "revocationDate"
|
|
case expirationDate = "expirationDate"
|
|
}
|
|
|
|
|
|
required init(from decoder: Decoder) throws {
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
self.id = try container.decodeIfPresent(UInt64.self, forKey: .id) ?? 0
|
|
self.user = try container.decodeEncrypted(key: .user)
|
|
self.purchaseDate = try container.decodeIfPresent(Date.self, forKey: .purchaseDate) ?? Date()
|
|
self.productId = try container.decodeIfPresent(String.self, forKey: .productId) ?? ""
|
|
self.quantity = try container.decodeIfPresent(Int.self, forKey: .quantity) ?? nil
|
|
self.revocationDate = try container.decodeIfPresent(Date.self, forKey: .revocationDate) ?? nil
|
|
self.expirationDate = try container.decodeIfPresent(Date.self, forKey: .expirationDate) ?? nil
|
|
try super.init(from: decoder)
|
|
}
|
|
|
|
public override func encode(to encoder: Encoder) throws {
|
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
try container.encode(self.id, forKey: .id)
|
|
try container.encodeAndEncryptIfPresent(self.user.data(using: .utf8), forKey: .user)
|
|
try container.encode(self.purchaseDate, forKey: .purchaseDate)
|
|
try container.encode(self.productId, forKey: .productId)
|
|
try container.encode(self.quantity, forKey: .quantity)
|
|
try container.encode(self.revocationDate, forKey: .revocationDate)
|
|
try container.encode(self.expirationDate, forKey: .expirationDate)
|
|
try super.encode(to: encoder)
|
|
}
|
|
|
|
func userValue() -> CustomUser? {
|
|
return Store.main.findById(user)
|
|
}
|
|
|
|
public func copy(from other: any Storable) {
|
|
guard let purchase = other as? BasePurchase else { return }
|
|
self.id = purchase.id
|
|
self.user = purchase.user
|
|
self.purchaseDate = purchase.purchaseDate
|
|
self.productId = purchase.productId
|
|
self.quantity = purchase.quantity
|
|
self.revocationDate = purchase.revocationDate
|
|
self.expirationDate = purchase.expirationDate
|
|
}
|
|
|
|
public static func relationships() -> [Relationship] {
|
|
return [
|
|
Relationship(type: CustomUser.self, keyPath: \BasePurchase.user),
|
|
]
|
|
}
|
|
|
|
} |