extended api

This commit is contained in:
Anton 2023-09-01 00:56:09 +02:00
parent 109a4eccae
commit 968e7303d4
2 changed files with 13 additions and 4 deletions

View File

@ -9,6 +9,11 @@ export type Place = {
text: string;
position?: Point;
};
export type Tag = {
id: string;
color: string;
};
export type Event = {
id: string;

View File

@ -17,30 +17,34 @@ export class itemsApi<T> implements ItemsApi<T>{
return await directusClient.request(readItems(this.collectionName as never,{limit: 500 }));
} catch (error) {
console.log(error);
throw new Error("Failed while loading items");
}
}
async createItem(item: T & { id?: string }) {
async createItem(item: T & { id?: string }) {
try {
return await directusClient.request(createItem(this.collectionName as keyof MyCollections,item))
} catch (error) {
} catch (error: any) {
console.log(error);
throw new Error(error.errors[0].message);
}
}
async updateItem(item: T & { id?: string }) {
try {
return await directusClient.request(updateItem(this.collectionName as keyof MyCollections,item.id!, item))
} catch (error) {
} catch (error: any) {
console.log(error);
throw new Error(error.errors[0].message);
}
}
async deleteItem(id: string ) {
try {
return await directusClient.request(deleteItem(this.collectionName as keyof MyCollections,id))
} catch (error) {
} catch (error: any) {
console.log(error);
throw new Error(error.errors[0].message);
}
}
}