From b9981d0e70988fbde3e40ddce29ffc57a330cb9e Mon Sep 17 00:00:00 2001 From: Mike Johnston Date: Sat, 28 Feb 2026 01:16:31 -0500 Subject: [PATCH] activity feed --- src/app.js | 5 +++-- src/models/index.js | 16 ++++++++++++++++ src/views/home.ejs | 15 +++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/app.js b/src/app.js index ade0554..c9f296e 100644 --- a/src/app.js +++ b/src/app.js @@ -123,9 +123,10 @@ async function start() { // Home page app.get('/', (req, res) => { - const { Hunts } = require('./models'); + const { Hunts, Scans } = require('./models'); const hunts = Hunts.getAll(); - res.render('home', { title: 'Loot Hunt', hunts }); + const recentActivity = Scans.getRecentActivity(5); + res.render('home', { title: 'Loot Hunt', hunts, recentActivity }); }); // 404 handler diff --git a/src/models/index.js b/src/models/index.js index 69d9a10..13f181a 100644 --- a/src/models/index.js +++ b/src/models/index.js @@ -329,6 +329,22 @@ const Scans = { GROUP BY u.id ORDER BY total_points DESC `).all(); + }, + + getRecentActivity(limit = 5) { + return db.prepare(` + SELECT s.points_awarded, s.scanned_at, + u.username, + p.card_number, + h.name as hunt_name, h.short_name as hunt_short_name, h.package_count + FROM scans s + JOIN users u ON s.user_id = u.id + JOIN packages p ON s.package_id = p.id + JOIN hunts h ON p.hunt_id = h.id + WHERE s.points_awarded > 0 + ORDER BY s.scanned_at DESC + LIMIT ? + `).all(limit); } }; diff --git a/src/views/home.ejs b/src/views/home.ejs index 7feab56..59e90cf 100644 --- a/src/views/home.ejs +++ b/src/views/home.ejs @@ -47,6 +47,21 @@ <% }) %> <% } %> + + <% if (typeof recentActivity !== 'undefined' && recentActivity && recentActivity.length > 0) { %> +

Recent Activity

+
+ <% recentActivity.forEach(a => { %> +
+ +<%= a.points_awarded %> +
+
<%= a.username %> found #<%= a.card_number %> in <%= a.hunt_name %>
+
<%= new Date(a.scanned_at).toLocaleString() %>
+
+
+ <% }) %> +
+ <% } %> <%- include('partials/footer') %>