From 931bdc6aace5e7aa71ffdfb470e208ead78a2a53 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 2 Nov 2018 03:32:24 +0900 Subject: Refactoring, Clean up and bug fixes --- src/server/api/endpoints/following/unstalk.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/server/api/endpoints/following/unstalk.ts') diff --git a/src/server/api/endpoints/following/unstalk.ts b/src/server/api/endpoints/following/unstalk.ts index 8b66f0727e..00e91357ec 100644 --- a/src/server/api/endpoints/following/unstalk.ts +++ b/src/server/api/endpoints/following/unstalk.ts @@ -1,6 +1,7 @@ -import $ from 'cafy'; import ID from '../../../../misc/cafy-id'; +import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import Following from '../../../../models/following'; import { ILocalUser } from '../../../../models/user'; +import getParams from '../../get-params'; export const meta = { desc: { @@ -10,20 +11,26 @@ export const meta = { requireCredential: true, - kind: 'following-write' + kind: 'following-write', + + params: { + userId: { + validator: $.type(ID), + transform: transform, + } + } }; export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { - const follower = user; + const [ps, psErr] = getParams(meta, params); + if (psErr) return rej(psErr); - // Get 'userId' parameter - const [userId, userIdErr] = $.type(ID).get(params.userId); - if (userIdErr) return rej('invalid userId param'); + const follower = user; // Fetch following const following = await Following.findOne({ followerId: follower._id, - followeeId: userId + followeeId: ps.userId }); if (following === null) { @@ -37,7 +44,6 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) = } }); - // Send response res(); // TODO: イベント -- cgit v1.2.3-freya