From 799adcae9953bfdc2ac10de7a2f54613f35fc4ef Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 24 Feb 2019 10:04:27 +0900 Subject: [PATCH] Improve doc --- src/server/api/endpoints/charts/user/notes.ts | 10 +-- src/services/chart/per-user-notes.ts | 66 ++++++++++--------- 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/server/api/endpoints/charts/user/notes.ts b/src/server/api/endpoints/charts/user/notes.ts index 6a95911b1..7e31978bf 100644 --- a/src/server/api/endpoints/charts/user/notes.ts +++ b/src/server/api/endpoints/charts/user/notes.ts @@ -1,7 +1,8 @@ import $ from 'cafy'; import define from '../../../define'; -import perUserNotesChart from '../../../../../services/chart/per-user-notes'; +import perUserNotesChart, { perUserNotesLogSchema } from '../../../../../services/chart/per-user-notes'; import ID, { transform } from '../../../../../misc/cafy-id'; +import { convertLog } from '../../../../../services/chart'; export const meta = { stability: 'stable', @@ -38,12 +39,7 @@ export const meta = { } }, - res: { - type: 'array', - items: { - type: 'object', - }, - }, + res: convertLog(perUserNotesLogSchema), }; export default define(meta, async (ps) => { diff --git a/src/services/chart/per-user-notes.ts b/src/services/chart/per-user-notes.ts index 9ce4e67c5..957a85737 100644 --- a/src/services/chart/per-user-notes.ts +++ b/src/services/chart/per-user-notes.ts @@ -2,44 +2,50 @@ import autobind from 'autobind-decorator'; import Chart, { Obj } from './'; import Note, { INote } from '../../models/note'; import { IUser } from '../../models/user'; +import { SchemaType } from '../../prelude/schema'; -/** - * ユーザーごとの投稿に関するチャート - */ -type PerUserNotesLog = { - /** - * 集計期間時点での、全投稿数 - */ - total: number; +export const perUserNotesLogSchema = { + type: 'object' as 'object', + properties: { + total: { + type: 'number' as 'number', + description: '集計期間時点での、全投稿数' + }, - /** - * 増加した投稿数 - */ - inc: number; + inc: { + type: 'number' as 'number', + description: '増加した投稿数' + }, - /** - * 減少した投稿数 - */ - dec: number; + dec: { + type: 'number' as 'number', + description: '減少した投稿数' + }, - diffs: { - /** - * 通常の投稿数の差分 - */ - normal: number; + diffs: { + type: 'object' as 'object', + properties: { + normal: { + type: 'number' as 'number', + description: '通常の投稿数の差分' + }, - /** - * リプライの投稿数の差分 - */ - reply: number; + reply: { + type: 'number' as 'number', + description: 'リプライの投稿数の差分' + }, - /** - * Renoteの投稿数の差分 - */ - renote: number; - }; + renote: { + type: 'number' as 'number', + description: 'Renoteの投稿数の差分' + }, + } + }, + } }; +type PerUserNotesLog = SchemaType; + class PerUserNotesChart extends Chart { constructor() { super('perUserNotes', true);