mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2026-03-01 12:44:17 +00:00
Update directus collections
This commit is contained in:
parent
13612c56aa
commit
847cb69c17
@ -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') =>
|
||||
|
||||
@ -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,
|
||||
@ -81,7 +81,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 }),
|
||||
@ -99,9 +99,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)
|
||||
@ -112,9 +110,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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user