diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2019-05-19 20:41:23 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2019-05-19 20:41:23 +0900 |
| commit | e103904a0454d8a05cea60d984bc1ef1e2b9e652 (patch) | |
| tree | 0f6f48594bd027abb5653cab4c4ec4d1a3143f1d /src/server/api/endpoints/users/groups/invitations/reject.ts | |
| parent | Update README.md [AUTOGEN] (#4940) (diff) | |
| download | sharkey-e103904a0454d8a05cea60d984bc1ef1e2b9e652.tar.gz sharkey-e103904a0454d8a05cea60d984bc1ef1e2b9e652.tar.bz2 sharkey-e103904a0454d8a05cea60d984bc1ef1e2b9e652.zip | |
Resolve #4941
Diffstat (limited to 'src/server/api/endpoints/users/groups/invitations/reject.ts')
| -rw-r--r-- | src/server/api/endpoints/users/groups/invitations/reject.ts | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/server/api/endpoints/users/groups/invitations/reject.ts b/src/server/api/endpoints/users/groups/invitations/reject.ts new file mode 100644 index 0000000000..e9e7bc8b48 --- /dev/null +++ b/src/server/api/endpoints/users/groups/invitations/reject.ts @@ -0,0 +1,53 @@ +import $ from 'cafy'; +import { ID } from '../../../../../../misc/cafy-id'; +import define from '../../../../define'; +import { ApiError } from '../../../../error'; +import { UserGroupInvites } from '../../../../../../models'; + +export const meta = { + desc: { + 'ja-JP': 'ユーザーグループへの招待を拒否します。', + 'en-US': 'Reject invite of a user group.' + }, + + tags: ['groups', 'users'], + + requireCredential: true, + + kind: 'write:user-groups', + + params: { + inviteId: { + validator: $.type(ID), + desc: { + 'ja-JP': '招待ID', + 'en-US': 'The invite ID' + } + }, + }, + + errors: { + noSuchInvitation: { + message: 'No such invitation.', + code: 'NO_SUCH_INVITATION', + id: 'ad7471d4-2cd9-44b4-ac68-e7136b4ce656' + }, + } +}; + +export default define(meta, async (ps, user) => { + // Fetch the invitation + const invite = await UserGroupInvites.findOne({ + id: ps.inviteId, + }); + + if (invite == null) { + throw new ApiError(meta.errors.noSuchInvitation); + } + + if (invite.userId !== user.id) { + throw new ApiError(meta.errors.noSuchInvitation); + } + + await UserGroupInvites.delete(invite.id); +}); |