I think it's done?
This commit is contained in:
30
src/ObjectCollections/RulesetCollection.ts
Normal file
30
src/ObjectCollections/RulesetCollection.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import MongoStoredObjectCollection from "./MongoStoredObjectCollection";
|
||||
import mongo from "mongodb";
|
||||
import {DEFAULT_RULESET, DEFAULT_RULESET_NAME, RulesetSchema} from "../rulesets";
|
||||
import {getMongoObjectCollection} from "../database";
|
||||
import Ruleset from "../Objects/Ruleset";
|
||||
|
||||
type RulesetMongoData = RulesetSchema;
|
||||
|
||||
class RulesetCollection extends MongoStoredObjectCollection<RulesetMongoData> {
|
||||
constructor(collectionClient: mongo.Collection) {
|
||||
super(collectionClient);
|
||||
}
|
||||
|
||||
private async rulesetFrom(data: RulesetMongoData): Promise<Ruleset> {
|
||||
return new Ruleset(data.id, data);
|
||||
}
|
||||
|
||||
async read(id: string): Promise<Ruleset> {
|
||||
if (id === DEFAULT_RULESET_NAME) {
|
||||
return new Ruleset(DEFAULT_RULESET_NAME, DEFAULT_RULESET);
|
||||
}
|
||||
else {
|
||||
const foundRuleset = await this.mongoRead(id);
|
||||
return this.rulesetFrom(foundRuleset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const RulesetCollectionSingleton = new RulesetCollection(getMongoObjectCollection("users"));
|
||||
export default RulesetCollectionSingleton;
|
||||
Reference in New Issue
Block a user