0e4a111f81
Resolve #7779
58 lines
1.3 KiB
TypeScript
58 lines
1.3 KiB
TypeScript
import $ from 'cafy';
|
|
import { ID } from '@/misc/cafy-id';
|
|
import cancelFollowRequest from '@/services/following/requests/cancel';
|
|
import define from '../../../define';
|
|
import { ApiError } from '../../../error';
|
|
import { getUser } from '../../../common/getters';
|
|
import { Users } from '@/models/index';
|
|
|
|
export const meta = {
|
|
tags: ['following', 'account'],
|
|
|
|
requireCredential: true as const,
|
|
|
|
kind: 'write:following',
|
|
|
|
params: {
|
|
userId: {
|
|
validator: $.type(ID),
|
|
}
|
|
},
|
|
|
|
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'
|
|
},
|
|
},
|
|
|
|
res: {
|
|
type: 'object' as const,
|
|
optional: false as const, nullable: false as const,
|
|
ref: 'User'
|
|
}
|
|
};
|
|
|
|
export default define(meta, async (ps, user) => {
|
|
// Fetch followee
|
|
const followee = await getUser(ps.userId).catch(e => {
|
|
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
|
|
throw e;
|
|
});
|
|
|
|
try {
|
|
await cancelFollowRequest(followee, user);
|
|
} catch (e) {
|
|
if (e.id === '17447091-ce07-46dd-b331-c1fd4f15b1e7') throw new ApiError(meta.errors.followRequestNotFound);
|
|
throw e;
|
|
}
|
|
|
|
return await Users.pack(followee.id, user);
|
|
});
|