monkeeShark/src/server/api/endpoints/following/requests/cancel.ts

27 lines
687 B
TypeScript
Raw Normal View History

2018-06-01 15:51:20 +00:00
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();
});