mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2026-01-20 20:01:18 +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 { MyCollections } from './directus'
|
||||||
import type { ItemsApi } from 'utopia-ui'
|
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> {
|
export class itemsApi<T> implements ItemsApi<T> {
|
||||||
collectionName: keyof MyCollections
|
collectionName: keyof MyCollections
|
||||||
filter: any
|
filter: any
|
||||||
@ -43,15 +54,7 @@ export class itemsApi<T> implements ItemsApi<T> {
|
|||||||
try {
|
try {
|
||||||
const result = await directusClient.request<T[]>(
|
const result = await directusClient.request<T[]>(
|
||||||
readItems(this.collectionName as never, {
|
readItems(this.collectionName as never, {
|
||||||
fields: [
|
fields: ITEM_FIELDS,
|
||||||
'*',
|
|
||||||
'secrets.*',
|
|
||||||
'to.*',
|
|
||||||
'relations.*',
|
|
||||||
'user_created.*',
|
|
||||||
'markerIcon.*',
|
|
||||||
{ offers: ['*'], needs: ['*'], gallery: ['*.*'] } as any,
|
|
||||||
],
|
|
||||||
filter: this.filter,
|
filter: this.filter,
|
||||||
limit: -1,
|
limit: -1,
|
||||||
}),
|
}),
|
||||||
@ -70,7 +73,11 @@ export class itemsApi<T> implements ItemsApi<T> {
|
|||||||
|
|
||||||
async getItem(id: string): Promise<T> {
|
async getItem(id: string): Promise<T> {
|
||||||
try {
|
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
|
return result as T
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
@ -82,13 +89,18 @@ export class itemsApi<T> implements ItemsApi<T> {
|
|||||||
async createItem(item: T & { id?: string }): Promise<T> {
|
async createItem(item: T & { id?: string }): Promise<T> {
|
||||||
try {
|
try {
|
||||||
const result = await directusClient.request(
|
const result = await directusClient.request(
|
||||||
createItem(this.collectionName, {
|
createItem(
|
||||||
...item,
|
this.collectionName,
|
||||||
...(this.customParameter && this.customParameter),
|
{
|
||||||
...(this.layerId && { layer: this.layerId }),
|
...item,
|
||||||
...(this.layerId && { layer: this.layerId }),
|
...(this.customParameter && this.customParameter),
|
||||||
...(this.mapId && { map: this.mapId }),
|
...(this.layerId && { layer: this.layerId }),
|
||||||
}),
|
...(this.mapId && { map: this.mapId }),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fields: ITEM_FIELDS,
|
||||||
|
},
|
||||||
|
),
|
||||||
)
|
)
|
||||||
return result as T
|
return result as T
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@ -100,7 +112,11 @@ export class itemsApi<T> implements ItemsApi<T> {
|
|||||||
|
|
||||||
async updateItem(item: T & { id?: string }): Promise<T> {
|
async updateItem(item: T & { id?: string }): Promise<T> {
|
||||||
try {
|
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
|
return result as T
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user