From 42d4e6610f2b0fdc5a4b384757756700dbb68454 Mon Sep 17 00:00:00 2001
From: syuilo <syuilotan@yahoo.co.jp>
Date: Fri, 6 Jul 2018 23:19:47 +0900
Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E8=A1=8C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../api/endpoints/notes/reactions/create.ts   | 36 ++++++++++++++-----
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/src/server/api/endpoints/notes/reactions/create.ts b/src/server/api/endpoints/notes/reactions/create.ts
index 709b47ab5d..8b22e53225 100644
--- a/src/server/api/endpoints/notes/reactions/create.ts
+++ b/src/server/api/endpoints/notes/reactions/create.ts
@@ -3,22 +3,40 @@ import Note from '../../../../../models/note';
 import create from '../../../../../services/note/reaction/create';
 import { validateReaction } from '../../../../../models/note-reaction';
 import { ILocalUser } from '../../../../../models/user';
+import getParams from '../../../get-params';
+
+export const meta = {
+	name: 'notes/reactions/create',
+
+	desc: {
+		ja: '投稿にリアクションします。'
+	},
+
+	params: {
+		noteId: $.type(ID).note({
+			desc: {
+				ja: '対象の投稿'
+			}
+		}),
+
+		reaction: $.str.pipe(validateReaction.ok).note({
+			desc: {
+				ja: 'リアクションの種類'
+			}
+		})
+	}
+};
 
 /**
  * React to a note
  */
 export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
-	// Get 'noteId' parameter
-	const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
-	if (noteIdErr) return rej('invalid noteId param');
-
-	// Get 'reaction' parameter
-	const [reaction, reactionErr] = $.str.pipe(validateReaction.ok).get(params.reaction);
-	if (reactionErr) return rej('invalid reaction param');
+	const [ps, psErr] = getParams(meta, params);
+	if (psErr) return rej(psErr);
 
 	// Fetch reactee
 	const note = await Note.findOne({
-		_id: noteId
+		_id: ps.noteId
 	});
 
 	if (note === null) {
@@ -26,7 +44,7 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
 	}
 
 	try {
-		await create(user, note, reaction);
+		await create(user, note, ps.reaction);
 	} catch (e) {
 		rej(e);
 	}