Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the AutoCompleteSelect value filling for evidences attached to a requirement assessment #902

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { tableSourceMapper, type TableSource } from '@skeletonlabs/skeleton';
import type { Actions } from '@sveltejs/kit';
import { fail, redirect } from '@sveltejs/kit';
import { setFlash } from 'sveltekit-flash-message/server';
import { setError, superValidate } from 'sveltekit-superforms';
import { superValidate } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import type { PageServerLoad } from './$types';
import { z } from 'zod';
Expand Down Expand Up @@ -43,6 +43,7 @@ export const load = (async ({ fetch, params }) => {
}

const schema = modelSchema(URLModel);
object.evidences = object.evidences.map((evidence) => evidence.id);
const form = await superValidate(object, zod(schema), { errors: true });

const foreignKeys: Record<string, any> = {};
Expand Down Expand Up @@ -116,24 +117,27 @@ export const load = (async ({ fetch, params }) => {

const tables: Record<string, any> = {};

for (const key of ['applied-controls', 'evidences'] as urlModel[]) {
const keyEndpoint = `${BASE_API_URL}/${key}/?requirement_assessments=${params.id}`;
const response = await fetch(keyEndpoint);
if (response.ok) {
const data = await response.json().then((data) => data.results);
await Promise.all(
['applied-controls', 'evidences'].map(async (key) => {
const keyEndpoint = `${BASE_API_URL}/${key}/?requirement_assessments=${params.id}`;
const response = await fetch(keyEndpoint);

const bodyData = tableSourceMapper(data, listViewFields[key].body);
if (response.ok) {
const data = await response.json().then((data) => data.results);

const table: TableSource = {
head: listViewFields[key].head,
body: bodyData,
meta: data
};
tables[key] = table;
} else {
console.error(`Failed to fetch data for ${key}: ${response.statusText}`);
}
}
const bodyData = tableSourceMapper(data, listViewFields[key].body);

const table: TableSource = {
head: listViewFields[key].head,
body: bodyData,
meta: data
};
tables[key] = table;
} else {
console.error(`Failed to fetch data for ${key}: ${response.statusText}`);
}
})
);

const measureForeignKeys: Record<string, any> = {};

Expand Down
Loading