Cleaned up naming scheme and finalised StoredPlayer, stats updaters, and generic templates for StoredObjectCollection and StoredObject
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
import mongoose from "mongoose";
|
||||
import {
|
||||
IPlayerStats,
|
||||
IPlayerStatsDoc, OutcomeType,
|
||||
OutcomeType,
|
||||
PlayerGameResults,
|
||||
PlayerStats,
|
||||
PlayerStatsMongoObjectInterface,
|
||||
PlayerStatsSchema, PlayerStatsUpdater
|
||||
PlayerStatsUpdater
|
||||
} from "./stats";
|
||||
import {
|
||||
getMongoObjectCollection,
|
||||
MongoStoredObject, MongoStoredObjectCollection,
|
||||
} from "./utils";
|
||||
import {CellValue} from "../controllers/statsController";
|
||||
@@ -65,9 +63,10 @@ class MongoStoredPlayer extends MongoStoredObject implements StoredPlayer {
|
||||
}
|
||||
|
||||
async updateStats(playerGameResults: PlayerGameResults & {outcome: OutcomeType}, ruleset: Ruleset) {
|
||||
const statsInterface = new PlayerStatsMongoObjectInterface(this.data.stats);
|
||||
await statsInterface.updateStats(playerGameResults, ruleset);
|
||||
const statsUpdater = new PlayerStatsUpdater(this.data.stats);
|
||||
await statsUpdater.updateStats(playerGameResults, ruleset);
|
||||
}
|
||||
}
|
||||
|
||||
export default PlayerCollection;
|
||||
const StoredPlayers = new MongoStoredPlayerCollection(getMongoObjectCollection("players"));
|
||||
export default StoredPlayers;
|
||||
@@ -137,8 +137,8 @@ class BaseStatsUpdater {
|
||||
}
|
||||
}
|
||||
|
||||
class RulesetMongoObjectInterface {
|
||||
private data: Ruleset;
|
||||
class MongoStoredRuleset {
|
||||
private readonly data: Ruleset;
|
||||
constructor(data: Ruleset) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import mongo, {MongoClient, Db} from "mongodb";
|
||||
import Settings from "../server-config.json";
|
||||
import {PlayerData, StoredPlayer} from "./player";
|
||||
|
||||
let SessionDbClient: Db;
|
||||
export async function initMongoSessionClient() {
|
||||
@@ -10,7 +9,7 @@ export async function initMongoSessionClient() {
|
||||
}
|
||||
return SessionDbClient;
|
||||
}
|
||||
export async function getMongoObjectCollection(collectionName: string) {
|
||||
export function getMongoObjectCollection(collectionName: string) {
|
||||
if (SessionDbClient === undefined) {
|
||||
throw new MongoError("Cannot retrieve a collection before the session client has been initialised!");
|
||||
}
|
||||
@@ -19,7 +18,7 @@ export async function getMongoObjectCollection(collectionName: string) {
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class MongoStoredObjectCollection<T extends MongoStoredObject> {
|
||||
export abstract class MongoStoredObjectCollection<T extends MongoStoredObject<any>> {
|
||||
protected mongoDbClientCollection: mongo.Collection;
|
||||
protected constructor(collectionClient: mongo.Collection) {
|
||||
this.mongoDbClientCollection = collectionClient;
|
||||
@@ -36,14 +35,14 @@ export abstract class MongoStoredObjectCollection<T extends MongoStoredObject> {
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class MongoStoredObject {
|
||||
protected constructor(protected data: {_id: string} & any) {}
|
||||
export abstract class MongoStoredObject<T> {
|
||||
protected constructor(protected data: {_id: string} & T) {}
|
||||
|
||||
id(): string {
|
||||
return this.data._id;
|
||||
}
|
||||
|
||||
rawData(): PlayerData {
|
||||
rawData(): T {
|
||||
return this.data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user