This commit is contained in:
2022-02-10 16:07:29 +00:00
parent c693625e34
commit 21dcd7837b
8 changed files with 46 additions and 38 deletions

View File

@ -1,5 +1,4 @@
import { defineStore } from "pinia"
import { FETCH_ACCOUNT } from "../store/action-types";
import { useAPI } from "./api";
import { useSessionStore } from "./session";
@ -42,7 +41,8 @@ export const useAccountStore = defineStore("budget/account", {
AccountsList(state) {
return state.Accounts.values();
},
Categories: (state) => (year : number, month : number) => {
CategoriesForMonth: (state) => (year : number, month : number) => {
console.log("MTH", state.Months)
const yearMap = state.Months.get(year);
return yearMap?.get(month)?.values();
},
@ -64,7 +64,7 @@ export const useAccountStore = defineStore("budget/account", {
OffBudgetAccountsBalance(state) : Number {
return this.OffBudgetAccounts.reduce((prev, curr) => prev + Number(curr.Balance), 0);
},
Transactions(state) {
TransactionsList(state) {
return (state.Transactions || []);
}
},
@ -82,11 +82,11 @@ export const useAccountStore = defineStore("budget/account", {
},
async FetchAccount(accountid : string) {
const api = useAPI();
const result = await api.GET("/api/v1/account/" + accountid + "/transactions");
const result = await api.GET("/account/" + accountid + "/transactions");
const response = await result.json();
this.Transactions = response.Transactions;
},
async FetchMonthBudget(budgetid : string, month : number, year : number) {
async FetchMonthBudget(budgetid : string, year : number, month : number) {
const api = useAPI();
const result = await api.GET("/budget/" + budgetid + "/" + year + "/" + month);
const response = await result.json();

View File

@ -1,4 +1,5 @@
import { defineStore } from 'pinia'
import { useAPI } from './api';
interface State {
Token: string | null
@ -33,17 +34,18 @@ export const useSessionStore = defineStore('session', {
this.Token = x.Token;
this.Budgets = x.Budgets;
},
login(login: any) {
return fetch("/api/v1/user/login", { method: "POST", body: JSON.stringify(login) })
.then(x => x.json())
.then(x => this.loginSuccess(x));
async login(login: any) {
const api = useAPI();
const response = await api.POST("/user/login", JSON.stringify(login));
const result = await response.json();
return this.loginSuccess(result);
},
register(login : any) {
return fetch("/api/v1/user/register", { method: "POST", body: JSON.stringify(login) })
.then(x => x.json())
.then(x => this.loginSuccess(x))
async register(login : any) {
const api = useAPI();
const response = await api.POST("/user/register", JSON.stringify(login));
const result = await response.json();
return this.loginSuccess(result);
},
// easily reset state using `$reset`
logout() {
this.$reset()
}