Files

56 lines
1.7 KiB
TypeScript

import axios, { AxiosError } from 'axios';
import { Note, PipelineItem } from '@/types';
import { toast } from 'vue-sonner';
const API_URL = '/api/pipeline';
const ITEMS_API_URL = '/api/pipelineItems';
export default {
/**
* Deletes an item by ID
* @param id - The id of the item to delete
* @returns boolean - True if the item was deleted, false otherwise
*/
async deletePipelineItem(id: number): Promise<boolean> {
try {
const response = await axios.delete(`${ITEMS_API_URL}/${id}`);
return true;
} catch (error) {
toast.error('Fehler beim Löschen des Vorgangs', { description: (error as AxiosError).message })
console.error(error)
return false;
}
},
/**
* Creates a new pipeline item
* @param item
* @returns
*/
async createPipelineItem(item: PipelineItem): Promise<PipelineItem | null> {
try {
const response = await axios.post(ITEMS_API_URL, item);
return response.data;
} catch (error) {
toast.error('Fehler beim Speichern des Vorgangs', { description: (error as AxiosError).message })
console.error(error)
return null;
}
},
/**
* Updates an existing pipeline item
* @param item
* @returns
*/
async updatePipelineItem(item: PipelineItem): Promise<PipelineItem | null> {
try {
const response = await axios.put(ITEMS_API_URL + '/' + item.id, item);
return response.data;
} catch (error) {
toast.error('Fehler beim Speichern des Vorgangs', { description: (error as AxiosError).message })
console.error(error)
return null;
}
}
};