Fix persistent locations not showing on homepage

The public /api/locations endpoint was only returning locations within 48 hours,
but it should also include persistent locations regardless of their age.

Updated SQL query to: 'WHERE created_at > ? OR persistent = 1'

This ensures that:
- Regular reports show for 48 hours (as intended)
- Persistent reports show indefinitely (as intended)
- Both types appear on the public map and homepage
This commit is contained in:
Deco Vander 2025-07-03 20:56:27 -04:00
parent 570fd92d00
commit fd3cbe686d

View file

@ -113,13 +113,13 @@ app.post('/api/admin/login', (req, res) => {
}
});
// Get all active locations (within 48 hours)
// Get all active locations (within 48 hours OR persistent)
app.get('/api/locations', (req, res) => {
console.log('Fetching active locations');
const fortyEightHoursAgo = new Date(Date.now() - 48 * 60 * 60 * 1000).toISOString();
db.all(
'SELECT * FROM locations WHERE created_at > ? ORDER BY created_at DESC',
'SELECT * FROM locations WHERE created_at > ? OR persistent = 1 ORDER BY created_at DESC',
[fortyEightHoursAgo],
(err, rows) => {
if (err) {
@ -127,7 +127,7 @@ app.get('/api/locations', (req, res) => {
res.status(500).json({ error: 'Internal server error' });
return;
}
console.log(`Fetched ${rows.length} active locations`);
console.log(`Fetched ${rows.length} active locations (including persistent)`);
res.json(rows);
}
);