-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create risk analysis from ebios detailed view
- Loading branch information
1 parent
87c60c4
commit 90e320f
Showing
5 changed files
with
119 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/+layout.server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { loadDetail } from '$lib/utils/load'; | ||
import type { PageServerLoad } from './$types'; | ||
import { getModelInfo } from '$lib/utils/crud'; | ||
|
||
export const load: PageServerLoad = async (event) => { | ||
return await loadDetail({ event, model: getModelInfo('ebios-rm'), id: event.params.id }); | ||
}; |
46 changes: 42 additions & 4 deletions
46
frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/+page.server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,45 @@ | ||
import { loadDetail } from '$lib/utils/load'; | ||
import { defaultDeleteFormAction, defaultWriteFormAction } from '$lib/utils/actions'; | ||
import { BASE_API_URL } from '$lib/utils/constants'; | ||
import { | ||
getModelInfo, | ||
urlParamModelForeignKeyFields, | ||
urlParamModelSelectFields | ||
} from '$lib/utils/crud'; | ||
import { modelSchema } from '$lib/utils/schemas'; | ||
import type { ModelInfo } from '$lib/utils/types'; | ||
import { type Actions } from '@sveltejs/kit'; | ||
import { superValidate } from 'sveltekit-superforms'; | ||
import { zod } from 'sveltekit-superforms/adapters'; | ||
import type { PageServerLoad } from './$types'; | ||
import { getModelInfo } from '$lib/utils/crud'; | ||
|
||
export const load: PageServerLoad = async (event) => { | ||
return await loadDetail({ event, model: getModelInfo('ebios-rm'), id: event.params.id }); | ||
export const load: PageServerLoad = async ({ params, fetch }) => { | ||
const URLModel = 'ebios-rm'; | ||
const model: ModelInfo = getModelInfo(URLModel); | ||
|
||
const endpoint = model.endpointUrl | ||
? `${BASE_API_URL}/${model.endpointUrl}/${params.id}/` | ||
: `${BASE_API_URL}/${model.urlModel}/${params.id}/`; | ||
const res = await fetch(endpoint); | ||
const data = await res.json(); | ||
|
||
const initialData = { | ||
risk_matrix: data.risk_matrix.id | ||
} | ||
|
||
const createSchema = modelSchema('risk-assessments'); | ||
const createRiskAnalysisForm = await superValidate(initialData, zod(createSchema), { errors: false }); | ||
|
||
return { createRiskAnalysisForm, model: getModelInfo('risk-assessments') }; | ||
}; | ||
|
||
export const actions: Actions = { | ||
create: async (event) => { | ||
// const redirectToWrittenObject = Boolean(event.params.model === 'entity-assessments'); | ||
return defaultWriteFormAction({ | ||
event, | ||
urlModel: 'risk-assessments', | ||
action: 'create' | ||
// redirectToWrittenObject: redirectToWrittenObject | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters