2018-11-01 18:32:24 +00:00
|
|
|
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
2018-06-01 15:51:20 +00:00
|
|
|
import cancelFollowRequest from '../../../../../services/following/requests/cancel';
|
2018-06-18 00:54:53 +00:00
|
|
|
import User, { pack, ILocalUser } from '../../../../../models/user';
|
2018-11-01 18:32:24 +00:00
|
|
|
import getParams from '../../../get-params';
|
2018-06-01 15:51:20 +00:00
|
|
|
|
2018-07-16 19:36:44 +00:00
|
|
|
export const meta = {
|
|
|
|
desc: {
|
2018-08-28 21:59:43 +00:00
|
|
|
'ja-JP': '自分が作成した、指定したフォローリクエストをキャンセルします。',
|
|
|
|
'en-US': 'Cancel a follow request.'
|
2018-07-16 19:36:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
requireCredential: true,
|
|
|
|
|
2018-11-01 18:32:24 +00:00
|
|
|
kind: 'following-write',
|
|
|
|
|
|
|
|
params: {
|
|
|
|
userId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
transform: transform,
|
|
|
|
}
|
|
|
|
}
|
2018-07-16 19:36:44 +00:00
|
|
|
};
|
|
|
|
|
2018-07-05 17:58:29 +00:00
|
|
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
2018-11-01 18:32:24 +00:00
|
|
|
const [ps, psErr] = getParams(meta, params);
|
|
|
|
if (psErr) return rej(psErr);
|
2018-06-01 15:51:20 +00:00
|
|
|
|
2018-06-02 03:58:56 +00:00
|
|
|
// Fetch followee
|
|
|
|
const followee = await User.findOne({
|
2018-11-01 18:32:24 +00:00
|
|
|
_id: ps.userId
|
2018-06-01 15:51:20 +00:00
|
|
|
});
|
|
|
|
|
2018-06-02 03:58:56 +00:00
|
|
|
if (followee === null) {
|
|
|
|
return rej('followee not found');
|
2018-06-01 15:51:20 +00:00
|
|
|
}
|
|
|
|
|
2018-08-23 05:56:39 +00:00
|
|
|
try {
|
|
|
|
await cancelFollowRequest(followee, user);
|
|
|
|
} catch (e) {
|
|
|
|
return rej(e);
|
|
|
|
}
|
2018-06-01 15:51:20 +00:00
|
|
|
|
2018-06-02 03:58:56 +00:00
|
|
|
res(await pack(followee._id, user));
|
2018-06-01 15:51:20 +00:00
|
|
|
});
|