feat(fullstack): Add test application form creation
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { useUserStore } from '~~/stores/useUserStore'
|
||||
import { useTestDataApi } from '~/composables/testing/useTestDataApi'
|
||||
|
||||
/**
|
||||
* TESTING-ONLY FEATURE
|
||||
*
|
||||
* One-click duplicator for the seeded demo application form "SAP S/4HANA".
|
||||
*
|
||||
* This version uses a dedicated backend endpoint to ensure reliability:
|
||||
* 1. Loads the seeded YAML on the backend.
|
||||
* 2. Creates a fresh ApplicationForm entity with new IDs.
|
||||
* 3. Sets current user as creator.
|
||||
* 4. Assigns the form to the currently selected organization.
|
||||
*/
|
||||
export function useSeededSapS4HanaDuplicator() {
|
||||
const { t } = useI18n()
|
||||
const logger = useLogger().withTag('seeded-sap-duplicator')
|
||||
const toast = useToast()
|
||||
|
||||
const { canWriteApplicationForms } = usePermissions()
|
||||
const userStore = useUserStore()
|
||||
const { selectedOrganization } = storeToRefs(userStore)
|
||||
|
||||
const isDuplicating = ref(false)
|
||||
|
||||
const showButton = computed(() => canWriteApplicationForms.value)
|
||||
|
||||
async function duplicateSapS4HanaForTesting() {
|
||||
if (isDuplicating.value) return
|
||||
|
||||
const organizationId = selectedOrganization.value?.id
|
||||
if (!organizationId) {
|
||||
toast.add({
|
||||
title: t('common.error'),
|
||||
description: 'Please select an organization first.',
|
||||
color: 'error'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
isDuplicating.value = true
|
||||
try {
|
||||
const { createTestDataApplicationForm } = useTestDataApi()
|
||||
|
||||
const created = await createTestDataApplicationForm(organizationId)
|
||||
|
||||
toast.add({
|
||||
title: t('common.success'),
|
||||
description: 'Created a new test application form.',
|
||||
color: 'success'
|
||||
})
|
||||
|
||||
if (created?.id) {
|
||||
await navigateTo(`/application-forms/${created.id}/0`)
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
logger.error('Failed creating test application form via backend:', e)
|
||||
toast.add({
|
||||
title: t('common.error'),
|
||||
description: 'Failed to create test application form. Check backend logs.',
|
||||
color: 'error'
|
||||
})
|
||||
} finally {
|
||||
isDuplicating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
showButton,
|
||||
isDuplicating,
|
||||
duplicateSapS4HanaForTesting
|
||||
}
|
||||
}
|
||||
24
legalconsenthub/app/composables/testing/useTestDataApi.ts
Normal file
24
legalconsenthub/app/composables/testing/useTestDataApi.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { TestDataApi, Configuration, type ApplicationFormDto } from '~~/.api-client'
|
||||
import { cleanDoubleSlashes, withoutTrailingSlash } from 'ufo'
|
||||
import { wrappedFetchWrap } from '~/utils/wrappedFetch'
|
||||
|
||||
export function useTestDataApi() {
|
||||
const appBaseUrl = useRuntimeConfig().app.baseURL
|
||||
const { serverApiBasePath, clientProxyBasePath } = useRuntimeConfig().public
|
||||
|
||||
const basePath = withoutTrailingSlash(
|
||||
cleanDoubleSlashes(import.meta.client ? appBaseUrl + clientProxyBasePath : clientProxyBasePath + serverApiBasePath)
|
||||
)
|
||||
|
||||
const testDataApiClient = new TestDataApi(
|
||||
new Configuration({ basePath, fetchApi: wrappedFetchWrap(useRequestFetch()) })
|
||||
)
|
||||
|
||||
async function createTestDataApplicationForm(organizationId: string): Promise<ApplicationFormDto> {
|
||||
return testDataApiClient.createTestDataApplicationForm({ organizationId })
|
||||
}
|
||||
|
||||
return {
|
||||
createTestDataApplicationForm
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user