40 lines
978 B
TypeScript
40 lines
978 B
TypeScript
import { defineStore } from "pinia";
|
|
import { POST } from "../api";
|
|
import { useBudgetsStore } from "./budget";
|
|
|
|
interface State {
|
|
CategoryGroups: Map<string, CategoryGroup>;
|
|
}
|
|
|
|
export interface CategoryGroup {
|
|
ID: string;
|
|
Name: string;
|
|
}
|
|
|
|
export const useCategoryGroupStore = defineStore("category-group", {
|
|
state: (): State => ({
|
|
CategoryGroups: new Map<string, CategoryGroup>(),
|
|
}),
|
|
getters: {
|
|
},
|
|
actions: {
|
|
async CreateCategoryGroup(
|
|
group: string,
|
|
) {
|
|
const result = await POST(
|
|
"/category-group/new",
|
|
JSON.stringify({
|
|
budgetId: useBudgetsStore().CurrentBudgetID,
|
|
group: group,
|
|
})
|
|
);
|
|
const response = await result.json();
|
|
this.AddCategoryGroup(response);
|
|
},
|
|
async AddCategoryGroup(...categoryGroups : CategoryGroup[]){
|
|
for (const categoryGroup of categoryGroups) {
|
|
this.CategoryGroups.set(categoryGroup.ID, categoryGroup);
|
|
}
|
|
}
|
|
},
|
|
}); |