summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/notes
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-07-06 23:19:47 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-07-06 23:19:47 +0900
commit42d4e6610f2b0fdc5a4b384757756700dbb68454 (patch)
treedf5079bede2b933e80ec0d534ab34d9432a1c99b /src/server/api/endpoints/notes
parent:v: (diff)
downloadsharkey-42d4e6610f2b0fdc5a4b384757756700dbb68454.tar.gz
sharkey-42d4e6610f2b0fdc5a4b384757756700dbb68454.tar.bz2
sharkey-42d4e6610f2b0fdc5a4b384757756700dbb68454.zip
移行
Diffstat (limited to 'src/server/api/endpoints/notes')
-rw-r--r--src/server/api/endpoints/notes/reactions/create.ts36
1 files 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);
}