alksdfja
This commit is contained in:
@@ -1411,6 +1411,18 @@ router.post('/logs', validateRequest(applicationLogSchema), async (req, res, nex
|
|||||||
// @access Private
|
// @access Private
|
||||||
router.get('/logs', async (req, res, next) => {
|
router.get('/logs', async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
|
const { planId } = req.query;
|
||||||
|
|
||||||
|
let whereConditions = ['p.user_id = $1'];
|
||||||
|
let queryParams = [req.user.id];
|
||||||
|
|
||||||
|
if (planId) {
|
||||||
|
whereConditions.push('al.plan_id = $2');
|
||||||
|
queryParams.push(planId);
|
||||||
|
}
|
||||||
|
|
||||||
|
const whereClause = whereConditions.join(' AND ');
|
||||||
|
|
||||||
const result = await pool.query(`
|
const result = await pool.query(`
|
||||||
SELECT
|
SELECT
|
||||||
al.*,
|
al.*,
|
||||||
@@ -1424,9 +1436,9 @@ router.get('/logs', async (req, res, next) => {
|
|||||||
JOIN properties p ON ls.property_id = p.id
|
JOIN properties p ON ls.property_id = p.id
|
||||||
JOIN user_equipment ue ON al.equipment_id = ue.id
|
JOIN user_equipment ue ON al.equipment_id = ue.id
|
||||||
LEFT JOIN equipment_types et ON ue.equipment_type_id = et.id
|
LEFT JOIN equipment_types et ON ue.equipment_type_id = et.id
|
||||||
WHERE p.user_id = $1
|
WHERE ${whereClause}
|
||||||
ORDER BY al.application_date DESC, al.created_at DESC
|
ORDER BY al.application_date DESC, al.created_at DESC
|
||||||
`, [req.user.id]);
|
`, queryParams);
|
||||||
|
|
||||||
const logs = result.rows.map(row => ({
|
const logs = result.rows.map(row => ({
|
||||||
id: row.id,
|
id: row.id,
|
||||||
@@ -1444,6 +1456,11 @@ router.get('/logs', async (req, res, next) => {
|
|||||||
createdAt: row.created_at
|
createdAt: row.created_at
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
console.log(`GET /logs query with planId: ${planId}, found ${logs.length} logs`);
|
||||||
|
if (logs.length > 0) {
|
||||||
|
console.log('First log GPS track:', logs[0].gpsTrack);
|
||||||
|
}
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
@@ -11,14 +11,22 @@ const ApplicationViewModal = ({ application, propertyDetails, onClose }) => {
|
|||||||
|
|
||||||
// Calculate coverage percentage based on GPS tracking and equipment specifications
|
// Calculate coverage percentage based on GPS tracking and equipment specifications
|
||||||
const calculateCoverage = (application, log) => {
|
const calculateCoverage = (application, log) => {
|
||||||
|
console.log('calculateCoverage called with:', { application, log });
|
||||||
|
console.log('GPS track points:', log?.gpsTrack?.points?.length || 0);
|
||||||
|
console.log('GPS track structure:', log?.gpsTrack);
|
||||||
|
|
||||||
if (!log?.gpsTrack?.points || log.gpsTrack.points.length < 2) {
|
if (!log?.gpsTrack?.points || log.gpsTrack.points.length < 2) {
|
||||||
|
console.log('No GPS points or insufficient points for coverage calculation');
|
||||||
return 0; // No movement = no coverage
|
return 0; // No movement = no coverage
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalDistance = log.gpsTrack.totalDistance || 0;
|
const totalDistance = log.gpsTrack.totalDistance || 0;
|
||||||
const plannedArea = application.totalSectionArea || 0;
|
const plannedArea = application.totalSectionArea || 0;
|
||||||
|
|
||||||
|
console.log('Total distance:', totalDistance, 'Planned area:', plannedArea);
|
||||||
|
|
||||||
if (totalDistance === 0 || plannedArea === 0) {
|
if (totalDistance === 0 || plannedArea === 0) {
|
||||||
|
console.log('Zero distance or area, returning 0 coverage');
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,10 +70,16 @@ const ApplicationViewModal = ({ application, propertyDetails, onClose }) => {
|
|||||||
|
|
||||||
// Try to fetch application logs to get GPS tracking data
|
// Try to fetch application logs to get GPS tracking data
|
||||||
try {
|
try {
|
||||||
|
console.log('Fetching logs for planId:', application.id);
|
||||||
const logsResponse = await applicationsAPI.getLogs({ planId: application.id });
|
const logsResponse = await applicationsAPI.getLogs({ planId: application.id });
|
||||||
|
console.log('Logs response:', logsResponse);
|
||||||
const logs = logsResponse.data.data.logs;
|
const logs = logsResponse.data.data.logs;
|
||||||
|
console.log('Parsed logs:', logs);
|
||||||
if (logs && logs.length > 0) {
|
if (logs && logs.length > 0) {
|
||||||
|
console.log('Setting application log to:', logs[0]);
|
||||||
setApplicationLog(logs[0]); // Get the most recent log
|
setApplicationLog(logs[0]); // Get the most recent log
|
||||||
|
} else {
|
||||||
|
console.log('No logs found in response');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('No application logs found:', error);
|
console.log('No application logs found:', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user