adjust itemsApi

This commit is contained in:
Anton Tranelis 2024-02-01 11:06:58 +01:00
parent efaa9aac69
commit 3c0481cbfc
3 changed files with 118 additions and 1511 deletions

1615
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -16,8 +16,7 @@
"axios": "^1.6.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.11.2",
"utopia-ui": "^3.0.0-alpha.62"
"react-router-dom": "^6.11.2"
},
"devDependencies": {
"@types/react": "^18.0.28",

View File

@ -9,6 +9,8 @@ export class itemsApi<T> implements ItemsApi<T>{
collectionName: string;
filter: any;
layerId: string | undefined;
mapId: string | undefined;
constructor(collectionName: string, layerId?: string | undefined, mapId?: string | undefined, filter?: any, ) {
this.collectionName = collectionName;
@ -18,9 +20,10 @@ export class itemsApi<T> implements ItemsApi<T>{
if(layerId) {
this.filter = {... filter, ... { "layer" : { "id": { "_eq": layerId }}}}
}
if(mapId) this.filter = {... filter, ... { "map" : { "id": { "_eq": mapId }}}}
console.log(this.filter);
this.mapId = mapId;
if(mapId) {
this.filter = {... filter, ... { "map" : { "id": { "_eq": mapId }}}}
}
}
async getItems() {
@ -47,7 +50,7 @@ export class itemsApi<T> implements ItemsApi<T>{
async createItem(item: T & { id?: string }) {
try {
return await directusClient.request(createItem(this.collectionName as keyof MyCollections, {...item, ...(this.layerId && {layer: this.layerId})}))
return await directusClient.request(createItem(this.collectionName as keyof MyCollections, {...item, ...(this.layerId && {layer: this.layerId}), ...(this.layerId && {layer: this.layerId}), ...(this.mapId && {map: this.mapId})}))
} catch (error: any) {
console.log(error);
if (error.errors[0]?.message)