diff --git a/Sources/App/Model/User.swift b/Sources/App/Model/User.swift index f2bca41..7520b80 100644 --- a/Sources/App/Model/User.swift +++ b/Sources/App/Model/User.swift @@ -1,7 +1,18 @@ import FluentSQLiteDriver +import FluentSQL import Vapor +private extension FieldProperty { + convenience init(_ key: User.Key) { + self.init(key: key.key) + } +} +private extension OptionalParentProperty { + convenience init(_ key: User.Key) { + self.init(key: key.key) + } +} /// A registered user final class User: Model { @@ -26,19 +37,19 @@ final class User: Model { var id: UUID? /// The user's full name. - @Field(key: Key.name.key) + @Field(.name) var name: String /// The hash of the user's password - @Field(key: Key.hash.key) + @Field(.hash) var passwordHash: String /// The user's total points - @Field(key: Key.points.key) + @Field(.points) var points: Int - // Example of an optional parent relation. - @OptionalParent(key: Key.table.key) + /// The table to which this user currently belongs + @OptionalParent(.table) var table: Table? init() { }