Update directus collections

This commit is contained in:
Maximilian Harz 2025-06-25 20:19:41 +02:00
parent b0a5f2f9ad
commit d5e730134e
2 changed files with 16 additions and 9 deletions

View File

@ -6,6 +6,7 @@ import { createDirectus, rest, authentication } from '@directus/sdk'
import type { AuthenticationData, AuthenticationStorage } from '@directus/sdk'
import type { Point } from 'geojson'
import type { Item } from 'utopia-ui'
export interface Place {
id: string
@ -50,6 +51,11 @@ interface CustomUserFields {
position: Point
}
interface ItemSecret {
secret: string
item: string
}
export interface MyCollections {
places: Place[]
events: Event[]
@ -57,6 +63,11 @@ export interface MyCollections {
tags: Tag[]
projects: Project[]
directus_users: CustomUserFields[]
item_secrets: ItemSecret[]
items: Item[]
team: any[]
features: any[]
attestations: any[]
}
export const authLocalStorage = (mainKey = 'directus_storage') =>

View File

@ -12,14 +12,14 @@ import type { MyCollections } from './directus'
import type { ItemsApi } from 'utopia-ui'
export class itemsApi<T> implements ItemsApi<T> {
collectionName: string
collectionName: keyof MyCollections
filter: any
layerId: string | undefined
mapId: string | undefined
customParameter: any
constructor(
collectionName: string,
collectionName: keyof MyCollections,
layerId?: string | undefined,
mapId?: string | undefined,
filter?: any,
@ -82,7 +82,7 @@ export class itemsApi<T> implements ItemsApi<T> {
async createItem(item: T & { id?: string }): Promise<T> {
try {
const result = await directusClient.request(
createItem(this.collectionName as keyof MyCollections, {
createItem(this.collectionName, {
...item,
...(this.customParameter && this.customParameter),
...(this.layerId && { layer: this.layerId }),
@ -100,9 +100,7 @@ export class itemsApi<T> implements ItemsApi<T> {
async updateItem(item: T & { id?: string }): Promise<T> {
try {
const result = await directusClient.request(
updateItem(this.collectionName as keyof MyCollections, item.id!, item),
)
const result = await directusClient.request(updateItem(this.collectionName, item.id!, item))
return result as T
} catch (error: any) {
console.log(error)
@ -113,9 +111,7 @@ export class itemsApi<T> implements ItemsApi<T> {
async deleteItem(id: string): Promise<boolean> {
try {
const result = await directusClient.request(
deleteItem(this.collectionName as keyof MyCollections, id),
)
const result = await directusClient.request(deleteItem(this.collectionName, id))
return result as unknown as boolean
} catch (error: any) {
console.log(error)