Started adding nutrition editing logic.
This commit is contained in:
1 parent
3ae697d852
commit
d613f8c1d7
6 files changed
+306
-15
No files matched your search
@@ -8,6 +8,7 @@ import {Unit} from "~/types/unit";
|
||||
import type {Label} from "~/types/label";
|
||||
import type {Settings} from "~/types/settings";
|
||||
import type {Supplier} from "~/types/supplier";
|
||||
import type {Nutrition} from "~/types/nutrition.ts";
|
||||
|
||||
interface State {
|
||||
config: RuntimeConfig,
|
||||
@@ -455,5 +456,56 @@ export const useLabelEditorStore = defineStore('label_editor_store', {
|
||||
this.addNotification(true, 'Fehler beim löschen des Lieferanten.');
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
// Nutrition
|
||||
async createArticleNutrition(articleID: number) {
|
||||
try {
|
||||
let article = await $fetch<Article>(this.config.public.url + '/article/' + articleID +'/nutrition', {
|
||||
method: 'POST',
|
||||
});
|
||||
|
||||
this.article = article;
|
||||
|
||||
this.addNotification(false, 'Nährwert angelegt');
|
||||
} catch {
|
||||
this.addNotification(true, 'Fehler beim anlegen der Nährwerte.');
|
||||
}
|
||||
},
|
||||
|
||||
async updateNutrition(nutrition: Nutrition): Promise<Nutrition> {
|
||||
try {
|
||||
let updatedNutrition = await $fetch<Nutrition>(this.config.public.url + '/nutrition/' + nutrition.id, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(nutrition),
|
||||
});
|
||||
|
||||
this.addNotification(false, 'Nährwert aktualisiert.');
|
||||
return updatedNutrition;
|
||||
} catch {
|
||||
this.addNotification(true, 'Fehler beim aktualisieren des Nährwerts.');
|
||||
return nutrition;
|
||||
}
|
||||
},
|
||||
|
||||
async deleteNutrition(nutrition: Nutrition): Promise<Nutrition | null> {
|
||||
try {
|
||||
await $fetch(this.config.public.url + '/nutrition/' + nutrition.id, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
|
||||
this.addNotification(false, 'Nährwert gelöscht.');
|
||||
return null;
|
||||
} catch {
|
||||
this.addNotification(true, 'Fehler beim löschen des Nährwerts.');
|
||||
return nutrition
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
// ...
|
||||
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user