From 3af564983c7a514fbc74dbfbbb27b36f9ada5b0e Mon Sep 17 00:00:00 2001 From: Mike Johnston Date: Wed, 29 Apr 2026 22:58:30 -0400 Subject: [PATCH] feat: fix how complaints are displayed after resolution --- src/models/index.js | 9 +++++++ src/routes/admin.js | 27 +++++++++++++++++++ src/views/admin/dashboard.ejs | 11 ++++++++ src/views/admin/manage-hunt.ejs | 47 ++++++++++++++++++++++++++------- 4 files changed, 84 insertions(+), 10 deletions(-) diff --git a/src/models/index.js b/src/models/index.js index bc1c084..4fb1d3d 100644 --- a/src/models/index.js +++ b/src/models/index.js @@ -585,6 +585,7 @@ const ComplaintReports = { JOIN packages p ON c.package_id = p.id JOIN hunts h ON c.hunt_id = h.id LEFT JOIN users u ON c.reported_by_user_id = u.id + WHERE c.status = 'open' ORDER BY c.created_at ASC `).all(); }, @@ -607,6 +608,14 @@ const ComplaintReports = { SET status = 'dismissed', reviewed_by = ?, reviewed_at = datetime('now'), resolution_note = ? WHERE id = ? `).run(reviewedBy, resolutionNote || null, id); + }, + + updateModeration(id, reviewedBy, status, resolutionNote) { + db.prepare(` + UPDATE complaint_reports + SET status = ?, reviewed_by = ?, reviewed_at = datetime('now'), resolution_note = ? + WHERE id = ? + `).run(status, reviewedBy, resolutionNote || null, id); } }; diff --git a/src/routes/admin.js b/src/routes/admin.js index 52bb145..6877cf4 100644 --- a/src/routes/admin.js +++ b/src/routes/admin.js @@ -192,6 +192,33 @@ router.post('/hunts/:id/complaints/:complaintId/dismiss', requireHuntAccess, (re res.redirect(`/admin/hunts/${hunt.id}`); }); +router.post('/hunts/:id/complaints/:complaintId/update', requireHuntAccess, (req, res) => { + const hunt = req.hunt; + const complaint = ComplaintReports.findById(parseInt(req.params.complaintId, 10)); + if (!complaint || complaint.hunt_id !== hunt.id) { + req.session.flash = { type: 'danger', message: 'Complaint not found.' }; + return res.redirect(`/admin/hunts/${hunt.id}`); + } + + const statusMap = { + open: 'open', + resolved: 'resolved', + ignored: 'dismissed', + dismissed: 'dismissed' + }; + const statusInput = String(req.body.status || '').toLowerCase(); + const normalizedStatus = statusMap[statusInput]; + if (!normalizedStatus) { + req.session.flash = { type: 'danger', message: 'Invalid complaint status.' }; + return res.redirect(`/admin/hunts/${hunt.id}`); + } + + const note = (req.body.note || '').trim(); + ComplaintReports.updateModeration(complaint.id, req.session.userId, normalizedStatus, note || null); + req.session.flash = { type: 'success', message: 'Complaint updated.' }; + res.redirect(`/admin/hunts/${hunt.id}`); +}); + // ─── Manage user roles (admin only) ─────────────────────── router.post('/users/:id/role', requireAdmin, (req, res) => { const userId = parseInt(req.params.id, 10); diff --git a/src/views/admin/dashboard.ejs b/src/views/admin/dashboard.ejs index b360362..922fc9d 100644 --- a/src/views/admin/dashboard.ejs +++ b/src/views/admin/dashboard.ejs @@ -99,6 +99,9 @@
<%= c.hunt_name %> · Package #<%= c.card_number %> + <% if (c.status !== 'open') { %> + <%= c.status === 'dismissed' ? 'Ignored' : 'Resolved' %> + <% } %>
<% if (c.reported_by_name) { %> @@ -110,6 +113,14 @@ <% } %> ·
+ <% if (c.status !== 'open') { %> +
+ Status: <%= c.status === 'dismissed' ? 'Ignored' : 'Resolved' %> +
+ <% if (c.resolution_note) { %> +

Note: <%= c.resolution_note %>

+ <% } %> + <% } %> Review in Hunt diff --git a/src/views/admin/manage-hunt.ejs b/src/views/admin/manage-hunt.ejs index a4946ac..f45616d 100644 --- a/src/views/admin/manage-hunt.ejs +++ b/src/views/admin/manage-hunt.ejs @@ -98,13 +98,17 @@ <% } %> <% if (typeof complaints !== 'undefined' && complaints && complaints.length > 0) { %> -

🚩 Open Complaints <%= complaints.length %>

+

🚩 Complaints <%= complaints.length %>

<% complaints.forEach(c => { %>
-
Package #<%= c.card_number %>
+
Package #<%= c.card_number %> + <% if (c.status !== 'open') { %> + <%= c.status === 'dismissed' ? 'Ignored' : 'Resolved' %> + <% } %> +
<% if (c.reported_by_name) { %> Reporter: <%= c.reported_by_name %> @@ -117,16 +121,39 @@

<%= c.message %>

+ <% if (c.status !== 'open') { %> +
+ Status: <%= c.status === 'dismissed' ? 'Ignored' : 'Resolved' %> +
+ <% if (c.resolution_note) { %> +

Note: <%= c.resolution_note %>

+ <% } %> + <% } %>
-
- - -
-
- - -
+ <% if (c.status === 'open') { %> +
+ + +
+
+ + +
+ <% } else { %> +
+ Edit +
+ + + +
+
+ <% } %>