Skip to content

Commit

Permalink
feat(ban): add endpoints for ban handling
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed May 31, 2024
1 parent 3625b4b commit e075b4d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/services/banService.ts
Original file line number Diff line number Diff line change
@@ -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,
}
9 changes: 9 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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']
Expand Down

0 comments on commit e075b4d

Please sign in to comment.