diff --git a/frontend/src/lib/utils/constants.ts b/frontend/src/lib/utils/constants.ts index f377d6b60..7062fbcdc 100644 --- a/frontend/src/lib/utils/constants.ts +++ b/frontend/src/lib/utils/constants.ts @@ -31,7 +31,7 @@ export const MONTH_LIST = [ 'December' ]; -const UUID_REGEX = '([0-9a-f]{8}\\-[0-9a-f]{4}\\-[0-9a-f]{4}\\-[0-9a-f]{4}\\-[0-9a-f]{12})'; +export const UUID_REGEX = '([0-9a-f]{8}\\-[0-9a-f]{4}\\-[0-9a-f]{4}\\-[0-9a-f]{4}\\-[0-9a-f]{12})'; export const UUID_LIST_REGEX = new RegExp(`^${UUID_REGEX}(,${UUID_REGEX})*$`); export const URN_REGEX = diff --git a/frontend/src/routes/(app)/[model=urlmodel]/[id=uuid]/+layout.server.ts b/frontend/src/routes/(app)/[model=urlmodel]/[id=uuid]/+layout.server.ts index bcc518f21..7e9e4d059 100644 --- a/frontend/src/routes/(app)/[model=urlmodel]/[id=uuid]/+layout.server.ts +++ b/frontend/src/routes/(app)/[model=urlmodel]/[id=uuid]/+layout.server.ts @@ -1,4 +1,4 @@ -import { BASE_API_URL } from '$lib/utils/constants'; +import { BASE_API_URL, UUID_REGEX } from '$lib/utils/constants'; import { URL_MODEL_MAP, getModelInfo, type ModelMapEntry } from '$lib/utils/crud'; import { tableSourceMapper, type TableSource } from '@skeletonlabs/skeleton'; @@ -67,7 +67,16 @@ export const load: LayoutServerLoad = async ({ fetch, params }) => { const deleteForm = await superValidate(zod(z.object({ id: z.string().uuid() }))); const createSchema = modelSchema(e.urlModel); initialData[e.field] = data.id; - if (data.folder) initialData['folder'] = data.folder.id ?? data.folder; + if (data.folder) { + if (!new RegExp(UUID_REGEX).test(data.folder)) { + const objectEndpoint = `${endpoint}object/`; + const objectResponse = await fetch(objectEndpoint); + const objectData = await objectResponse.json(); + initialData['folder'] = objectData.folder; + } else { + initialData['folder'] = data.folder.id ?? data.folder; + } + } const createForm = await superValidate(initialData, zod(createSchema), { errors: false }); const foreignKeys: Record = {};