diff --git a/src/server/api/endpoints/charts/users.ts b/src/server/api/endpoints/charts/users.ts index 0b1b18bbe7..9de54a630e 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 ce23209aea..0cb3711f95 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');