Skip to content

Commit

Permalink
fix: add dynamically controls in scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Hacene committed Dec 27, 2024
1 parent 1af2a58 commit cb7c6f2
Show file tree
Hide file tree
Showing 2 changed files with 259 additions and 254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,13 @@ export const actions: Actions = {
const scenarioEndpoint = `${BASE_API_URL}/risk-scenarios/${event.params.id}/`;
const scenario = await event.fetch(`${scenarioEndpoint}object`).then((res) => res.json());

const measures = [...scenario.applied_controls, measure.id];
const field: string = event.url.searchParams.get('field') || 'applied_controls';

const measures = [...scenario[field], measure.id];

const patchRequestInitOptions: RequestInit = {
method: 'PATCH',
body: JSON.stringify({ applied_controls: measures })
body: JSON.stringify({ [field]: measures })
};

const patchRes = await event.fetch(scenarioEndpoint, patchRequestInitOptions);
Expand Down
Loading

0 comments on commit cb7c6f2

Please sign in to comment.