maj via codex
This commit is contained in:
33
frontend/src/stores/astuces.js
Normal file
33
frontend/src/stores/astuces.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import { ref } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import { astucesApi } from '@/api/astuces';
|
||||
export const useAstucesStore = defineStore('astuces', () => {
|
||||
const astuces = ref([]);
|
||||
const loading = ref(false);
|
||||
async function fetchAll(params) {
|
||||
loading.value = true;
|
||||
try {
|
||||
astuces.value = await astucesApi.list(params);
|
||||
}
|
||||
finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
async function create(a) {
|
||||
const created = await astucesApi.create(a);
|
||||
astuces.value.unshift(created);
|
||||
return created;
|
||||
}
|
||||
async function update(id, data) {
|
||||
const updated = await astucesApi.update(id, data);
|
||||
const idx = astuces.value.findIndex(x => x.id === id);
|
||||
if (idx !== -1)
|
||||
astuces.value[idx] = updated;
|
||||
return updated;
|
||||
}
|
||||
async function remove(id) {
|
||||
await astucesApi.remove(id);
|
||||
astuces.value = astuces.value.filter(a => a.id !== id);
|
||||
}
|
||||
return { astuces, loading, fetchAll, create, update, remove };
|
||||
});
|
||||
37
frontend/src/stores/astuces.ts
Normal file
37
frontend/src/stores/astuces.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import { astucesApi, type Astuce } from '@/api/astuces'
|
||||
|
||||
export const useAstucesStore = defineStore('astuces', () => {
|
||||
const astuces = ref<Astuce[]>([])
|
||||
const loading = ref(false)
|
||||
|
||||
async function fetchAll(params?: { categorie?: string; mois?: number; tag?: string }) {
|
||||
loading.value = true
|
||||
try {
|
||||
astuces.value = await astucesApi.list(params)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function create(a: Omit<Astuce, 'id' | 'created_at'>) {
|
||||
const created = await astucesApi.create(a)
|
||||
astuces.value.unshift(created)
|
||||
return created
|
||||
}
|
||||
|
||||
async function update(id: number, data: Partial<Astuce>) {
|
||||
const updated = await astucesApi.update(id, data)
|
||||
const idx = astuces.value.findIndex(x => x.id === id)
|
||||
if (idx !== -1) astuces.value[idx] = updated
|
||||
return updated
|
||||
}
|
||||
|
||||
async function remove(id: number) {
|
||||
await astucesApi.remove(id)
|
||||
astuces.value = astuces.value.filter(a => a.id !== id)
|
||||
}
|
||||
|
||||
return { astuces, loading, fetchAll, create, update, remove }
|
||||
})
|
||||
@@ -14,9 +14,16 @@ export const useGardensStore = defineStore('gardens', () => {
|
||||
gardens.value.push(created);
|
||||
return created;
|
||||
}
|
||||
async function update(id, g) {
|
||||
const updated = await gardensApi.update(id, g);
|
||||
const idx = gardens.value.findIndex(x => x.id === id);
|
||||
if (idx !== -1)
|
||||
gardens.value[idx] = updated;
|
||||
return updated;
|
||||
}
|
||||
async function remove(id) {
|
||||
await gardensApi.delete(id);
|
||||
gardens.value = gardens.value.filter(g => g.id !== id);
|
||||
}
|
||||
return { gardens, loading, fetchAll, create, remove };
|
||||
return { gardens, loading, fetchAll, create, update, remove };
|
||||
});
|
||||
|
||||
@@ -14,9 +14,16 @@ export const usePlantingsStore = defineStore('plantings', () => {
|
||||
plantings.value.push(created);
|
||||
return created;
|
||||
}
|
||||
async function update(id, p) {
|
||||
const updated = await plantingsApi.update(id, p);
|
||||
const idx = plantings.value.findIndex(x => x.id === id);
|
||||
if (idx !== -1)
|
||||
plantings.value[idx] = updated;
|
||||
return updated;
|
||||
}
|
||||
async function remove(id) {
|
||||
await plantingsApi.delete(id);
|
||||
plantings.value = plantings.value.filter(p => p.id !== id);
|
||||
}
|
||||
return { plantings, loading, fetchAll, create, remove };
|
||||
return { plantings, loading, fetchAll, create, update, remove };
|
||||
});
|
||||
|
||||
@@ -14,6 +14,13 @@ export const useTasksStore = defineStore('tasks', () => {
|
||||
tasks.value.push(created);
|
||||
return created;
|
||||
}
|
||||
async function update(id, data) {
|
||||
const updated = await tasksApi.update(id, data);
|
||||
const idx = tasks.value.findIndex(t => t.id === id);
|
||||
if (idx !== -1)
|
||||
tasks.value[idx] = updated;
|
||||
return updated;
|
||||
}
|
||||
async function updateStatut(id, statut) {
|
||||
const t = tasks.value.find(t => t.id === id);
|
||||
if (!t)
|
||||
@@ -25,5 +32,5 @@ export const useTasksStore = defineStore('tasks', () => {
|
||||
await tasksApi.delete(id);
|
||||
tasks.value = tasks.value.filter(t => t.id !== id);
|
||||
}
|
||||
return { tasks, loading, fetchAll, create, updateStatut, remove };
|
||||
return { tasks, loading, fetchAll, create, update, updateStatut, remove };
|
||||
});
|
||||
|
||||
@@ -18,9 +18,16 @@ export const useToolsStore = defineStore('tools', () => {
|
||||
tools.value.push(created);
|
||||
return created;
|
||||
}
|
||||
async function update(id, t) {
|
||||
const updated = await toolsApi.update(id, t);
|
||||
const idx = tools.value.findIndex(x => x.id === id);
|
||||
if (idx !== -1)
|
||||
tools.value[idx] = updated;
|
||||
return updated;
|
||||
}
|
||||
async function remove(id) {
|
||||
await toolsApi.delete(id);
|
||||
tools.value = tools.value.filter(t => t.id !== id);
|
||||
}
|
||||
return { tools, loading, fetchAll, create, remove };
|
||||
return { tools, loading, fetchAll, create, update, remove };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user