| const prisma = require('../config/database'); |
| const { detectAbsorptionOpportunity } = require('./synergyController'); |
|
|
| |
| |
| |
| |
| exports.updateLocation = async (req, res) => { |
| try { |
| const { truckId, lat, lng, speed, heading } = req.body; |
| const io = req.app.get('io'); |
|
|
| if (!truckId || lat === undefined || lng === undefined) { |
| return res.status(400).json({ success: false, message: 'truckId, lat, and lng are required' }); |
| } |
|
|
| |
| const truck = await prisma.truck.update({ |
| where: { id: truckId }, |
| data: { |
| currentLat: lat, |
| currentLng: lng |
| } |
| }); |
|
|
| |
| await prisma.gPSLog.create({ |
| data: { |
| truckId, |
| latitude: lat, |
| longitude: lng, |
| speed, |
| heading |
| } |
| }); |
|
|
| |
| |
| const opportunity = await detectAbsorptionOpportunity(truckId, lat, lng, io); |
|
|
| res.status(200).json({ |
| success: true, |
| message: 'Location updated', |
| opportunityDetected: !!opportunity |
| }); |
|
|
| } catch (error) { |
| console.error('Update Location Error:', error); |
| res.status(500).json({ success: false, message: 'Internal server error' }); |
| } |
| }; |
|
|