aoijsd;
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -311,6 +311,9 @@ const Applications = () => {
|
||||
{application.avgSpeedMph > 0 && (
|
||||
<p>• Target Speed: {application.avgSpeedMph.toFixed(1)} mph</p>
|
||||
)}
|
||||
{application.spreaderSetting && (
|
||||
<p>• Spreader Setting: {application.spreaderSetting}</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{application.notes && (
|
||||
|
||||
Reference in New Issue
Block a user