Split category and category-group stores
This commit is contained in:
39
web/src/stores/category-group.ts
Normal file
39
web/src/stores/category-group.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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;
|
||||
CategoryIDs: 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(categoryGroup : CategoryGroup){
|
||||
this.CategoryGroups.set(categoryGroup.ID, categoryGroup);
|
||||
}
|
||||
},
|
||||
});
|
@@ -1,12 +1,9 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { GET, POST } from "../api";
|
||||
import { POST } from "../api";
|
||||
import { useBudgetsStore } from "./budget";
|
||||
import { useAccountStore } from "./budget-account";
|
||||
import { Budget, useSessionStore } from "./session";
|
||||
|
||||
interface State {
|
||||
Categories: Map<string, Category>;
|
||||
CategoryGroups: Map<string, CategoryGroup>;
|
||||
}
|
||||
|
||||
export interface Category {
|
||||
@@ -18,32 +15,13 @@ export interface Category {
|
||||
Activity: number;
|
||||
}
|
||||
|
||||
export interface CategoryGroup {
|
||||
ID: string;
|
||||
Name: string;
|
||||
}
|
||||
|
||||
export const useCategoryStore = defineStore("category", {
|
||||
state: (): State => ({
|
||||
Categories: new Map<string, Category>(),
|
||||
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();
|
||||
useCategoryStore().AddCategoryGroup(response);
|
||||
},
|
||||
async CreateCategory(
|
||||
group: string,
|
||||
name: string,
|
||||
@@ -57,13 +35,10 @@ export const useCategoryStore = defineStore("category", {
|
||||
})
|
||||
);
|
||||
const response = await result.json();
|
||||
useCategoryStore().AddCategory(response);
|
||||
this.AddCategory(response);
|
||||
},
|
||||
async AddCategory(category : Category){
|
||||
this.Categories.set(category.ID, category);
|
||||
},
|
||||
async AddCategoryGroup(categoryGroup : CategoryGroup){
|
||||
this.CategoryGroups.set(categoryGroup.ID, categoryGroup);
|
||||
}
|
||||
},
|
||||
});
|
Reference in New Issue
Block a user