Skip to content

Commit

Permalink
feat: filter feared-events in ro/to
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Hacene committed Dec 13, 2024
1 parent dc05c89 commit 9f08593
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
5 changes: 3 additions & 2 deletions frontend/src/lib/utils/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ interface ForeignKeyField {
urlModel: urlModel;
endpointUrl?: string;
urlParams?: string;
detail?: boolean;
}

interface Field {
Expand Down Expand Up @@ -624,7 +625,7 @@ export const URL_MODEL_MAP: ModelMap = {
verboseNamePlural: 'Feared events',
foreignKeyFields: [
{ field: 'ebios_rm_study', urlModel: 'ebios-rm', endpointUrl: 'ebios-rm/studies' },
{ field: 'assets', urlModel: 'assets', urlParams: 'ebios_rm_studies=' },
{ field: 'assets', urlModel: 'assets', urlParams: 'ebios_rm_studies=', detail: true },
{ field: 'qualifications', urlModel: 'qualifications' }
],
selectFields: [{ field: 'gravity', valueType: 'number', detail: true }]
Expand All @@ -638,7 +639,7 @@ export const URL_MODEL_MAP: ModelMap = {
verboseNamePlural: 'Ro to',
foreignKeyFields: [
{ field: 'ebios_rm_study', urlModel: 'ebios-rm', endpointUrl: 'ebios-rm/studies' },
{ field: 'feared_events', urlModel: 'feared-events', endpointUrl: 'ebios-rm/feared-events' }
{ field: 'feared_events', urlModel: 'feared-events', endpointUrl: 'ebios-rm/feared-events', urlParams: 'ebios_rm_study=', detail: true }
],
selectFields: [
{ field: 'risk-origin' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,10 @@ export const load: PageServerLoad = async ({ params, fetch }) => {

for (const keyField of foreignKeyFields) {
const model = getModelInfo(keyField.urlModel);
const queryParams = keyField.urlParams ? `?${keyField.urlParams}` : '';
const queryParams = keyField.urlParams ? `?${keyField.urlParams}${keyField.detail ? params.id : ''}` : '';
let url = model.endpointUrl
? `${BASE_API_URL}/${model.endpointUrl}/${queryParams}`
: `${BASE_API_URL}/${model.urlModel}/${queryParams}`;
if (model.urlModel === 'assets') {
url = `${BASE_API_URL}/${model.urlModel}/${queryParams}${params.id}`;
}
const response = await fetch(url);
if (response.ok) {
foreignKeys[keyField.field] = await response.json().then((data) => data.results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,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 queryParams = keyField.urlParams ? `?${keyField.urlParams}${keyField.detail ? params.id : ''}` : '';
const url = `${BASE_API_URL}/${keyModel.endpointUrl ?? keyModel.urlModel}/${queryParams}`;
const response = await fetch(url);
if (response.ok) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const load: PageServerLoad = async (event) => {

if (foreignKeyFields) {
for (const keyField of foreignKeyFields) {
const queryParams = keyField.urlParams ? `?${keyField.urlParams}` : '';
const queryParams = keyField.urlParams ? `?${keyField.urlParams}${keyField.detail ? object.ebios_rm_study : ''}` : '';
const url = `${BASE_API_URL}/${keyField.endpointUrl || keyField.urlModel}/${queryParams}`;
const response = await event.fetch(url);
if (response.ok) {
Expand Down

0 comments on commit 9f08593

Please sign in to comment.