sharkey/src/server/api/endpoints/following/requests/reject.ts

27 lines
711 B
TypeScript
Raw Normal View History

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