This commit is contained in:
Jake Kasper
2025-08-23 14:06:32 -04:00
parent f12818cfdd
commit ae3ad6fb81
4 changed files with 217 additions and 25 deletions

View File

@@ -273,8 +273,15 @@ router.post('/plans', validateRequest(applicationPlanSchema), async (req, res, n
rateAmount: parseFloat(rateAmount),
rateUnit,
applicationType,
equipmentData,
nozzleData
equipmentData: {
category_name: equipmentData.category_name,
spray_width_feet: equipmentData.spray_width_feet,
tank_size_gallons: equipmentData.tank_size_gallons
},
nozzleData: nozzleData ? {
flow_rate_gpm: nozzleData.flow_rate_gpm,
spray_angle: nozzleData.spray_angle
} : null
});
// Prepare equipment object for calculations
@@ -544,6 +551,51 @@ router.put('/plans/:id', validateParams(idParamSchema), validateRequest(applicat
}
});
// @route DELETE /api/applications/plans/:id
// @desc Delete application plan
// @access Private
router.delete('/plans/:id', validateParams(idParamSchema), async (req, res, next) => {
try {
const planId = req.params.id;
const client = await pool.connect();
try {
await client.query('BEGIN');
// Check if plan belongs to user
const planCheck = await client.query(
'SELECT id FROM application_plans WHERE id = $1 AND user_id = $2',
[planId, req.user.id]
);
if (planCheck.rows.length === 0) {
throw new AppError('Application plan not found', 404);
}
// Delete plan products first (due to foreign key constraint)
await client.query('DELETE FROM application_plan_products WHERE plan_id = $1', [planId]);
// Delete the plan
await client.query('DELETE FROM application_plans WHERE id = $1', [planId]);
await client.query('COMMIT');
res.json({
success: true,
message: 'Application plan deleted successfully'
});
} catch (error) {
await client.query('ROLLBACK');
throw error;
} finally {
client.release();
}
} catch (error) {
next(error);
}
});
// @route PUT /api/applications/plans/:id/status
// @desc Update application plan status
// @access Private

View File

@@ -24,7 +24,7 @@ function calculateLiquidApplication(areaSquareFeet, rateAmount, rateUnit, equipm
console.log(`Calculating liquid application:
Area: ${areaSquareFeet} sq ft (${areaAcres.toFixed(3)} acres, ${area1000sqft.toFixed(1)} x 1000sqft)
Rate: ${rateAmount} ${rateUnit}
Equipment: ${equipment?.categoryName}
Equipment: ${equipment?.categoryName} (width: ${equipment?.sprayWidthFeet || 'N/A'} ft)
Nozzle GPM: ${nozzle?.flowRateGpm || 'N/A'}`);
// Calculate application speed first based on equipment and nozzle