Massive restructuring, most of the progress on reorganising Data Access Layer etc. finished. Gotta get the app back up and running now

This commit is contained in:
Daniel Ledda
2020-07-17 11:40:53 +02:00
parent cef6249c09
commit 4542036b77
33 changed files with 784 additions and 852 deletions

View File

@@ -0,0 +1,33 @@
import {Ruleset} from "../rulesets";
import {AccountStatsMongoData, OutcomeType, PlayerGameResults} from "./DefaultStatsMongoData";
import {UpdateError} from "../errors";
import StatsUpdater from "./StatsUpdater";
class AccountStats {
private data?: AccountStatsMongoData;
private readonly updater: StatsUpdater;
constructor(data?: AccountStatsMongoData) {
if (data) {
this.data = data;
}
this.updater = new StatsUpdater();
}
use(data: AccountStatsMongoData) {
this.data = data;
this.updater.use(data);
}
updateStats(playerGameResults: PlayerGameResults & {outcome: OutcomeType}, ruleset: Ruleset): void {
if (this.data) {
this.updater.updateStats(playerGameResults, 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.`);
}
}
}
export default AccountStats;