Functionality to create, update and delete label.
This commit is contained in:
@@ -5,6 +5,7 @@ import type {RuntimeConfig} from "nuxt/schema";
|
||||
import {Origin} from "~/types/origin";
|
||||
import type {Variant} from "~/types/variant";
|
||||
import {Unit} from "~/types/unit";
|
||||
import type {Label} from "~/types/label";
|
||||
|
||||
interface State {
|
||||
config: RuntimeConfig,
|
||||
@@ -21,6 +22,8 @@ interface State {
|
||||
article: Article | null,
|
||||
articleEdit: Article | null,
|
||||
|
||||
labels: Array<Label>,
|
||||
|
||||
origins: Array<Origin>,
|
||||
units: Array<Unit>,
|
||||
}
|
||||
@@ -41,6 +44,8 @@ export const useLabelEditorStore = defineStore('label_editor_store', {
|
||||
article: null,
|
||||
articleEdit: null,
|
||||
|
||||
labels: [],
|
||||
|
||||
origins: [
|
||||
Origin.EU,
|
||||
Origin.NonEU,
|
||||
@@ -117,6 +122,68 @@ export const useLabelEditorStore = defineStore('label_editor_store', {
|
||||
this.addNotification(false, "Benachrichtigungen gelöscht")
|
||||
},
|
||||
|
||||
async loadLabels() {
|
||||
try {
|
||||
const labels: Array<Label> = await $fetch<Array<Label>>(this.config.public.url + '/label', {
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
this.labels = labels;
|
||||
|
||||
this.addNotification(false, 'Etiketten Typen geladen');
|
||||
} catch {
|
||||
this.addNotification(true, 'Fehler beim laden der Etiketten Typen');
|
||||
}
|
||||
},
|
||||
|
||||
async createLabel(label: Label) {
|
||||
try {
|
||||
let createdLabel = await $fetch<Label>(this.config.public.url + '/label', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(label),
|
||||
});
|
||||
|
||||
this.labels.push(createdLabel);
|
||||
|
||||
this.addNotification(false, 'Etiketten Typ "' + createdLabel.name + '" erstellt');
|
||||
} catch {
|
||||
this.addNotification(true, 'Fehler beim erstellen des Etiketten Typ: ' + label.name);
|
||||
}
|
||||
},
|
||||
|
||||
async updateLabel(label: Label) {
|
||||
let labelIndex = this.labels.findIndex(i => i.id === label.id);
|
||||
|
||||
try {
|
||||
let updatedLabel = await $fetch<Label>(this.config.public.url + '/label/' + label.id, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(label),
|
||||
});
|
||||
|
||||
this.labels[labelIndex] = updatedLabel;
|
||||
|
||||
this.addNotification(false, 'Etiketten Typ aktualisiert.');
|
||||
} catch {
|
||||
this.addNotification(true, 'Fehler beim aktualisieren des Etiketten Typen.');
|
||||
}
|
||||
},
|
||||
|
||||
async deleteLabel(labelID: number) {
|
||||
let labelIndex = this.labels.findIndex(i => i.id === labelID);
|
||||
|
||||
try {
|
||||
await $fetch(this.config.public.url + '/label/' + labelID, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
|
||||
this.labels.splice(labelIndex, 1);
|
||||
|
||||
this.addNotification(false, 'Etiketten Typ aktualisiert.');
|
||||
} catch {
|
||||
this.addNotification(true, 'Fehler beim aktualisieren des Etiketten Typen.');
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// Article
|
||||
async loadArticle(articleID: number) {
|
||||
|
||||
Reference in New Issue
Block a user