aoijsd;
This commit is contained in:
@@ -89,10 +89,49 @@ router.get('/plans', async (req, res, next) => {
|
|||||||
queryParams
|
queryParams
|
||||||
);
|
);
|
||||||
|
|
||||||
res.json({
|
// Get spreader settings for each plan
|
||||||
success: true,
|
const plansWithSettings = await Promise.all(
|
||||||
data: {
|
result.rows.map(async (plan) => {
|
||||||
plans: result.rows.map(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,
|
id: plan.id,
|
||||||
status: plan.status,
|
status: plan.status,
|
||||||
plannedDate: plan.planned_date,
|
plannedDate: plan.planned_date,
|
||||||
@@ -106,9 +145,17 @@ router.get('/plans', async (req, res, next) => {
|
|||||||
totalProductAmount: parseFloat(plan.total_product_amount || 0),
|
totalProductAmount: parseFloat(plan.total_product_amount || 0),
|
||||||
totalWaterAmount: parseFloat(plan.total_water_amount || 0),
|
totalWaterAmount: parseFloat(plan.total_water_amount || 0),
|
||||||
avgSpeedMph: parseFloat(plan.avg_speed_mph || 0),
|
avgSpeedMph: parseFloat(plan.avg_speed_mph || 0),
|
||||||
|
spreaderSetting: spreaderSetting?.setting_value || null,
|
||||||
createdAt: plan.created_at,
|
createdAt: plan.created_at,
|
||||||
updatedAt: plan.updated_at
|
updatedAt: plan.updated_at
|
||||||
}))
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
success: true,
|
||||||
|
data: {
|
||||||
|
plans: plansWithSettings
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -311,6 +311,9 @@ const Applications = () => {
|
|||||||
{application.avgSpeedMph > 0 && (
|
{application.avgSpeedMph > 0 && (
|
||||||
<p>• Target Speed: {application.avgSpeedMph.toFixed(1)} mph</p>
|
<p>• Target Speed: {application.avgSpeedMph.toFixed(1)} mph</p>
|
||||||
)}
|
)}
|
||||||
|
{application.spreaderSetting && (
|
||||||
|
<p>• Spreader Setting: {application.spreaderSetting}</p>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{application.notes && (
|
{application.notes && (
|
||||||
|
|||||||
Reference in New Issue
Block a user