diff options
author | Maksim Sukharev <antreesy.web@gmail.com> | 2024-05-31 13:42:24 +0200 |
---|---|---|
committer | Maksim Sukharev <antreesy.web@gmail.com> | 2024-06-19 11:00:44 +0200 |
commit | 04b1d46a41affedd2065d98674beface67e437a3 (patch) | |
tree | feac5fb1a4391e305de24f1ff245806e41964b7c /src | |
parent | d87d7fb2da4a88de2e872ccef31752cd3b35229f (diff) |
feat(ban): add endpoints for ban handling
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/services/banService.ts | 56 | ||||
-rw-r--r-- | src/types/index.ts | 9 |
2 files changed, 65 insertions, 0 deletions
diff --git a/src/services/banService.ts b/src/services/banService.ts new file mode 100644 index 000000000..0f90ac1f0 --- /dev/null +++ b/src/services/banService.ts @@ -0,0 +1,56 @@ +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import axios from '@nextcloud/axios' +import { generateOcsUrl } from '@nextcloud/router' + +import type { + getBansResponse, + banActorParams, + banActorResponse, + unbanActorParams, + unbanActorResponse, +} from '../types' + +/** + * Get information about configured bans for this conversation + * + * @param token - the conversation token + * @param [options] - request options + */ +const getConversationBans = async function(token: string, options?: object): getBansResponse { + return axios.get(generateOcsUrl('/apps/spreed/api/v1/ban/{token}', { token }, options), options) +} + +/** + * Ban actor with specified internal note for this conversation + * + * @param token - the conversation token + * @param payload - banned actor information + * @param [options] - request options + */ +const banActor = async function(token: string, payload: banActorParams, options?: object): banActorResponse { + return axios.post(generateOcsUrl('/apps/spreed/api/v1/ban/{token}', { token }, options), payload, options) +} + +/** + * Ban actor with specified internal note for this conversation + * + * @param token - the conversation token + * @param banId - ban id + * @param [options] - request options + */ +const unbanActor = async function(token: string, banId: unbanActorParams['banId'], options?: object): unbanActorResponse { + return axios.delete(generateOcsUrl('/apps/spreed/api/v1/ban/{token}', { token }, options), { + ...options, + params: { banId } as unbanActorParams, + }) +} + +export { + getConversationBans, + banActor, + unbanActor, +} diff --git a/src/types/index.ts b/src/types/index.ts index 5b7f65eba..e733416a6 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -89,6 +89,15 @@ export type setEmojiAvatarParams = ApiOptions<operations['avatar-emoji-avatar'][ export type setEmojiAvatarResponse = ApiResponse<operations['avatar-emoji-avatar']['responses'][200]['content']['application/json']> export type deleteAvatarResponse = ApiResponse<operations['avatar-delete-avatar']['responses'][200]['content']['application/json']> +// Bans +export type Ban = components['schemas']['Ban'] + +export type getBansResponse = ApiResponse<operations['ban-list-bans']['responses'][200]['content']['application/json']> +export type banActorParams = ApiOptions<operations['ban-ban-actor']['parameters']['query']>['params'] +export type banActorResponse = ApiResponse<operations['ban-ban-actor']['responses'][200]['content']['application/json']> +export type unbanActorParams = ApiOptions<operations['ban-unban-actor']['parameters']['query']>['params'] +export type unbanActorResponse = ApiResponse<operations['ban-unban-actor']['responses'][200]['content']['application/json']> + // Bots export type Bot = components['schemas']['Bot'] export type BotWithDetails = components['schemas']['BotWithDetails'] |