gps tracking stuff
This commit is contained in:
@@ -1008,6 +1008,8 @@ router.get('/logs', async (req, res, next) => {
|
||||
// @access Private
|
||||
router.post('/logs', validateRequest(applicationLogSchema), async (req, res, next) => {
|
||||
try {
|
||||
console.log('Create log request received:', JSON.stringify(req.body, null, 2));
|
||||
|
||||
const {
|
||||
planId,
|
||||
lawnSectionId,
|
||||
@@ -1052,6 +1054,18 @@ router.post('/logs', validateRequest(applicationLogSchema), async (req, res, nex
|
||||
}
|
||||
|
||||
// Create application log
|
||||
console.log('Inserting application log with values:', {
|
||||
planId,
|
||||
userId: req.user.id,
|
||||
lawnSectionId,
|
||||
equipmentId,
|
||||
weatherConditions: JSON.stringify(weatherConditions),
|
||||
gpsTrack: JSON.stringify(gpsTrack),
|
||||
averageSpeed,
|
||||
areaCovered,
|
||||
notes
|
||||
});
|
||||
|
||||
const logResult = await client.query(
|
||||
`INSERT INTO application_logs
|
||||
(plan_id, user_id, lawn_section_id, equipment_id, weather_conditions,
|
||||
@@ -1064,8 +1078,10 @@ router.post('/logs', validateRequest(applicationLogSchema), async (req, res, nex
|
||||
);
|
||||
|
||||
const log = logResult.rows[0];
|
||||
console.log('Application log inserted successfully:', log);
|
||||
|
||||
// Add products to log
|
||||
console.log('Adding products to log:', products);
|
||||
for (const product of products) {
|
||||
const {
|
||||
productId,
|
||||
@@ -1077,6 +1093,11 @@ router.post('/logs', validateRequest(applicationLogSchema), async (req, res, nex
|
||||
actualSpeedMph
|
||||
} = product;
|
||||
|
||||
console.log('Inserting product:', {
|
||||
logId: log.id, productId, userProductId, rateAmount, rateUnit,
|
||||
actualProductAmount, actualWaterAmount, actualSpeedMph
|
||||
});
|
||||
|
||||
await client.query(
|
||||
`INSERT INTO application_log_products
|
||||
(log_id, product_id, user_product_id, rate_amount, rate_unit,
|
||||
@@ -1085,6 +1106,8 @@ router.post('/logs', validateRequest(applicationLogSchema), async (req, res, nex
|
||||
[log.id, productId, userProductId, rateAmount, rateUnit,
|
||||
actualProductAmount, actualWaterAmount, actualSpeedMph]
|
||||
);
|
||||
|
||||
console.log('Product inserted successfully');
|
||||
}
|
||||
|
||||
// If this was from a plan, mark the plan as completed
|
||||
|
||||
@@ -177,7 +177,7 @@ const applicationLogSchema = Joi.object({
|
||||
actualProductAmount: Joi.number().positive(),
|
||||
actualWaterAmount: Joi.number().positive(),
|
||||
actualSpeedMph: Joi.number().positive()
|
||||
})).min(1).required()
|
||||
}).or('productId', 'userProductId')).min(1).required()
|
||||
});
|
||||
|
||||
// Validation middleware
|
||||
|
||||
Reference in New Issue
Block a user