summaryrefslogtreecommitdiff
path: root/src/chart/users.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-02-08 04:31:33 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-02-08 04:31:33 +0900
commitaba85b977dfc868c1a65ce06ed58ea59d0371f7f (patch)
tree5e27a5397bb3ee93ae1790ed2f92c6264ae86956 /src/chart/users.ts
parentImplement instance blocking (#4182) (diff)
downloadsharkey-aba85b977dfc868c1a65ce06ed58ea59d0371f7f.tar.gz
sharkey-aba85b977dfc868c1a65ce06ed58ea59d0371f7f.tar.bz2
sharkey-aba85b977dfc868c1a65ce06ed58ea59d0371f7f.zip
Refactoring: Move chart dir into services dir
Diffstat (limited to 'src/chart/users.ts')
-rw-r--r--src/chart/users.ts75
1 files changed, 0 insertions, 75 deletions
diff --git a/src/chart/users.ts b/src/chart/users.ts
deleted file mode 100644
index 547e595b01..0000000000
--- a/src/chart/users.ts
+++ /dev/null
@@ -1,75 +0,0 @@
-import autobind from 'autobind-decorator';
-import Chart, { Obj } from './';
-import User, { IUser, isLocalUser } from '../models/user';
-
-/**
- * ユーザーに関するチャート
- */
-type UsersLog = {
- local: {
- /**
- * 集計期間時点での、全ユーザー数
- */
- total: number;
-
- /**
- * 増加したユーザー数
- */
- inc: number;
-
- /**
- * 減少したユーザー数
- */
- dec: number;
- };
-
- remote: UsersLog['local'];
-};
-
-class UsersChart extends Chart<UsersLog> {
- constructor() {
- super('users');
- }
-
- @autobind
- protected async getTemplate(init: boolean, latest?: UsersLog): Promise<UsersLog> {
- const [localCount, remoteCount] = init ? await Promise.all([
- User.count({ host: null }),
- User.count({ host: { $ne: null } })
- ]) : [
- latest ? latest.local.total : 0,
- latest ? latest.remote.total : 0
- ];
-
- return {
- local: {
- total: localCount,
- inc: 0,
- dec: 0
- },
- remote: {
- total: remoteCount,
- inc: 0,
- dec: 0
- }
- };
- }
-
- @autobind
- public async update(user: IUser, isAdditional: boolean) {
- const update: Obj = {};
-
- update.total = isAdditional ? 1 : -1;
- if (isAdditional) {
- update.inc = 1;
- } else {
- update.dec = 1;
- }
-
- await this.inc({
- [isLocalUser(user) ? 'local' : 'remote']: update
- });
- }
-}
-
-export default new UsersChart();