28 lines
826 B
JavaScript
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 };
|
|
});
|