From 35acd015b83533c00aaf3d47660b2d3a3f91b9a2 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 23 Dec 2025 07:50:01 +0100 Subject: [PATCH] fix(app): fix Directus API responses missing relational data (offers, needs, relations) (#619) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: antontranelis <31516529+antontranelis@users.noreply.github.com> Co-authored-by: mahula --- app/src/api/itemsApi.ts | 52 +++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/app/src/api/itemsApi.ts b/app/src/api/itemsApi.ts index 7b60142f..7522842a 100644 --- a/app/src/api/itemsApi.ts +++ b/app/src/api/itemsApi.ts @@ -11,6 +11,17 @@ import { directusClient } from './directus' import type { MyCollections } from './directus' import type { ItemsApi } from 'utopia-ui' +// Fields to request when fetching items to include all relational data +const ITEM_FIELDS = [ + '*', + 'secrets.*', + 'to.*', + 'relations.*', + 'user_created.*', + 'markerIcon.*', + { offers: ['*'], needs: ['*'], gallery: ['*.*'] } as any, +] + export class itemsApi implements ItemsApi { collectionName: keyof MyCollections filter: any @@ -43,15 +54,7 @@ export class itemsApi implements ItemsApi { try { const result = await directusClient.request( readItems(this.collectionName as never, { - fields: [ - '*', - 'secrets.*', - 'to.*', - 'relations.*', - 'user_created.*', - 'markerIcon.*', - { offers: ['*'], needs: ['*'], gallery: ['*.*'] } as any, - ], + fields: ITEM_FIELDS, filter: this.filter, limit: -1, }), @@ -70,7 +73,11 @@ export class itemsApi implements ItemsApi { async getItem(id: string): Promise { try { - const result = await directusClient.request(readItem(this.collectionName as never, id)) + const result = await directusClient.request( + readItem(this.collectionName as never, id, { + fields: ITEM_FIELDS, + }), + ) return result as T } catch (error: any) { console.log(error) @@ -82,13 +89,18 @@ export class itemsApi implements ItemsApi { async createItem(item: T & { id?: string }): Promise { try { const result = await directusClient.request( - createItem(this.collectionName, { - ...item, - ...(this.customParameter && this.customParameter), - ...(this.layerId && { layer: this.layerId }), - ...(this.layerId && { layer: this.layerId }), - ...(this.mapId && { map: this.mapId }), - }), + createItem( + this.collectionName, + { + ...item, + ...(this.customParameter && this.customParameter), + ...(this.layerId && { layer: this.layerId }), + ...(this.mapId && { map: this.mapId }), + }, + { + fields: ITEM_FIELDS, + }, + ), ) return result as T } catch (error: any) { @@ -100,7 +112,11 @@ export class itemsApi implements ItemsApi { async updateItem(item: T & { id?: string }): Promise { try { - const result = await directusClient.request(updateItem(this.collectionName, item.id!, item)) + const result = await directusClient.request( + updateItem(this.collectionName, item.id!, item, { + fields: ITEM_FIELDS, + }), + ) return result as T } catch (error: any) { console.log(error)