feat(intrants): frontend API clients + Pinia stores
This commit is contained in:
28
frontend/src/stores/achats.ts
Normal file
28
frontend/src/stores/achats.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
// frontend/src/stores/achats.ts
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { achatsApi, type AchatIntrant } from '@/api/achats'
|
||||
|
||||
export const useAchatsStore = defineStore('achats', () => {
|
||||
const achats = ref<AchatIntrant[]>([])
|
||||
const loading = ref(false)
|
||||
|
||||
async function fetchAll(params?: { categorie?: string }) {
|
||||
loading.value = true
|
||||
try { achats.value = await achatsApi.list(params) }
|
||||
finally { loading.value = false }
|
||||
}
|
||||
|
||||
async function create(a: Partial<AchatIntrant>) {
|
||||
const created = await achatsApi.create(a)
|
||||
achats.value.unshift(created)
|
||||
return created
|
||||
}
|
||||
|
||||
async function remove(id: number) {
|
||||
await achatsApi.delete(id)
|
||||
achats.value = achats.value.filter(a => a.id !== id)
|
||||
}
|
||||
|
||||
return { achats, loading, fetchAll, create, remove }
|
||||
})
|
||||
35
frontend/src/stores/fabrications.ts
Normal file
35
frontend/src/stores/fabrications.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
// frontend/src/stores/fabrications.ts
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { fabricationsApi, type Fabrication } from '@/api/fabrications'
|
||||
|
||||
export const useFabricationsStore = defineStore('fabrications', () => {
|
||||
const fabrications = ref<Fabrication[]>([])
|
||||
const loading = ref(false)
|
||||
|
||||
async function fetchAll(params?: { type?: string; statut?: string }) {
|
||||
loading.value = true
|
||||
try { fabrications.value = await fabricationsApi.list(params) }
|
||||
finally { loading.value = false }
|
||||
}
|
||||
|
||||
async function create(f: Partial<Fabrication>) {
|
||||
const created = await fabricationsApi.create(f)
|
||||
fabrications.value.unshift(created)
|
||||
return created
|
||||
}
|
||||
|
||||
async function updateStatut(id: number, statut: string) {
|
||||
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: number) {
|
||||
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