Added variants base functionality.
This commit is contained in:
@@ -3,6 +3,7 @@ import type {Article} from "~/types/article";
|
||||
import {NotificationMessage} from "~/types/notificationMessage";
|
||||
import type {RuntimeConfig} from "nuxt/schema";
|
||||
import {Origin} from "~/types/origin";
|
||||
import type {Variant} from "~/types/variant";
|
||||
|
||||
interface State {
|
||||
config: RuntimeConfig,
|
||||
@@ -165,5 +166,25 @@ export const useLabelEditorStore = defineStore('label_editor_store', {
|
||||
this.addNotification(true, 'Es ist kein Artikel ausgewählt');
|
||||
}
|
||||
},
|
||||
|
||||
// Variant
|
||||
async addVariant(articleID: number, variant: Variant) {
|
||||
if(this.article != null) {
|
||||
try {
|
||||
let createdVariant = await $fetch<Variant>(this.config.public.url + '/article/' + articleID + '/variant', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(variant),
|
||||
});
|
||||
|
||||
this.article.variants.push(createdVariant);
|
||||
|
||||
this.addNotification(false, 'Variante erstellt.');
|
||||
} catch {
|
||||
this.addNotification(true, 'Fehler beim erstellen der Variante.');
|
||||
}
|
||||
} else {
|
||||
this.addNotification(true, 'Kann Variante nicht erstellen. Es ist kein Artikel ausgewählt.');
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user