From 93a565da9c4350da2179febfe1c2de28ea9619a5 Mon Sep 17 00:00:00 2001 From: Jake Kasper Date: Tue, 26 Aug 2025 06:48:45 -0500 Subject: [PATCH] aoijsd; --- backend/src/routes/applications.js | 57 +++++++++++++++++-- .../src/pages/Applications/Applications.js | 3 + 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/backend/src/routes/applications.js b/backend/src/routes/applications.js index 1061f53..98b3eb2 100644 --- a/backend/src/routes/applications.js +++ b/backend/src/routes/applications.js @@ -89,10 +89,49 @@ router.get('/plans', async (req, res, next) => { queryParams ); - res.json({ - success: true, - data: { - plans: result.rows.map(plan => ({ + // Get spreader settings for each plan + const plansWithSettings = await Promise.all( + result.rows.map(async (plan) => { + let spreaderSetting = null; + + // Only get spreader settings for granular applications with equipment + if (plan.equipment_name) { + // Get the first product for this plan to determine if it's granular + const productResult = await pool.query( + `SELECT app.product_id, app.user_product_id, p.product_type as shared_type, up.product_type as user_type + FROM application_plan_products app + LEFT JOIN products p ON app.product_id = p.id + LEFT JOIN user_products up ON app.user_product_id = up.id + WHERE app.plan_id = $1 + LIMIT 1`, + [plan.id] + ); + + if (productResult.rows.length > 0) { + const product = productResult.rows[0]; + const productType = product.shared_type || product.user_type; + + if (productType === 'granular') { + // Get equipment ID + const equipmentResult = await pool.query( + 'SELECT id FROM user_equipment WHERE custom_name = $1 AND user_id = $2', + [plan.equipment_name, req.user.id] + ); + + if (equipmentResult.rows.length > 0) { + const equipmentId = equipmentResult.rows[0].id; + spreaderSetting = await getSpreaderSettingsForEquipment( + equipmentId, + product.product_id, + product.user_product_id, + req.user.id + ); + } + } + } + } + + return { id: plan.id, status: plan.status, plannedDate: plan.planned_date, @@ -106,9 +145,17 @@ router.get('/plans', async (req, res, next) => { totalProductAmount: parseFloat(plan.total_product_amount || 0), totalWaterAmount: parseFloat(plan.total_water_amount || 0), avgSpeedMph: parseFloat(plan.avg_speed_mph || 0), + spreaderSetting: spreaderSetting?.setting_value || null, createdAt: plan.created_at, updatedAt: plan.updated_at - })) + }; + }) + ); + + res.json({ + success: true, + data: { + plans: plansWithSettings } }); } catch (error) { diff --git a/frontend/src/pages/Applications/Applications.js b/frontend/src/pages/Applications/Applications.js index 6074caf..d2ab244 100644 --- a/frontend/src/pages/Applications/Applications.js +++ b/frontend/src/pages/Applications/Applications.js @@ -311,6 +311,9 @@ const Applications = () => { {application.avgSpeedMph > 0 && (

• Target Speed: {application.avgSpeedMph.toFixed(1)} mph

)} + {application.spreaderSetting && ( +

• Spreader Setting: {application.spreaderSetting}

+ )} )} {application.notes && (