From e31a2f7e55bb96d661945d0475cc5cc678c0eb18 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 23 Aug 2018 14:56:39 +0900 Subject: [PATCH] Fix bug: Check following request existance --- src/server/api/endpoints/following/requests/cancel.ts | 6 +++++- src/services/following/requests/cancel.ts | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/server/api/endpoints/following/requests/cancel.ts b/src/server/api/endpoints/following/requests/cancel.ts index 9bfc40ce65..c46b948d29 100644 --- a/src/server/api/endpoints/following/requests/cancel.ts +++ b/src/server/api/endpoints/following/requests/cancel.ts @@ -27,7 +27,11 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) = return rej('followee not found'); } - await cancelFollowRequest(followee, user); + try { + await cancelFollowRequest(followee, user); + } catch (e) { + return rej(e); + } // Send response res(await pack(followee._id, user)); diff --git a/src/services/following/requests/cancel.ts b/src/services/following/requests/cancel.ts index b0b574da58..26e4544d5c 100644 --- a/src/services/following/requests/cancel.ts +++ b/src/services/following/requests/cancel.ts @@ -12,6 +12,15 @@ export default async function(followee: IUser, follower: IUser) { deliver(follower as ILocalUser, content, followee.inbox); } + const request = await FollowRequest.findOne({ + followeeId: followee._id, + followerId: follower._id + }); + + if (request == null) { + throw 'request not found'; + } + await FollowRequest.remove({ followeeId: followee._id, followerId: follower._id