Files
jardin/frontend/src/stores/achats.js
2026-03-09 18:19:38 +01:00

28 lines
826 B
JavaScript

// frontend/src/stores/achats.ts
import { defineStore } from 'pinia';
import { ref } from 'vue';
import { achatsApi } from '@/api/achats';
export const useAchatsStore = defineStore('achats', () => {
const achats = ref([]);
const loading = ref(false);
async function fetchAll(params) {
loading.value = true;
try {
achats.value = await achatsApi.list(params);
}
finally {
loading.value = false;
}
}
async function create(a) {
const created = await achatsApi.create(a);
achats.value.unshift(created);
return created;
}
async function remove(id) {
await achatsApi.delete(id);
achats.value = achats.value.filter(a => a.id !== id);
}
return { achats, loading, fetchAll, create, remove };
});