Files
cod-backend/Sources/App/Models/Match.swift
2021-08-04 16:32:17 -05:00

108 lines
2.6 KiB
Swift

import Fluent
import Vapor
final class Match: Model, Content {
static let schema = "match"
@ID(key: .id)
var id: UUID?
@Field(key: "map")
var map: String?
@Field(key: "win")
var win: Bool
@Field(key: "date")
var date: Date
@Field(key: "roundsWon")
var roundsWon: Int?
@Field(key: "roundsLost")
var roundsLost: Int?
@Field(key: "codGame")
var codGame: String?
@Field(key: "notes")
var notes: String?
@Field(key: "players")
var players: String?
@Field(key: "sweaty")
var sweaty: Bool?
@Field(key: "finalKillRuinedPlayerId")
var finalKillRuinedPlayerId: Int?
@Field(key: "numberOfFinalKillsRuined")
var numberOfFinalKillsRuined: Int?
@Field(key: "competitive")
var competitive: Bool
@Field(key: "gameMode")
var gameMode: Int
init() { }
init(id: UUID? = nil, map:String?, win:Bool, date:Date, roundsWon:Int?, roundsLost:Int?, codGame:String?, notes:String?, players:String?, sweaty:Bool?, finalKillRuinedPlayerId:Int?, numberOfFinalKillsRuined:Int?,competitive:Bool, gameMode:Int) {
self.id = id
self.map = map
self.win = win
self.date = date
self.roundsWon = roundsWon
self.roundsLost = roundsLost
self.codGame = codGame;
self.notes = notes;
self.players = players
self.sweaty = sweaty
self.finalKillRuinedPlayerId = finalKillRuinedPlayerId
self.numberOfFinalKillsRuined = numberOfFinalKillsRuined
self.competitive = competitive
self.gameMode = gameMode
}
func update( newMatch:Match) {
guard let _ = newMatch.id else {
return
}
self.map = newMatch.map
self.win = newMatch.win
self.date = newMatch.date
self.roundsWon = newMatch.roundsWon
self.roundsLost = newMatch.roundsLost
self.codGame = newMatch.codGame;
self.notes = newMatch.notes;
self.players = newMatch.players
self.sweaty = newMatch.sweaty
self.finalKillRuinedPlayerId = newMatch.finalKillRuinedPlayerId
self.numberOfFinalKillsRuined = newMatch.numberOfFinalKillsRuined
self.competitive = newMatch.competitive
self.gameMode = newMatch.gameMode
}
var playerList:[Int] {
return players?.components(separatedBy: ",").map({ (playerId) -> Int in
(Int(playerId.trimmingCharacters(in: .whitespaces) ) ?? -1)
}) ?? []
}
}
//extension Match {
// struct Create: Content {
// }
//}