Admin platform, with users, transactions, games and admin creation

This commit is contained in:
Edd
2026-01-02 16:17:55 +00:00
parent b9df0a4d4a
commit e89b60c844
14 changed files with 959 additions and 24 deletions
+62 -2
View File
@@ -95,8 +95,7 @@ export const useAPIStore = defineStore('api', () => {
const queryParams = new URLSearchParams({
page: params.page || 1,
...(params.type && { type: params.type }),
...(params.date_from && { date_from: params.date_from }),
...(params.date_to && { date_to: params.date_to }),
...(params.blocked && { blocked: params.blocked }),
}).toString()
return axios.get(`${API_BASE_URL}/users/${authStore.currentUserID}/transactions?${queryParams}`)
@@ -114,6 +113,58 @@ export const useAPIStore = defineStore('api', () => {
return axios.get(`${API_BASE_URL}/statistics/me`)
}
const getPublicStats = () => {
return axios.get(`${API_BASE_URL}/statistics/public`)
}
const getAdminStats = () => {
return axios.get(`${API_BASE_URL}/admin/statistics`)
}
const getAdminUsers = (params) => {
const queryParams = new URLSearchParams({
page: params.page || 1,
...(params.type && { type: params.type }),
...(params.blocked && { blocked: params.blocked }),
}).toString()
return axios.get(`${API_BASE_URL}/admin/users?${queryParams}`)
}
const blockUser = (user) => {
return axios.post(`${API_BASE_URL}/admin/users/${user.id}/block`)
}
const unblockUser = (user) => {
return axios.post(`${API_BASE_URL}/admin/users/${user.id}/unblock`)
}
const deleteUser = (user) => {
return axios.delete(`${API_BASE_URL}/admin/users/${user.id}`)
}
const getAdminTransactions = (params) => {
const queryParams = new URLSearchParams({
page: params.page || 1,
...(params.sort_datetime == 'asc' && { sort_datetime: 'asc' }),
...(params.sort_coins && { sort_coins: params.sort_coins }),
}).toString()
return axios.get(`${API_BASE_URL}/admin/transactions?${queryParams}`)
}
const getAdminGames = (params) => {
const queryParams = new URLSearchParams({
page: params.page || 1,
...(params.sort_direction == 'asc' && { sort_direction: 'asc' }),
...(params.type && { type: params.type }),
}).toString()
return axios.get(`${API_BASE_URL}/games?${queryParams}`)
}
const postAdmin = async (credentials) => {
return axios.post(`${API_BASE_URL}/admin/users`, credentials)
}
return {
postLogin,
postLogout,
@@ -123,6 +174,15 @@ export const useAPIStore = defineStore('api', () => {
getCurrentUserTransactions,
getCurrentUserStats,
getLeaderboard,
getPublicStats,
getAdminStats,
getAdminUsers,
blockUser,
unblockUser,
deleteUser,
getAdminTransactions,
getAdminGames,
postAdmin,
gameQueryParameters,
}
})
+12 -1
View File
@@ -4,7 +4,7 @@ import { useAPIStore } from './api'
export const useAuthStore = defineStore('auth', () => {
const DEFAULT_TIMEOUT = 5 * 60 * 1000
const DEFAULT_TIMEOUT = 30 * 60 * 1000
const REMEMBER_ME_TIMEOUT = 365 * 24 * 60 * 60 * 1000
const currentUser = ref(undefined)
@@ -20,6 +20,10 @@ export const useAuthStore = defineStore('auth', () => {
return currentUser.value?.id
})
const isAdmin = computed(() => {
return currentUser.value?.type === 'A'
})
const isTokenAlmostExpired = () => {
if (!tokenExpiry.value) return false;
return Date.now() > (tokenExpiry.value - 60 * 1000);
@@ -112,10 +116,16 @@ export const useAuthStore = defineStore('auth', () => {
return true
}
const updateCurrentUserCoins = (coins) => {
if (!currentUser.value) return;
currentUser.value.coins_balance = coins
}
return {
currentUser,
isLoggedIn,
currentUserID,
isAdmin,
token,
rememberMe,
getToken,
@@ -124,5 +134,6 @@ export const useAuthStore = defineStore('auth', () => {
resetTokenExpiry,
isTokenAlmostExpired,
restoreSession,
updateCurrentUserCoins,
}
})
+2
View File
@@ -1,6 +1,7 @@
import { defineStore } from 'pinia'
import axios from 'axios'
import { inject, ref } from 'vue'
import { useAuthStore } from './auth'
export const useUserStore = defineStore('user', () => {
const API_BASE_URL = inject('apiBaseURL')
@@ -10,6 +11,7 @@ export const useUserStore = defineStore('user', () => {
try {
const response = await axios.get(`${API_BASE_URL}/users/me/coins`)
coins.value = response.data?.coins || 0
useAuthStore().updateCurrentUserCoins(coins.value)
return response
} catch (error) {
console.error('Error fetching coins', error)