Files
gremiumhub/legalconsenthub/app/composables/user/useUserApi.ts

40 lines
1.2 KiB
TypeScript

import { UserApi, Configuration, type UserDto, type UpdateEmailPreferencesDto } from '~~/.api-client'
import { cleanDoubleSlashes, withoutTrailingSlash } from 'ufo'
import { wrappedFetchWrap } from '~/utils/wrappedFetch'
export function useUserApi() {
const appBaseUrl = useRuntimeConfig().app.baseURL
const { serverApiBasePath, clientProxyBasePath } = useRuntimeConfig().public
const basePath = withoutTrailingSlash(
cleanDoubleSlashes(
import.meta.client
? appBaseUrl + clientProxyBasePath
: useRequestURL().origin + clientProxyBasePath + serverApiBasePath
)
)
const userApiClient = new UserApi(new Configuration({ basePath, fetchApi: wrappedFetchWrap(useRequestFetch()) }))
async function getUserById(id: string): Promise<UserDto> {
return userApiClient.getUserById({ id })
}
async function updateEmailPreferences(
id: string,
updateEmailPreferencesDto: UpdateEmailPreferencesDto
): Promise<UserDto> {
return userApiClient.updateUserEmailPreferences({ id, updateEmailPreferencesDto })
}
async function deleteUser(id: string): Promise<void> {
return userApiClient.deleteUser({ id })
}
return {
getUserById,
updateEmailPreferences,
deleteUser
}
}