create-categories #79
44
web/src/stores/category.ts
Normal file
44
web/src/stores/category.ts
Normal 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);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user