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

49 lines
1.1 KiB
TypeScript
Raw Normal View History

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