68 lines
2.0 KiB
TypeScript
68 lines
2.0 KiB
TypeScript
import {
|
|
CommentApi,
|
|
Configuration,
|
|
type ApplicationFormCommentCountsDto,
|
|
type CommentDto,
|
|
type CreateCommentDto,
|
|
type CursorPagedCommentDto
|
|
} from '~~/.api-client'
|
|
import { cleanDoubleSlashes, withoutTrailingSlash } from 'ufo'
|
|
import { wrappedFetchWrap } from '~/utils/wrappedFetch'
|
|
|
|
export function useCommentApi() {
|
|
const appBaseUrl = useRuntimeConfig().app.baseURL
|
|
const { serverApiBasePath, clientProxyBasePath } = useRuntimeConfig().public
|
|
|
|
const basePath = withoutTrailingSlash(
|
|
cleanDoubleSlashes(import.meta.client ? appBaseUrl + clientProxyBasePath : clientProxyBasePath + serverApiBasePath)
|
|
)
|
|
|
|
const commentApiClient = new CommentApi(
|
|
new Configuration({ basePath, fetchApi: wrappedFetchWrap(useRequestFetch()) })
|
|
)
|
|
|
|
async function createComment(
|
|
applicationFormId: string,
|
|
formElementId: string,
|
|
createCommentDto: CreateCommentDto
|
|
): Promise<CommentDto> {
|
|
return commentApiClient.createComment({ applicationFormId, formElementId, createCommentDto })
|
|
}
|
|
|
|
async function getCommentsByApplicationFormId(
|
|
applicationFormId: string,
|
|
formElementId?: string,
|
|
cursorCreatedAt?: Date,
|
|
limit: number = 10
|
|
): Promise<CursorPagedCommentDto> {
|
|
return commentApiClient.getCommentsByApplicationFormId({
|
|
applicationFormId,
|
|
formElementId,
|
|
cursorCreatedAt,
|
|
limit
|
|
})
|
|
}
|
|
|
|
async function getGroupedCommentCountByApplicationFromId(
|
|
applicationFormId: string
|
|
): Promise<ApplicationFormCommentCountsDto> {
|
|
return commentApiClient.getGroupedCommentCountByApplicationFromId({ applicationFormId })
|
|
}
|
|
|
|
async function updateComment(id: string, commentDto: CommentDto): Promise<CommentDto> {
|
|
return commentApiClient.updateComment({ id, commentDto })
|
|
}
|
|
|
|
async function deleteCommentById(id: string): Promise<void> {
|
|
return commentApiClient.deleteComment({ id })
|
|
}
|
|
|
|
return {
|
|
createComment,
|
|
getCommentsByApplicationFormId,
|
|
getGroupedCommentCountByApplicationFromId,
|
|
updateComment,
|
|
deleteCommentById
|
|
}
|
|
}
|