feat: Add detailed user statistics view for admin with QR code list and scan counts

This commit is contained in:
Mohan Ki
2026-07-27 18:05:38 +05:30
parent 2e79d3a27c
commit 2a2f09ccb7
3 changed files with 173 additions and 0 deletions
+29
View File
@@ -24,6 +24,35 @@ router.get('/users', async (req, res) => {
}
});
// Get user details (QR codes, scans)
router.get('/users/:id/details', async (req, res) => {
const { id } = req.params;
try {
// Fetch user info
const userRes = await pgPool.query('SELECT id, email, role, created_at FROM users WHERE id = $1', [id]);
if (userRes.rows.length === 0) {
return res.status(404).json({ error: 'User not found' });
}
// Fetch QR codes and scan counts
const qrRes = await pgPool.query(`
SELECT q.id, q.type, q.data_type, q.destination_url, q.short_url_id, q.created_at, q.design_data->>'name' as name,
(SELECT COUNT(*) FROM qr_scans s WHERE s.qr_code_id = q.id) as scan_count
FROM qr_codes q
WHERE q.user_id = $1
ORDER BY q.created_at DESC
`, [id]);
res.json({
user: userRes.rows[0],
qrCodes: qrRes.rows
});
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Server Error fetching user details' });
}
});
// Update a user's tier
router.put('/users/:id/tier', async (req, res) => {
const { id } = req.params;