From 73e84df9deeb90a98968479a42d80e47aaaa1a95 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 24 Feb 2019 12:23:31 +0900 Subject: [PATCH] Improve doc --- src/server/api/endpoints/charts/users.ts | 10 ++-- src/services/chart/users.ts | 59 ++++++++++++++++-------- 2 files changed, 42 insertions(+), 27 deletions(-) diff --git a/src/server/api/endpoints/charts/users.ts b/src/server/api/endpoints/charts/users.ts index 0b1b18bbe..9de54a630 100644 --- a/src/server/api/endpoints/charts/users.ts +++ b/src/server/api/endpoints/charts/users.ts @@ -1,6 +1,7 @@ import $ from 'cafy'; import define from '../../define'; -import usersChart from '../../../../services/chart/users'; +import usersChart, { usersLogSchema } from '../../../../services/chart/users'; +import { convertLog } from '../../../../services/chart'; export const meta = { stability: 'stable', @@ -28,12 +29,7 @@ export const meta = { }, }, - res: { - type: 'array', - items: { - type: 'object', - }, - }, + res: convertLog(usersLogSchema), }; export default define(meta, async (ps) => { diff --git a/src/services/chart/users.ts b/src/services/chart/users.ts index ce23209ae..0cb3711f9 100644 --- a/src/services/chart/users.ts +++ b/src/services/chart/users.ts @@ -1,31 +1,50 @@ import autobind from 'autobind-decorator'; import Chart, { Obj } from './'; import User, { IUser, isLocalUser } from '../../models/user'; +import { SchemaType } from '../../prelude/schema'; -/** - * ユーザーに関するチャート - */ -type UsersLog = { - local: { - /** - * 集計期間時点での、全ユーザー数 - */ - total: number; +const logSchema = { + /** + * 集計期間時点での、全ユーザー数 + */ + total: { + type: 'number' as 'number', + description: '集計期間時点での、全ユーザー数' + }, - /** - * 増加したユーザー数 - */ - inc: number; + /** + * 増加したユーザー数 + */ + inc: { + type: 'number' as 'number', + description: '増加したユーザー数' + }, - /** - * 減少したユーザー数 - */ - dec: number; - }; - - remote: UsersLog['local']; + /** + * 減少したユーザー数 + */ + dec: { + type: 'number' as 'number', + description: '減少したユーザー数' + }, }; +export const usersLogSchema = { + type: 'object' as 'object', + properties: { + local: { + type: 'object' as 'object', + properties: logSchema + }, + remote: { + type: 'object' as 'object', + properties: logSchema + }, + } +}; + +type UsersLog = SchemaType; + class UsersChart extends Chart { constructor() { super('users');