Skip to content

Commit

Permalink
Treat RO/TO pertinence, motivation, resources values as numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
nas-tabchiche committed Dec 6, 2024
1 parent a137114 commit 2d96f3d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
6 changes: 3 additions & 3 deletions frontend/src/lib/utils/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
]
}
};
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/lib/utils/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down

0 comments on commit 2d96f3d

Please sign in to comment.