From b679163d01b0152b38db658fe49d8a57c6aad930 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 24 Feb 2019 09:45:27 +0900 Subject: Improve type definitions --- src/services/chart/notes.ts | 89 ++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 38 deletions(-) (limited to 'src/services/chart/notes.ts') diff --git a/src/services/chart/notes.ts b/src/services/chart/notes.ts index 8f95f63638..d3704fed9a 100644 --- a/src/services/chart/notes.ts +++ b/src/services/chart/notes.ts @@ -2,48 +2,61 @@ import autobind from 'autobind-decorator'; import Chart, { Obj } from '.'; import Note, { INote } from '../../models/note'; import { isLocalUser } from '../../models/user'; +import { SchemaType } from '../../prelude/schema'; + +const logSchema = { + total: { + type: 'number' as 'number', + description: '集計期間時点での、全投稿数' + }, + + inc: { + type: 'number' as 'number', + description: '増加した投稿数' + }, + + dec: { + type: 'number' as 'number', + description: '減少した投稿数' + }, + + diffs: { + type: 'object' as 'object', + properties: { + normal: { + type: 'number' as 'number', + description: '通常の投稿数の差分' + }, -/** - * 投稿に関するチャート - */ -type NotesLog = { - local: { - /** - * 集計期間時点での、全投稿数 - */ - total: number; - - /** - * 増加した投稿数 - */ - inc: number; - - /** - * 減少した投稿数 - */ - dec: number; - - diffs: { - /** - * 通常の投稿数の差分 - */ - normal: number; - - /** - * リプライの投稿数の差分 - */ - reply: number; - - /** - * Renoteの投稿数の差分 - */ - renote: number; - }; - }; + reply: { + type: 'number' as 'number', + description: 'リプライの投稿数の差分' + }, - remote: NotesLog['local']; + renote: { + type: 'number' as 'number', + description: 'Renoteの投稿数の差分' + }, + } + }, }; +export const notesLogSchema = { + type: 'object' as 'object', + properties: { + local: { + type: 'object' as 'object', + properties: logSchema + }, + remote: { + type: 'object' as 'object', + properties: logSchema + }, + } +}; + +type NotesLog = SchemaType; + class NotesChart extends Chart { constructor() { super('notes'); -- cgit v1.2.3-freya