mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35: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
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();
|
||||
}
|
||||
}
|
20
backend/src/data/entities/StatValue.ts
Normal file
20
backend/src/data/entities/StatValue.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
import { Entity, Column, PrimaryColumn, CreateDateColumn } from "typeorm";
|
||||
|
||||
@Entity("stats")
|
||||
export class StatValue {
|
||||
@Column()
|
||||
@PrimaryColumn()
|
||||
id: string;
|
||||
|
||||
@Column()
|
||||
guild_id: string;
|
||||
|
||||
@Column()
|
||||
source: string;
|
||||
|
||||
@Column() key: string;
|
||||
|
||||
@Column() value: number;
|
||||
|
||||
@Column() created_at: string;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue