summaryrefslogtreecommitdiff
path: root/src/services/chart/active-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/services/chart/active-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/services/chart/active-users.ts')
-rw-r--r--src/services/chart/active-users.ts48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/services/chart/active-users.ts b/src/services/chart/active-users.ts
new file mode 100644
index 0000000000..2a4e1a97ac
--- /dev/null
+++ b/src/services/chart/active-users.ts
@@ -0,0 +1,48 @@
+import autobind from 'autobind-decorator';
+import Chart, { Obj } from '.';
+import { IUser, isLocalUser } from '../../models/user';
+
+/**
+ * アクティブユーザーに関するチャート
+ */
+type ActiveUsersLog = {
+ local: {
+ /**
+ * アクティブユーザー数
+ */
+ count: number;
+ };
+
+ remote: ActiveUsersLog['local'];
+};
+
+class ActiveUsersChart extends Chart<ActiveUsersLog> {
+ constructor() {
+ super('activeUsers');
+ }
+
+ @autobind
+ protected async getTemplate(init: boolean, latest?: ActiveUsersLog): Promise<ActiveUsersLog> {
+ return {
+ local: {
+ count: 0
+ },
+ remote: {
+ count: 0
+ }
+ };
+ }
+
+ @autobind
+ public async update(user: IUser) {
+ const update: Obj = {
+ count: 1
+ };
+
+ await this.incIfUnique({
+ [isLocalUser(user) ? 'local' : 'remote']: update
+ }, 'users', user._id.toHexString());
+ }
+}
+
+export default new ActiveUsersChart();