diff --git a/backend/src/routes/applications.js b/backend/src/routes/applications.js index 8c6fa56..507811d 100644 --- a/backend/src/routes/applications.js +++ b/backend/src/routes/applications.js @@ -931,7 +931,9 @@ router.put('/plans/:id/status', validateParams(idParamSchema), async (req, res, // @access Private router.get('/logs', async (req, res, next) => { try { - const { property_id, start_date, end_date, limit = 50 } = req.query; + console.log('=== FIRST LOGS ENDPOINT CALLED ==='); + const { property_id, start_date, end_date, limit = 50, planId } = req.query; + console.log('Query params:', { property_id, start_date, end_date, limit, planId }); let whereConditions = ['al.user_id = $1']; let queryParams = [req.user.id]; @@ -943,6 +945,12 @@ router.get('/logs', async (req, res, next) => { queryParams.push(property_id); } + if (planId) { + paramCount++; + whereConditions.push(`al.plan_id = $${paramCount}`); + queryParams.push(planId); + } + if (start_date) { paramCount++; whereConditions.push(`al.application_date >= $${paramCount}`); @@ -978,6 +986,19 @@ router.get('/logs', async (req, res, next) => { queryParams ); + console.log(`Found ${result.rows.length} logs`); + if (result.rows.length > 0) { + console.log('First log gps_track:', result.rows[0].gps_track); + console.log('First log raw data sample:', { + id: result.rows[0].id, + plan_id: result.rows[0].plan_id, + gps_track: result.rows[0].gps_track, + average_speed: result.rows[0].average_speed, + area_covered: result.rows[0].area_covered, + notes: result.rows[0].notes + }); + } + res.json({ success: true, data: { @@ -986,6 +1007,7 @@ router.get('/logs', async (req, res, next) => { planId: log.plan_id, applicationDate: log.application_date, weatherConditions: log.weather_conditions, + gpsTrack: log.gps_track, // ADD THIS MISSING FIELD averageSpeed: parseFloat(log.average_speed), areaCovered: parseFloat(log.area_covered), notes: log.notes, @@ -1411,7 +1433,9 @@ router.post('/logs', validateRequest(applicationLogSchema), async (req, res, nex // @access Private router.get('/logs', async (req, res, next) => { try { + console.log('=== LOGS ENDPOINT CALLED ==='); const { planId } = req.query; + console.log('planId parameter:', planId); let whereConditions = ['p.user_id = $1']; let queryParams = [req.user.id];