misskey/src/server/api/endpoints/following/requests/accept.ts

27 lines
708 B
TypeScript
Raw Normal View History

2018-06-01 14:55:27 +02:00
import $ from 'cafy'; import ID from '../../../../../cafy-id';
2018-06-01 17:15:17 +02:00
import acceptFollowRequest from '../../../../../services/following/requests/accept';
2018-06-18 02:54:53 +02:00
import User, { ILocalUser } from '../../../../../models/user';
2018-06-01 14:55:27 +02:00
/**
* Accept a follow request
*/
2018-06-18 02:54:53 +02:00
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
2018-06-02 05:58:56 +02:00
// Get 'userId' parameter
const [followerId, followerIdErr] = $.type(ID).get(params.userId);
if (followerIdErr) return rej('invalid userId param');
2018-06-01 14:55:27 +02:00
// Fetch follower
const follower = await User.findOne({
_id: followerId
});
if (follower === null) {
return rej('follower not found');
}
await acceptFollowRequest(user, follower);
// Send response
res();
});