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

49 lines
1.1 KiB
TypeScript
Raw Normal View History

2019-02-05 11:48:08 +09:00
import $ from 'cafy';
import ID, { transform } from '../../../../../misc/cafy-id';
2018-06-02 00:15:17 +09:00
import rejectFollowRequest from '../../../../../services/following/requests/reject';
2018-11-02 13:47:44 +09:00
import define from '../../../define';
import { ApiError } from '../../../error';
2019-02-22 14:02:56 +09:00
import { getUser } from '../../../common/getters';
2018-06-01 21:55:27 +09:00
2018-07-17 04:36:44 +09:00
export const meta = {
desc: {
2018-08-29 06:59:43 +09:00
'ja-JP': '自分に届いた、指定したフォローリクエストを拒否します。',
'en-US': 'Reject a follow request.'
2018-07-17 04:36:44 +09:00
},
requireCredential: true,
2018-11-02 03:32:24 +09:00
kind: 'following-write',
params: {
userId: {
validator: $.type(ID),
transform: transform,
2018-11-03 22:49:36 +09:00
desc: {
'ja-JP': '対象のユーザーのID',
'en-US': 'Target user ID'
}
2018-11-02 03:32:24 +09:00
}
},
errors: {
noSuchUser: {
message: 'No such user.',
code: 'NO_SUCH_USER',
id: 'abc2ffa6-25b2-4380-ba99-321ff3a94555'
},
2018-11-02 03:32:24 +09:00
}
2018-07-17 04:36:44 +09:00
};
export default define(meta, async (ps, user) => {
2018-06-01 21:55:27 +09:00
// Fetch follower
2019-02-22 14:02:56 +09:00
const follower = await getUser(ps.userId).catch(e => {
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
throw e;
2018-06-01 21:55:27 +09:00
});
await rejectFollowRequest(user, follower);
return;
});