1
0
mirror of https://github.com/misskey-dev/misskey synced 2025-01-08 10:53:29 +09:00
misskey/src/server/api/endpoints/following/requests/cancel.ts

27 lines
744 B
TypeScript
Raw Normal View History

2018-06-02 00:51:20 +09:00
import $ from 'cafy'; import ID from '../../../../../cafy-id';
import cancelFollowRequest from '../../../../../services/following/requests/cancel';
2018-06-18 09:54:53 +09:00
import User, { pack, ILocalUser } from '../../../../../models/user';
2018-06-02 00:51:20 +09:00
/**
* Cancel a follow request
*/
2018-06-18 09:54:53 +09:00
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
2018-06-02 12:58:56 +09:00
// Get 'userId' parameter
const [followeeId, followeeIdErr] = $.type(ID).get(params.userId);
if (followeeIdErr) return rej('invalid userId param');
2018-06-02 00:51:20 +09:00
2018-06-02 12:58:56 +09:00
// Fetch followee
const followee = await User.findOne({
_id: followeeId
2018-06-02 00:51:20 +09:00
});
2018-06-02 12:58:56 +09:00
if (followee === null) {
return rej('followee not found');
2018-06-02 00:51:20 +09:00
}
2018-06-02 12:58:56 +09:00
await cancelFollowRequest(followee, user);
2018-06-02 00:51:20 +09:00
// Send response
2018-06-02 12:58:56 +09:00
res(await pack(followee._id, user));
2018-06-02 00:51:20 +09:00
});