mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2026-01-14 00:44:31 +00:00
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 <lenzmath@posteo.de>
This commit is contained in:
parent
ed6613ac55
commit
35acd015b8
@ -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<T> implements ItemsApi<T> {
|
||||
collectionName: keyof MyCollections
|
||||
filter: any
|
||||
@ -43,15 +54,7 @@ export class itemsApi<T> implements ItemsApi<T> {
|
||||
try {
|
||||
const result = await directusClient.request<T[]>(
|
||||
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<T> implements ItemsApi<T> {
|
||||
|
||||
async getItem(id: string): Promise<T> {
|
||||
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<T> implements ItemsApi<T> {
|
||||
async createItem(item: T & { id?: string }): Promise<T> {
|
||||
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<T> implements ItemsApi<T> {
|
||||
|
||||
async updateItem(item: T & { id?: string }): Promise<T> {
|
||||
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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user