Rewrite addCategoriesForMonth with patch call
This commit is contained in:
parent
fe018e1953
commit
57930d0e5d
@ -104,16 +104,17 @@ export const useAccountStore = defineStore("budget/account", {
|
|||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
this.addCategoriesForMonth(year, month, response.Categories);
|
this.addCategoriesForMonth(year, month, response.Categories);
|
||||||
},
|
},
|
||||||
addCategoriesForMonth(year : number, month : number, categories : Category[]) : void {
|
addCategoriesForMonth(year: number, month: number, categories: Category[]): void {
|
||||||
const yearMap = this.Months.get(year) || new Map<number, Map<string, Category>>();
|
this.$patch((state) => {
|
||||||
this.Months.set(year, yearMap);
|
const yearMap = state.Months.get(year) || new Map<number, Map<string, Category>>();
|
||||||
|
const monthMap = yearMap.get(month) || new Map<string, Category>();
|
||||||
|
for (const category of categories) {
|
||||||
|
monthMap.set(category.ID, category);
|
||||||
|
}
|
||||||
|
|
||||||
const monthMap = yearMap.get(month) || new Map<string, Category>();
|
yearMap.set(month, monthMap);
|
||||||
yearMap.set(month, monthMap);
|
state.Months.set(year, yearMap);
|
||||||
|
});
|
||||||
for (const category of categories){
|
|
||||||
monthMap.set(category.ID, category);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
logout() {
|
logout() {
|
||||||
this.$reset()
|
this.$reset()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user