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:
parent
570fd92d00
commit
fd3cbe686d
1 changed files with 3 additions and 3 deletions
|
@ -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) => {
|
app.get('/api/locations', (req, res) => {
|
||||||
console.log('Fetching active locations');
|
console.log('Fetching active locations');
|
||||||
const fortyEightHoursAgo = new Date(Date.now() - 48 * 60 * 60 * 1000).toISOString();
|
const fortyEightHoursAgo = new Date(Date.now() - 48 * 60 * 60 * 1000).toISOString();
|
||||||
|
|
||||||
db.all(
|
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],
|
[fortyEightHoursAgo],
|
||||||
(err, rows) => {
|
(err, rows) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -127,7 +127,7 @@ app.get('/api/locations', (req, res) => {
|
||||||
res.status(500).json({ error: 'Internal server error' });
|
res.status(500).json({ error: 'Internal server error' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(`Fetched ${rows.length} active locations`);
|
console.log(`Fetched ${rows.length} active locations (including persistent)`);
|
||||||
res.json(rows);
|
res.json(rows);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue