Reorganize project. Add folder for shared code between backend/dashboard. Switch from jest to ava for tests.
This commit is contained in:
parent
80a82fe348
commit
16111bbe84
162 changed files with 11056 additions and 9900 deletions
28
backend/src/data/BaseGuildRepository.ts
Normal file
28
backend/src/data/BaseGuildRepository.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { BaseRepository } from "./BaseRepository";
|
||||
|
||||
export class BaseGuildRepository extends BaseRepository {
|
||||
private static guildInstances: Map<string, any>;
|
||||
|
||||
protected guildId: string;
|
||||
|
||||
constructor(guildId: string) {
|
||||
super();
|
||||
this.guildId = guildId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a cached instance of the inheriting class for the specified guildId,
|
||||
* or creates a new instance if one doesn't exist yet
|
||||
*/
|
||||
public static getGuildInstance<T extends typeof BaseGuildRepository>(this: T, guildId: string): InstanceType<T> {
|
||||
if (!this.guildInstances) {
|
||||
this.guildInstances = new Map();
|
||||
}
|
||||
|
||||
if (!this.guildInstances.has(guildId)) {
|
||||
this.guildInstances.set(guildId, new this(guildId));
|
||||
}
|
||||
|
||||
return this.guildInstances.get(guildId) as InstanceType<T>;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue