adding player profiles
All checks were successful
Build Images and Deploy / Update-PROD-Stack (push) Successful in 28s

This commit is contained in:
2026-02-28 00:51:43 -05:00
parent 30f0c98102
commit 79ee7064a8
11 changed files with 256 additions and 31 deletions

View File

@@ -56,6 +56,48 @@ const Users = {
const totalPoints = this.getTotalPoints(userId);
const scanCount = db.prepare('SELECT COUNT(*) as count FROM scans WHERE user_id = ? AND points_awarded > 0').get(userId).count;
return { ...user, totalPoints, scanCount };
},
getRecentScans(userId, limit = 20) {
return db.prepare(`
SELECT s.points_awarded, s.scanned_at,
p.card_number, p.unique_code,
h.name as hunt_name, h.short_name as hunt_short_name, h.package_count
FROM scans s
JOIN packages p ON s.package_id = p.id
JOIN hunts h ON p.hunt_id = h.id
WHERE s.user_id = ?
ORDER BY s.scanned_at DESC
LIMIT ?
`).all(userId, limit);
},
getHuntBreakdown(userId) {
return db.prepare(`
SELECT h.name as hunt_name, h.short_name as hunt_short_name,
COUNT(s.id) as scans, SUM(s.points_awarded) as points
FROM scans s
JOIN packages p ON s.package_id = p.id
JOIN hunts h ON p.hunt_id = h.id
WHERE s.user_id = ? AND s.points_awarded > 0
GROUP BY h.id
ORDER BY points DESC
`).all(userId);
},
getRank(userId) {
const rows = db.prepare(`
SELECT user_id, SUM(points_awarded) as total
FROM scans WHERE points_awarded > 0
GROUP BY user_id
ORDER BY total DESC
`).all();
const idx = rows.findIndex(r => r.user_id === userId);
return idx >= 0 ? idx + 1 : null;
},
getTotalPlayerCount() {
return db.prepare('SELECT COUNT(DISTINCT user_id) as count FROM scans WHERE points_awarded > 0').get().count;
}
};