summaryrefslogtreecommitdiff
path: root/src/services/chart/charts/classes/test-grouped.ts
blob: e32cbcf41630e0a1b3c9d3862c39482aba67951c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import autobind from 'autobind-decorator';
import Chart, { Obj, DeepPartial } from '../../core';
import { SchemaType } from '../../../../misc/schema';
import { name, schema } from '../schemas/test-grouped';

type TestGroupedLog = SchemaType<typeof schema>;

export default class TestGroupedChart extends Chart<TestGroupedLog> {
	private total = {} as Record<string, number>;

	constructor() {
		super(name, schema, true);
	}

	@autobind
	protected genNewLog(latest: TestGroupedLog): DeepPartial<TestGroupedLog> {
		return {
			foo: {
				total: latest.foo.total,
			},
		};
	}

	@autobind
	protected async fetchActual(group: string): Promise<DeepPartial<TestGroupedLog>> {
		return {
			foo: {
				total: this.total[group],
			},
		};
	}

	@autobind
	public async increment(group: string) {
		if (this.total[group] == null) this.total[group] = 0;

		const update: Obj = {};

		update.total = 1;
		update.inc = 1;
		this.total[group]++;

		await this.inc({
			foo: update
		}, group);
	}
}