/
aychuikov
/
ProfessionalJuniorAppForTest
Обзор
Документация
Войти
/
aychuikov
/
ProfessionalJuniorAppForTest
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/controllers/admin.controller.js
103 строки
5 KB
Tank4444
feat: Establish core server architecture with services, admin UI, and API documentation.
05 фев 2026, 13:53
05 фев 2026, 13:53
6e8ff48
Код
Авторство
О чём код?
const prisma = require('../prisma'); const getDashboard = async (req, res) => { try { const users = await prisma.user.findMany({ select: { id: true, email: true, firstName: true, lastName: true, points: true, rank: true } }); const applications = await prisma.application.findMany(); res.send(` <!DOCTYPE html> <html> <head> <title>Admin Dashboard</title> <style> body { font-family: sans-serif; padding: 20px; background: #f4f4f9; color: #333; } .card { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); margin-bottom: 20px; } h1 { color: #333; border-bottom: 2px solid #ddd; padding-bottom: 10px; } h2 { color: #007bff; margin-top: 0; } .stat-group { display: flex; gap: 20px; margin-bottom: 20px; } .stat-card { background: #e7f3ff; padding: 15px; border-radius: 8px; flex: 1; text-align: center; } .stat-val { font-size: 28px; font-weight: bold; display: block; } table { width: 100%; border-collapse: collapse; margin-top: 10px; } th, td { text-align: left; padding: 12px; border-bottom: 1px solid #eee; } th { background: #f8f9fa; } tr:hover { background: #fcfcfc; } .badge { padding: 4px 8px; border-radius: 4px; font-size: 12px; font-weight: bold; background: #eee; } </style> </head> <body> <h1>Service UI - Data Viewer</h1> <div class="stat-group"> <div class="stat-card"> <span class="stat-val">${users.length}</span> Users </div> <div class="stat-card"> <span class="stat-val">${applications.length}</span> Applications </div> </div> <div class="card"> <h2>Users</h2> <table> <thead> <tr> <th>Email</th> <th>Name</th> <th>Points</th> <th>Rank</th> </tr> </thead> <tbody> ${users.map(u => ` <tr> <td>${u.email}</td> <td>${u.firstName} ${u.lastName}</td> <td>${u.points}</td> <td><span class="badge">#${u.rank}</span></td> </tr> `).join('') || '<tr><td colspan="4">No users found</td></tr>'} </tbody> </table> </div> <div class="card"> <h2>Applications</h2> <table> <thead> <tr> <th>App Name</th> <th>Author ID</th> <th>Status</th> <th>Rating</th> </tr> </thead> <tbody> ${applications.map(a => ` <tr> <td>${a.appName}</td> <td>${a.authorId}</td> <td><span class="badge">${a.status}</span></td> <td>${a.rating} (${a.votes} votes)</td> </tr> `).join('') || '<tr><td colspan="4">No applications found</td></tr>'} </tbody> </table> </div> <div class="card" style="background: #fff3cd; border: 1px solid #ffeeba;"> <p><strong>Tip:</strong> If Prisma Studio (npm run db:ui) is giving ERR_EMPTY_RESPONSE, it might be because of a port conflict. You can try accessing it at <code>http://localhost:5555</code> (default Prisma Studio port) instead of port 3000.</p> </div> </body> </html> `); } catch (error) { res.status(500).send("Error loading dashboard: " + error.message); } }; module.exports = { getDashboard };