This commit is contained in:
syuilo
2018-06-02 00:51:20 +09:00
parent f14571dc42
commit a26c19cbd2
5 changed files with 97 additions and 1 deletions

View File

@ -0,0 +1,26 @@
import $ from 'cafy'; import ID from '../../../../../cafy-id';
import cancelFollowRequest from '../../../../../services/following/requests/cancel';
import User from '../../../../../models/user';
/**
* Cancel a follow request
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'followerId' parameter
const [followerId, followerIdErr] = $.type(ID).get(params.followerId);
if (followerIdErr) return rej('invalid followerId param');
// Fetch follower
const follower = await User.findOne({
_id: followerId
});
if (follower === null) {
return rej('follower not found');
}
await cancelFollowRequest(user, follower);
// Send response
res();
});

View File

@ -0,0 +1,14 @@
//import $ from 'cafy'; import ID from '../../../../../cafy-id';
import FollowRequest, { pack } from '../../../../../models/follow-request';
/**
* Get all pending received follow requests
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
const reqs = await FollowRequest.find({
followeeId: user._id
});
// Send response
res(await Promise.all(reqs.map(req => pack(req))));
});