I think it's done?
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
import {Ruleset} from "../rulesets";
|
||||
import {RulesetSchema} from "../rulesets";
|
||||
import {AccountStatsMongoData, OutcomeType, PlayerGameResults} from "./DefaultStatsMongoData";
|
||||
import {UpdateError} from "../errors";
|
||||
import StatsUpdater from "./StatsUpdater";
|
||||
import Ruleset from "./Ruleset";
|
||||
|
||||
class AccountStats {
|
||||
private data?: AccountStatsMongoData;
|
||||
private data: AccountStatsMongoData;
|
||||
private readonly updater: StatsUpdater;
|
||||
constructor(data?: AccountStatsMongoData) {
|
||||
if (data) {
|
||||
this.data = data;
|
||||
}
|
||||
constructor(data: AccountStatsMongoData) {
|
||||
this.data = data;
|
||||
this.updater = new StatsUpdater();
|
||||
}
|
||||
|
||||
@@ -18,16 +17,22 @@ class AccountStats {
|
||||
this.updater.use(data);
|
||||
}
|
||||
|
||||
updateStats(playerGameResults: PlayerGameResults & {outcome: OutcomeType}, ruleset: Ruleset): void {
|
||||
updateStats(playerGameResults: (PlayerGameResults & {outcome: OutcomeType})[], ruleset: Ruleset): void {
|
||||
if (this.data) {
|
||||
this.updater.updateStats(playerGameResults, ruleset);
|
||||
this.data.gamesPlayed += 1;
|
||||
for (const playerGameResult of playerGameResults) {
|
||||
this.updater.updateStats(playerGameResult, ruleset);
|
||||
this.data.gamesPlayed += 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new UpdateError(`Cannot update without data! Call the use() method to hydrate the updater with data
|
||||
to analyse.`);
|
||||
}
|
||||
}
|
||||
|
||||
getData(): AccountStatsMongoData {
|
||||
return this.data;
|
||||
}
|
||||
}
|
||||
|
||||
export default AccountStats;
|
||||
Reference in New Issue
Block a user