From 2d96f3db4d04278cc9aedbff4eb7a03aa7cc029e Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Fri, 6 Dec 2024 16:08:50 +0100 Subject: [PATCH] Treat RO/TO pertinence, motivation, resources values as numbers --- frontend/src/lib/utils/crud.ts | 6 +++--- frontend/src/lib/utils/schemas.ts | 6 +++--- .../[id=uuid]/workshop-two/ro-to/+page.server.ts | 10 +++------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/frontend/src/lib/utils/crud.ts b/frontend/src/lib/utils/crud.ts index fd8a9eb65..b0e762ebe 100644 --- a/frontend/src/lib/utils/crud.ts +++ b/frontend/src/lib/utils/crud.ts @@ -637,9 +637,9 @@ export const URL_MODEL_MAP: ModelMap = { ], selectFields: [ { field: 'risk-origin' }, - { field: 'motivation' }, - { field: 'resources' }, - { field: 'pertinence' } + { field: 'motivation', valueType: 'number' }, + { field: 'resources', valueType: 'number' }, + { field: 'pertinence', valueType: 'number' } ] } }; diff --git a/frontend/src/lib/utils/schemas.ts b/frontend/src/lib/utils/schemas.ts index 318ac0c56..ed65b698d 100644 --- a/frontend/src/lib/utils/schemas.ts +++ b/frontend/src/lib/utils/schemas.ts @@ -418,9 +418,9 @@ export const roToSchema = z.object({ feared_events: z.string().uuid().array(), risk_origin: z.string(), target_objective: z.string(), - motivation: z.string().optional(), - resources: z.string().optional(), - pertinence: z.string().optional(), + motivation: z.number().default(0).optional(), + resources: z.number().default(0).optional(), + pertinence: z.number().default(0).optional(), activity: z.number().min(0).max(4).optional().default(0), is_selected: z.boolean().optional().default(false), justification: z.string().optional() diff --git a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-two/ro-to/+page.server.ts b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-two/ro-to/+page.server.ts index ba8529259..fdad14f79 100644 --- a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-two/ro-to/+page.server.ts +++ b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-two/ro-to/+page.server.ts @@ -33,9 +33,7 @@ export const load: PageServerLoad = async ({ params, fetch }) => { for (const keyField of foreignKeyFields) { const keyModel = getModelInfo(keyField.urlModel); const queryParams = keyField.urlParams ? `?${keyField.urlParams}` : ''; - const url = keyModel.endpointUrl - ? `${BASE_API_URL}/${keyModel.endpointUrl}/${queryParams}` - : `${BASE_API_URL}/${keyModel.urlModel}/${queryParams}`; + const url = `${BASE_API_URL}/${keyModel.endpointUrl ?? keyModel.urlModel}/${queryParams}`; const response = await fetch(url); if (response.ok) { foreignKeys[keyField.field] = await response.json().then((data) => data.results); @@ -50,15 +48,13 @@ export const load: PageServerLoad = async ({ params, fetch }) => { for (const selectField of selectFields) { if (selectField.detail) continue; - const url = model.endpointUrl - ? `${BASE_API_URL}/${model.endpointUrl}/${selectField.field}/` - : `${BASE_API_URL}/${model.urlModel}/${selectField.field}/`; + const url = `${BASE_API_URL}/${model.endpointUrl ?? model.urlModel}/${selectField.field}/`; const response = await fetch(url); if (response.ok) { selectOptions[selectField.field] = await response.json().then((data) => Object.entries(data).map(([key, value]) => ({ label: value, - value: key + value: selectField.valueType === 'number' ? parseInt(key) : key })) ); } else {