Schafkopf-Server/Sources/App/Model/User.swift
2021-12-22 22:11:37 +01:00

56 lines
1.1 KiB
Swift

import FluentSQLiteDriver
import Vapor
/// A registered user
final class User: Model {
enum Key: String {
case id = "id"
case name = "name"
case hash = "hash"
case points = "points"
case table = "table_id"
var key: FieldKey {
.init(stringLiteral: rawValue)
}
}
/// The name of the SQLite table
static let schema = "user"
/// The unique identifier for this user.
@ID(key: .id)
var id: UUID?
/// The user's full name.
@Field(key: Key.name.key)
var name: String
/// The hash of the user's password
@Field(key: Key.hash.key)
var passwordHash: String
/// The user's total points
@Field(key: Key.points.key)
var points: Int
// Example of an optional parent relation.
@OptionalParent(key: Key.table.key)
var table: Table?
init() { }
/// Creates a new user.
init(id: UUID? = nil, name: String, hash: String) {
self.id = id
self.name = name
self.passwordHash = hash
self.points = 0
}
}
//extension User: Content { }