Add category store

This commit is contained in:
Jan Bader 2022-09-11 21:02:06 +00:00
parent a06d0df142
commit bae9f030b2

View File

@ -0,0 +1,44 @@
import { defineStore } from "pinia";
import { GET, POST } from "../api";
import { useAccountStore } from "./budget-account";
import { Budget, useSessionStore } from "./session";
interface State {
Categories: Map<string, Category>;
}
export interface Category {
ID: string;
Group: string;
Name: string;
AvailableLastMonth: number;
Assigned: number;
Activity: number;
}
export const useCategoryStore = defineStore("category", {
state: (): State => ({
Categories: new Map<string, Category>(),
}),
getters: {
},
actions: {
async CreateCategory(
group: string,
name: string,
) {
const result = await POST(
"/category/new",
JSON.stringify({
name: name,
group: group,
})
);
const response = await result.json();
useCategoryStore().AddCategory(response);
},
async AddCategory(category : Category){
this.Categories.set(category.ID, category);
}
},
});