feat(#23): Add email notifications
This commit is contained in:
@@ -5,3 +5,5 @@ export { useApplicationFormVersionApi } from './applicationFormVersion/useApplic
|
||||
export { useApplicationFormNavigation } from './useApplicationFormNavigation'
|
||||
export { useNotification } from './notification/useNotification'
|
||||
export { useNotificationApi } from './notification/useNotificationApi'
|
||||
export { useUser } from './user/useUser'
|
||||
export { useUserApi } from './user/useUserApi'
|
||||
|
||||
26
legalconsenthub/app/composables/user/useUser.ts
Normal file
26
legalconsenthub/app/composables/user/useUser.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { UpdateEmailPreferencesDto, UserDto } from '~~/.api-client'
|
||||
import { useUserApi } from '~/composables'
|
||||
|
||||
export function useUser() {
|
||||
const userApi = useUserApi()
|
||||
|
||||
async function getUserById(userId: string): Promise<UserDto> {
|
||||
return await userApi.getUserById(userId)
|
||||
}
|
||||
|
||||
async function updateEmailPreferences(
|
||||
userId: string,
|
||||
email: string | null,
|
||||
emailOnFormCreated: boolean,
|
||||
emailOnFormSubmitted: boolean
|
||||
): Promise<UserDto> {
|
||||
const updateDto: UpdateEmailPreferencesDto = { email, emailOnFormCreated, emailOnFormSubmitted }
|
||||
|
||||
return await userApi.updateEmailPreferences(userId, updateDto)
|
||||
}
|
||||
|
||||
return {
|
||||
getUserById,
|
||||
updateEmailPreferences
|
||||
}
|
||||
}
|
||||
42
legalconsenthub/app/composables/user/useUserApi.ts
Normal file
42
legalconsenthub/app/composables/user/useUserApi.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user