From e464b5239405ac84fa20a82c8c72dc7864413d48 Mon Sep 17 00:00:00 2001 From: TobiZog Date: Sun, 27 Oct 2024 00:12:27 +0200 Subject: [PATCH] Account Dashboard Card --- software/backend/routes/account.routes.ts | 9 +++++++++ software/src/data/api/accountApi.ts | 4 ++++ .../src/pages/admin/dashboardPage/index.vue | 14 +++++++++++++- software/src/stores/account.store.ts | 19 +++++++++++++++++-- 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/software/backend/routes/account.routes.ts b/software/backend/routes/account.routes.ts index b3342a4..e703a89 100644 --- a/software/backend/routes/account.routes.ts +++ b/software/backend/routes/account.routes.ts @@ -8,6 +8,15 @@ import { Exercise } from "../models/exercises/exercise.model"; export const account = Router() +account.get("/", (req: Request, res: Response) => { + Account.findAll({ + include: [ AccountRole ] + }) + .then(accounts => { + res.status(200).json(accounts) + }) +}) + // Login user account.post("/login", (req: Request, res: Response) => { Account.findOne({ diff --git a/software/src/data/api/accountApi.ts b/software/src/data/api/accountApi.ts index 8394f3a..2efc97f 100644 --- a/software/src/data/api/accountApi.ts +++ b/software/src/data/api/accountApi.ts @@ -3,6 +3,10 @@ import { AccountModel } from "../models/user/accountModel" const BASE_URL = "http://localhost:3000/accounts" +export async function fetchAllAccounts() { + return await axios.get(BASE_URL) +} + export async function loginAccount(username: string, password: string) { return await axios.post(BASE_URL + "/login", { username: username, diff --git a/software/src/pages/admin/dashboardPage/index.vue b/software/src/pages/admin/dashboardPage/index.vue index 717f88e..f07125a 100644 --- a/software/src/pages/admin/dashboardPage/index.vue +++ b/software/src/pages/admin/dashboardPage/index.vue @@ -24,6 +24,7 @@ exerciseStore.solveExercise(2, 1) bandStore.getBands() locationStore.getLocations() genreStore.getGenres() +accountStore.getAllAccounts() concertStore.getConcerts() .then(result => { for(let concert of concertStore.concerts) { @@ -106,13 +107,24 @@ concertStore.getConcerts() :title="$t('account.account', 2)" icon="mdi-account" > +
+ {{ accountStore.accounts.length }} {{ $t('account.account', accountStore.accounts.length) }} +
+ +
{{ genreStore.genres.length }} {{ $t('band.genre', 2) }} diff --git a/software/src/stores/account.store.ts b/software/src/stores/account.store.ts index d3f45b8..996cc41 100644 --- a/software/src/stores/account.store.ts +++ b/software/src/stores/account.store.ts @@ -3,7 +3,7 @@ import { defineStore } from "pinia"; import { AccountModel } from "../data/models/user/accountModel"; import { OrderModel } from "../data/models/ordering/orderModel"; import { useFeedbackStore } from "./feedback.store"; -import { loginAccount, registerAccount, updateAccount } from "../data/api/accountApi"; +import { fetchAllAccounts, loginAccount, registerAccount, updateAccount } from "../data/api/accountApi"; import { fetchUserOrders } from "../data/api/orderApi"; import { BannerStateEnum } from "../data/enums/bannerStateEnum"; import { AddressModel } from "../data/models/user/addressModel"; @@ -11,18 +11,23 @@ import { PaymentModel } from "../data/models/user/paymentModel"; import { AccountApiModel } from "../data/models/user/accountApiModel"; import { ref } from "vue"; import { OrderApiModel } from "@/data/models/apiEndpoints/orderApiModel"; +import { LocationApiModel } from "@/data/models/locations/locationApiModel"; export const useAccountStore = defineStore("accountStore", { state: () => ({ + /** All accounts */ + accounts: ref>([]), + /** Useraccount which is currently logged in */ userAccount: useLocalStorage("hackmycart/accountStore/userAccount", new AccountApiModel()), /** User input on login screen */ + // todo: Remove JSON! loginData: ref<{ username: String, password: String}>( { username: "duranduran", password: "H4nn0ver" } ), - /** */ + /** Buffer for register data */ registerData: ref(new AccountModel()), /** All orders of the user */ @@ -33,6 +38,16 @@ export const useAccountStore = defineStore("accountStore", { }), actions: { + async getAllAccounts() { + this.fetchInProgress = true + + fetchAllAccounts() + .then(response => { + this.accounts = response.data + this.fetchInProgress = false + }) + }, + /** * Start the login process *