claude 5
This commit is contained in:
34
frontend/src/stores/fabrications.js
Normal file
34
frontend/src/stores/fabrications.js
Normal file
@@ -0,0 +1,34 @@
|
||||
// frontend/src/stores/fabrications.ts
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import { fabricationsApi } from '@/api/fabrications';
|
||||
export const useFabricationsStore = defineStore('fabrications', () => {
|
||||
const fabrications = ref([]);
|
||||
const loading = ref(false);
|
||||
async function fetchAll(params) {
|
||||
loading.value = true;
|
||||
try {
|
||||
fabrications.value = await fabricationsApi.list(params);
|
||||
}
|
||||
finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
async function create(f) {
|
||||
const created = await fabricationsApi.create(f);
|
||||
fabrications.value.unshift(created);
|
||||
return created;
|
||||
}
|
||||
async function updateStatut(id, statut) {
|
||||
const updated = await fabricationsApi.updateStatut(id, statut);
|
||||
const idx = fabrications.value.findIndex(f => f.id === id);
|
||||
if (idx !== -1)
|
||||
fabrications.value[idx] = updated;
|
||||
return updated;
|
||||
}
|
||||
async function remove(id) {
|
||||
await fabricationsApi.delete(id);
|
||||
fabrications.value = fabrications.value.filter(f => f.id !== id);
|
||||
}
|
||||
return { fabrications, loading, fetchAll, create, updateStatut, remove };
|
||||
});
|
||||
Reference in New Issue
Block a user