Refactoring: Move chart dir into services dir

This commit is contained in:
syuilo 2019-02-08 04:31:33 +09:00
parent e6612f610c
commit aba85b977d
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
41 changed files with 53 additions and 53 deletions

View file

@ -0,0 +1,66 @@
import autobind from 'autobind-decorator';
import Chart, { Obj } from '.';
import Instance from '../../models/instance';
/**
*
*/
type FederationLog = {
instance: {
/**
*
*/
total: number;
/**
*
*/
inc: number;
/**
*
*/
dec: number;
};
};
class FederationChart extends Chart<FederationLog> {
constructor() {
super('federation');
}
@autobind
protected async getTemplate(init: boolean, latest?: FederationLog): Promise<FederationLog> {
const [total] = init ? await Promise.all([
Instance.count({})
]) : [
latest ? latest.instance.total : 0
];
return {
instance: {
total: total,
inc: 0,
dec: 0
}
};
}
@autobind
public async update(isAdditional: boolean) {
const update: Obj = {};
update.total = isAdditional ? 1 : -1;
if (isAdditional) {
update.inc = 1;
} else {
update.dec = 1;
}
await this.inc({
instance: update
});
}
}
export default new FederationChart();