mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-14 05:45:02 +00:00
Initial work on stats
This commit is contained in:
parent
26c460e67a
commit
56fb432c7c
6 changed files with 347 additions and 4 deletions
backend/src/data
30
backend/src/data/GuildStats.ts
Normal file
30
backend/src/data/GuildStats.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||
import { connection } from "./db";
|
||||
import { getRepository, Repository } from "typeorm";
|
||||
import { StatValue } from "./entities/StatValue";
|
||||
|
||||
export class GuildStats extends BaseGuildRepository {
|
||||
private stats: Repository<StatValue>;
|
||||
|
||||
constructor(guildId) {
|
||||
super(guildId);
|
||||
this.stats = getRepository(StatValue);
|
||||
}
|
||||
|
||||
async saveValue(source: string, key: string, value: number): Promise<void> {
|
||||
await this.stats.insert({
|
||||
guild_id: this.guildId,
|
||||
source,
|
||||
key,
|
||||
value,
|
||||
});
|
||||
}
|
||||
|
||||
async deleteOldValues(source: string, cutoff: string): Promise<void> {
|
||||
await this.stats
|
||||
.createQueryBuilder()
|
||||
.where("source = :source", { source })
|
||||
.andWhere("created_at < :cutoff", { cutoff })
|
||||
.delete();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue