From e075b4de60abaafac66503cca78fbc2c0d199f9d Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Fri, 31 May 2024 13:42:24 +0200 Subject: [PATCH] feat(ban): add endpoints for ban handling Signed-off-by: Maksim Sukharev --- src/services/banService.ts | 56 ++++++++++++++++++++++++++++++++++++++ src/types/index.ts | 9 ++++++ 2 files changed, 65 insertions(+) create mode 100644 src/services/banService.ts diff --git a/src/services/banService.ts b/src/services/banService.ts new file mode 100644 index 00000000000..0f90ac1f0af --- /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 b82dbb8da02..66afbd6c8db 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -74,6 +74,15 @@ export type setEmojiAvatarParams = ApiOptions export type deleteAvatarResponse = ApiResponse +// Bans +export type Ban = components['schemas']['Ban'] + +export type getBansResponse = ApiResponse +export type banActorParams = ApiOptions['params'] +export type banActorResponse = ApiResponse +export type unbanActorParams = ApiOptions['params'] +export type unbanActorResponse = ApiResponse + // Bots export type Bot = components['schemas']['Bot'] export type BotWithDetails = components['schemas']['BotWithDetails']