Skip to content
This repository has been archived by the owner on Feb 4, 2025. It is now read-only.

Commit

Permalink
Used session storage in all views
Browse files Browse the repository at this point in the history
  • Loading branch information
GrPe committed May 21, 2024
1 parent 6b25f55 commit 662cc7b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
9 changes: 5 additions & 4 deletions src/Overmoney.Portal/src/components/views/CategoryView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@ import type { Category } from '../../data_access/models/category'
import CategoryList from '../lists/CategoryList.vue';
import CreateCategoryModal from '../modals/CreateCategoryModal.vue';
import UpdateCategoryModal from '../modals/UpdateCategoryModal.vue';
import type { UserContext } from '@/data_access/userContext';
import { userSessionStore } from '@/data_access/sessionStore';
export default {
data() {
const client = new Client();
const session = userSessionStore();
return {
client,
categories: [] as Array<Category>,
showModal: false,
showUpdateModal: false,
categoryToUpdate: {} as Category | undefined,
userContext: { userId: 1 } as UserContext
session
}
},
mounted() {
this.client.getCategories(this.userContext.userId)
this.client.getCategories(this.session.userId)
.then((x) => { this.categories = x });
},
components: {
Expand All @@ -38,7 +39,7 @@ export default {
methods: {
async onCreateCategory(categoryName: string) {
this.showModal = false;
let result = await this.client.createCategory({ name: categoryName, userId: this.userContext.userId })
let result = await this.client.createCategory({ name: categoryName, userId: this.session.userId })
this.categories.push(result);
},
async onRemoveCategory(id: number) {
Expand Down
9 changes: 5 additions & 4 deletions src/Overmoney.Portal/src/components/views/PayeeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@ import { Client } from '@/data_access/client';
import type { Payee } from '../../data_access/models/payee'
import CreatePayeeModal from '../modals/CreatePayeeModal.vue';
import UpdatePayeeModal from '../modals/UpdatePayeeModal.vue';
import type { UserContext } from '@/data_access/userContext';
import PayeesList from '../lists/PayeesList.vue';
import { userSessionStore } from '@/data_access/sessionStore';
export default {
data() {
const client = new Client();
const session = userSessionStore();
return {
client,
payees: [] as Array<Payee>,
showModal: false,
showUpdateModal: false,
payeeToUpdate: {} as Payee | undefined,
userContext: { userId: 1 } as UserContext
session
}
},
mounted() {
this.client.getPayees(this.userContext.userId)
this.client.getPayees(this.session.userId)
.then((x) => { this.payees = x });
},
components: {
Expand All @@ -38,7 +39,7 @@ export default {
methods: {
async onCreatePayee(payeeName: string) {
this.showModal = false;
let result = await this.client.createPayee({ name: payeeName, userId: this.userContext.userId })
let result = await this.client.createPayee({ name: payeeName, userId: this.session.userId })
this.payees.push(result);
},
async onRemovePayee(id: number) {
Expand Down
15 changes: 8 additions & 7 deletions src/Overmoney.Portal/src/components/views/TransactionView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ import type { Category } from '../../data_access/models/category';
import type { createTransactionRequest } from '@/data_access/models/requests/createTransactionRequest';
import type { updateTransactionRequest } from '@/data_access/models/requests/updateTransactionRequest';
import { Client } from '@/data_access/client';
import type { UserContext } from '@/data_access/userContext';
import CreateTransactionModal from '@/components/modals/CreateTransactionModal.vue';
import UpdateTransactionModal from '@/components/modals/UpdateTransactionModal.vue';
import { userSessionStore } from '@/data_access/sessionStore';
export default {
data() {
const client = new Client();
const session = userSessionStore();
return {
client,
categories: [] as Array<Category>,
Expand All @@ -34,24 +35,24 @@ export default {
showModal: false,
showUpdateModal: false,
transactionToUpdate: {} as Transaction | undefined,
userContext: { userId: 1 } as UserContext
session
}
},
mounted() {
this.client.getWallets(this.userContext.userId)
this.client.getWallets(this.session.userId)
.then(x => { this.wallets = x })
.then(() => this.client.getCategories(this.userContext.userId))
.then(() => this.client.getCategories(this.session.userId))
.then(x => { this.categories = x })
.then(() => this.client.getPayees(this.userContext.userId))
.then(() => this.client.getPayees(this.session.userId))
.then(x => { this.payees = x })
.then(() => this.client.getTransactions(this.userContext.userId))
.then(() => this.client.getTransactions(this.session.userId))
.then(x => { this.transactions = x });
},
methods: {
async onCreateTransaction(transaction: createTransactionRequest) {
this.showModal = false;
transaction.userId = this.userContext.userId;
transaction.userId = this.session.userId;
let result = await this.client.createTransaction(transaction);
this.transactions.push(result);
},
Expand Down
4 changes: 2 additions & 2 deletions src/Overmoney.Portal/src/data_access/sessionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const userSessionStore = defineStore("user", {
apiToken(): string | undefined {
return this.userContext?.token;
},
getUserId(): number | undefined {
return this.userContext?.userId;
userId(): number {
return this.userContext!.userId;
},
isAuthenticated(): boolean {
//no token
Expand Down

0 comments on commit 662cc7b

Please sign in to comment.