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

63 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-02-05 02:48:08 +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';
2019-02-22 05:06:17 +00:00
import { pack } from '../../../../../models/user';
2018-11-02 04:47:44 +00:00
import define from '../../../define';
import { ApiError } from '../../../error';
2019-02-22 05:02:56 +00:00
import { getUser } from '../../../common/getters';
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
},
tags: ['following', 'account'],
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-11-03 13:49:36 +00:00
desc: {
'ja-JP': '対象のユーザーのID',
'en-US': 'Target user ID'
}
2018-11-01 18:32:24 +00:00
}
},
errors: {
noSuchUser: {
message: 'No such user.',
code: 'NO_SUCH_USER',
id: '4e68c551-fc4c-4e46-bb41-7d4a37bf9dab'
},
followRequestNotFound: {
message: 'Follow request not found.',
code: 'FOLLOW_REQUEST_NOT_FOUND',
id: '089b125b-d338-482a-9a09-e2622ac9f8d4'
},
2018-11-01 18:32:24 +00:00
}
2018-07-16 19:36:44 +00:00
};
export default define(meta, async (ps, user) => {
2018-06-02 03:58:56 +00:00
// Fetch followee
2019-02-22 05:02:56 +00:00
const followee = 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 15:51:20 +00:00
});
try {
await cancelFollowRequest(followee, user);
} catch (e) {
if (e.id === '17447091-ce07-46dd-b331-c1fd4f15b1e7') throw new ApiError(meta.errors.followRequestNotFound);
throw e;
}
2018-06-01 15:51:20 +00:00
return await pack(followee._id, user);
});