All checks were successful
Build Images and Deploy / Update-PROD-Stack (push) Successful in 28s
92 lines
3.6 KiB
JavaScript
92 lines
3.6 KiB
JavaScript
const express = require('express');
|
|
const router = express.Router();
|
|
const { Hunts, Packages, Scans, Users } = require('../models');
|
|
|
|
// ─── Hunt profile ─────────────────────────────────────────
|
|
router.get('/hunt/:shortName', (req, res) => {
|
|
const hunt = Hunts.findByShortName(req.params.shortName);
|
|
if (!hunt) {
|
|
return res.status(404).render('error', { title: 'Not Found', message: 'Hunt not found.' });
|
|
}
|
|
|
|
const packages = Packages.getByHunt(hunt.id);
|
|
const isExpired = Hunts.isExpired(hunt);
|
|
|
|
res.render('hunt/profile', { title: hunt.name, hunt, packages, isExpired });
|
|
});
|
|
|
|
// ─── Hunt leaderboard ─────────────────────────────────────
|
|
router.get('/hunt/:shortName/leaderboard', (req, res) => {
|
|
const hunt = Hunts.findByShortName(req.params.shortName);
|
|
if (!hunt) {
|
|
return res.status(404).render('error', { title: 'Not Found', message: 'Hunt not found.' });
|
|
}
|
|
|
|
const leaderboard = Hunts.getLeaderboard(hunt.id);
|
|
res.render('hunt/leaderboard', { title: `${hunt.name} - Leaderboard`, hunt, leaderboard });
|
|
});
|
|
|
|
// ─── Global leaderboard ──────────────────────────────────
|
|
router.get('/leaderboard', (req, res) => {
|
|
const leaderboard = Scans.getGlobalLeaderboard();
|
|
res.render('leaderboard/global', { title: 'Global Leaderboard', leaderboard });
|
|
});
|
|
|
|
// ─── Package profile (by card number — no secret code exposed) ────
|
|
router.get('/hunt/:shortName/:cardNumber', (req, res) => {
|
|
const { shortName, cardNumber } = req.params;
|
|
if (!/^\d+$/.test(cardNumber)) {
|
|
return res.status(404).render('error', { title: 'Not Found', message: 'Package not found.' });
|
|
}
|
|
|
|
const pkg = Packages.findByHuntAndCardNumber(shortName, cardNumber);
|
|
if (!pkg) {
|
|
return res.status(404).render('error', { title: 'Not Found', message: 'Package not found.' });
|
|
}
|
|
|
|
const fullPkg = Packages.getProfile(pkg.id);
|
|
const scanHistory = Packages.getScanHistory(pkg.id);
|
|
const isFirstScanner = req.session && req.session.userId && fullPkg.first_scanned_by === req.session.userId;
|
|
const isLastScanner = req.session && req.session.userId && fullPkg.last_scanned_by === req.session.userId;
|
|
|
|
res.render('loot/profile', {
|
|
title: `Package ${fullPkg.card_number} of ${pkg.package_count} - ${fullPkg.hunt_name}`,
|
|
pkg: fullPkg,
|
|
scanHistory,
|
|
isFirstScanner,
|
|
isLastScanner,
|
|
packages_total: pkg.package_count
|
|
});
|
|
});
|
|
|
|
// ─── User profile ─────────────────────────────────────────
|
|
router.get('/player/:username', (req, res) => {
|
|
const user = Users.findByUsername(req.params.username);
|
|
if (!user) {
|
|
return res.status(404).render('error', { title: 'Not Found', message: 'Player not found.' });
|
|
}
|
|
|
|
const profile = Users.getProfile(user.id);
|
|
const recentScans = Users.getRecentScans(user.id);
|
|
const huntBreakdown = Users.getHuntBreakdown(user.id);
|
|
const rank = Users.getRank(user.id);
|
|
const totalPlayers = Users.getTotalPlayerCount();
|
|
|
|
res.render('player/profile', {
|
|
title: `${user.username}'s Profile`,
|
|
profile,
|
|
recentScans,
|
|
huntBreakdown,
|
|
rank,
|
|
totalPlayers
|
|
});
|
|
});
|
|
|
|
// ─── Browse all hunts ─────────────────────────────────────
|
|
router.get('/hunts', (req, res) => {
|
|
const hunts = Hunts.getAll();
|
|
res.render('hunt/list', { title: 'All Hunts', hunts });
|
|
});
|
|
|
|
module.exports = router;
|