mirror of
https://github.com/nfonteyne/octane-website.git
synced 2026-09-03 23:24:48 +02:00
update: dashboard page admin
This commit is contained in:
parent
a1ec2263a5
commit
1f9c290010
11 changed files with 248 additions and 2 deletions
56
src/routes/admin.js
Normal file
56
src/routes/admin.js
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
const express = require('express');
|
||||
const usersRepo = require('../repositories/usersRepo');
|
||||
const songsRepo = require('../repositories/songsRepo');
|
||||
const suggestionsRepo = require('../repositories/suggestionsRepo');
|
||||
const setlistsRepo = require('../repositories/setlistsRepo');
|
||||
const { requireAdmin } = require('../auth/middleware');
|
||||
const asyncHandler = require('../lib/asyncHandler');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get(
|
||||
'/stats',
|
||||
requireAdmin,
|
||||
asyncHandler(async (req, res) => {
|
||||
const [users, songs, suggestions, concerts] = await Promise.all([
|
||||
usersRepo.findAllWithActivity(),
|
||||
songsRepo.getStats(),
|
||||
suggestionsRepo.getStats(),
|
||||
setlistsRepo.getStats(),
|
||||
]);
|
||||
|
||||
res.json({
|
||||
userCount: users.length,
|
||||
users: users.map((u) => ({
|
||||
id: u.id,
|
||||
name: u.name,
|
||||
avatarUrl: u.avatar_url,
|
||||
isAdmin: u.is_admin,
|
||||
createdAt: u.created_at,
|
||||
lastSeenAt: u.updated_at,
|
||||
songsAdded: u.songs_added,
|
||||
suggestionsProposed: u.suggestions_proposed,
|
||||
votesCast: u.votes_cast,
|
||||
})),
|
||||
songs: {
|
||||
totalSongs: songs.total_songs,
|
||||
distinctArtists: songs.distinct_artists,
|
||||
tutorialsAdded: songs.tutorials_added,
|
||||
},
|
||||
suggestions: {
|
||||
total: suggestions.total,
|
||||
pending: suggestions.pending,
|
||||
approved: suggestions.approved,
|
||||
rejected: suggestions.rejected,
|
||||
totalVotes: suggestions.total_votes,
|
||||
},
|
||||
concerts: {
|
||||
pastConcerts: concerts.past_concerts,
|
||||
upcomingConcerts: concerts.upcoming_concerts,
|
||||
avgSongsPerConcert: concerts.avg_songs_per_concert,
|
||||
},
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
module.exports = router;
|
||||
|
|
@ -6,6 +6,7 @@ const suggestionsRoutes = require('./suggestions');
|
|||
const setlistsRoutes = require('./setlists');
|
||||
const musicSearchRoutes = require('./musicSearch');
|
||||
const calendarRoutes = require('./calendar');
|
||||
const adminRoutes = require('./admin');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
|
|
@ -16,5 +17,6 @@ router.use('/suggestions', suggestionsRoutes);
|
|||
router.use('/setlists', setlistsRoutes);
|
||||
router.use('/music-search', musicSearchRoutes);
|
||||
router.use('/calendar', calendarRoutes);
|
||||
router.use('/admin', adminRoutes);
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue