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

35 lines
940 B
TypeScript
Raw Normal View History

2018-07-07 10:19:00 +00:00
import $ from 'cafy'; import ID 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-06-01 15:51:20 +00:00
2018-07-16 19:36:44 +00:00
export const meta = {
desc: {
ja: '自分が作成した、指定したフォローリクエストをキャンセルします。',
en: 'Cancel a follow request.'
},
requireCredential: true,
kind: 'following-write'
};
2018-07-05 17:58:29 +00:00
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
2018-06-02 03:58:56 +00:00
// Get 'userId' parameter
const [followeeId, followeeIdErr] = $.type(ID).get(params.userId);
if (followeeIdErr) return rej('invalid userId param');
2018-06-01 15:51:20 +00:00
2018-06-02 03:58:56 +00:00
// Fetch followee
const followee = await User.findOne({
_id: followeeId
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-06-02 03:58:56 +00:00
await cancelFollowRequest(followee, user);
2018-06-01 15:51:20 +00:00
// Send response
2018-06-02 03:58:56 +00:00
res(await pack(followee._id, user));
2018-06-01 15:51:20 +00:00
});