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

41 lines
952 B
TypeScript
Raw Normal View History

2018-11-02 03:32:24 +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-06-18 09:54:53 +09:00
import User, { ILocalUser } from '../../../../../models/user';
2018-11-02 03:32:24 +09:00
import getParams from '../../../get-params';
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-07-17 04:36:44 +09:00
};
2018-07-06 02:58:29 +09:00
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
2018-11-02 03:32:24 +09:00
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
2018-06-01 21:55:27 +09:00
// Fetch follower
const follower = await User.findOne({
2018-11-02 03:32:24 +09:00
_id: ps.userId
2018-06-01 21:55:27 +09:00
});
if (follower === null) {
return rej('follower not found');
}
await rejectFollowRequest(user, follower);
res();
});