Skip to content

Commit

Permalink
Mapbox Intergration (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
lksnjw authored Oct 11, 2024
1 parent e168915 commit d59d888
Show file tree
Hide file tree
Showing 65 changed files with 755 additions and 291 deletions.
22 changes: 22 additions & 0 deletions backend/controllers/DLDriverController.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,28 @@ const getAvailableDriversCount = asyncHandler(async (req, res) => {
res.json({ count })
})






// Add this function to check if NIC number and password are equal
export const checkNicPassword = asyncHandler(async (req, res) => {
const driver = await DLDriver.findById(req.driver._id)

if (driver) {
// Compare the NIC number (idCardNumber) and password
const isMatch = await bcrypt.compare(driver.idCardNumber, driver.password)
if (isMatch) {
res.json({ nicMatchesPassword: true }) // If they are the same
} else {
res.json({ nicMatchesPassword: false }) // If they are different
}
} else {
res.status(404).json({ message: 'Driver not found' })
}
})

export { getDriversCount, getAvailableDriversCount }

export {
Expand Down
50 changes: 50 additions & 0 deletions backend/controllers/DLOcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import dOrder from '../models/DLOModel.js'
import Order from '../models/OrderModel.js' // Import the Order model
import Shop from '../models/shopModel.js' // Import the Shop model
import User from '../models/userModel.js' // Import the User model
import DLDelivery from '../models/DLDeliveryModel.js'


// @desc Create a new order
// @route POST /api/orders
Expand Down Expand Up @@ -182,12 +184,60 @@ const assignReadyOrders = async () => {
}
}



// Helper function to update the order status based on delivery status
const syncDeliveryAndOrderStatus = async () => {
try {
// Fetch all deliveries where the status is 'Picked Up', 'On The Way', or 'Delivered'
const deliveries = await DLDelivery.find({
deliveryStatus: { $in: ['Picked Up', 'On The Way', 'Delivered'] }
})

// Iterate over each delivery and update the corresponding order
for (const delivery of deliveries) {
const order = await Order.findById(delivery.orderID)

if (order) {
// Map delivery status to corresponding order status
let newOrderStatus

if (delivery.deliveryStatus === 'Picked Up') {
newOrderStatus = 'Picked Up'
} else if (delivery.deliveryStatus === 'On The Way') {
newOrderStatus = 'On The Way'
} else if (delivery.deliveryStatus === 'Delivered') {
newOrderStatus = 'Delivered'
}

// Update the order's status if it's different
if (order.orderStatus !== newOrderStatus) {
order.orderStatus = newOrderStatus
await order.save() // Save the updated order
console.log(`Order ${order._id} updated to ${newOrderStatus}`)
}
}
}
} catch (error) {
console.error('Error syncing delivery and order status:', error)
}
}



// Function to repeatedly check for ready orders every 5 seconds
const startOrderAssignment = () => {
/* console.log('Starting periodic check for ready orders...')*/
setInterval(assignReadyOrders, 5000) // Run the check every 5 seconds
}

const startSyncDeliveryOrderStatus = () => {
setInterval(syncDeliveryAndOrderStatus, 5000) // Run every 5 seconds
}

export { startSyncDeliveryOrderStatus }


export { startOrderAssignment }

export { deleteOrder }
Expand Down
1 change: 1 addition & 0 deletions backend/models/DLOModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const dorderSchema = new mongoose.Schema(
{
/* generate and store the oID:{type: String,}, */


oID: { type: String },

orderID: {
Expand Down
4 changes: 4 additions & 0 deletions backend/routes/DLDriverRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
verifyPassword,
getDriversCount,
getAvailableDriversCount,
checkNicPassword,

// Add logout driver function
} from '../controllers/DLDriverController.js'
Expand Down Expand Up @@ -63,4 +64,7 @@ router.get('/count', getDriversCount)
// Route to get the number of available drivers
router.get('/available/count', getAvailableDriversCount)

router.get('/nic-password-check', protectDriver, checkNicPassword)


export default router
3 changes: 2 additions & 1 deletion backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import DLEmailRoutes from './routes/DLEmailRoutes.js' //DL
import oRoutes from './routes/DLORoutes.js' // DL
import { checkForAvailableDrivers } from './controllers/DLDeliveryController.js' //DL THIS IS CHECKING ALL ODRS AND ASSIGN DRIVERS
import deliveryRoutes from './routes/DLDeliveryRoute.js' //DL
import { startOrderAssignment } from './controllers/DLOcontroller.js' // Import the periodic check
import { startOrderAssignment,startSyncDeliveryOrderStatus } from './controllers/DLOcontroller.js' // Import the periodic check

checkForAvailableDrivers() //DL
startOrderAssignment()
startSyncDeliveryOrderStatus() //DL

import { errorHandler, notFound } from './middlewares/errorMiddleware.js'

Expand Down
Binary file added backend/uploads/1727053967402-id1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727053967402-images (1).jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727053967402-li1 - Copy (2).jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727054250696-id2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727054250696-images (2).jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727054250696-li1 - Copy (3).jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727055520267-li1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727060006946-id1 - Copy.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727060006947-id1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727060006947-images.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727060871491-download.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727060871491-id1 - Copy.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727060871491-li1 - Copy (3).jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727061115161-id1 - Copy.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727061115162-images (2).jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727061115162-li1 - Copy (3).jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727062096026-id1 - Copy.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727062096026-images (2).jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727062096026-li1 - Copy (2).jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727519172982-images (1).jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727519172982-li1 - Copy.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727519172984-id2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/uploads/1727544307081-images (1).jpeg
Binary file added backend/uploads/1727544307081-images (2).jpeg
Binary file added backend/uploads/1727544350765-images (1).jpeg
Binary file added backend/uploads/1727544350765-images (2).jpeg
Binary file added backend/uploads/1727544653930-images (1).jpeg
Binary file added backend/uploads/1727544780630-images (1).jpeg
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"jspdf-invoice-template": "^1.4.4",
"lucide": "^0.433.0",
"lucide-react": "^0.436.0",
"mapbox-gl": "^3.7.0",
"react": "^18.3.1",
"react-chartjs-2": "^5.2.0",
"react-dom": "^18.3.1",
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import AddStaff from './Pages/Admin/AaddStaff'
import UpdateStaff from './Pages/Admin/AupdateStaff'
import AddCoupon from './Pages/Admin/AaddCoupons'
import UpdateCoupon from './Pages/Admin/AupdateCoupon'
import AdminLogin from './Components/Admin/admnlogins'

// Farmer Pages
import FarmerLogin from './Pages/farmer/FarmerLogin'
Expand All @@ -70,7 +71,6 @@ import DLDriverRegistrationForm from './Pages/delivery/DLDriverRegistrationForm'
import DLApproveDriver from './Pages/delivery/DLApproveDriver' // Ensure the path is correct
import DLDriverAccept from './Pages/delivery/DLDriverAccept'
import DLImageUpload from './Pages/delivery/DLImageUpload'
import DLSendEmail from './Pages/delivery/DLSendEmail' // Import the DLSendEmail component
import DLLogin from './Pages/delivery/DLLogin' // Added DLLogin import

import DeliveryDashboard from './Pages/delivery/DLDriverDashboard'
Expand All @@ -89,6 +89,8 @@ import DLViewDelivery from './Pages/delivery/DLviewDelivery' // Import the
import OngoingDelivery from './Pages/delivery/driver/OngoingDelivery' // Import the OngoingDelivery component
import ViewDelivery from './Pages/delivery/driver/ViewDelivery' // Import the ViewDelivery page
import ViewDeliveries from './Pages/delivery/driver/ViewDeliveries' // Import the ViewDeliveries page
import DLMap from './Pages/delivery/DLMap' // Import the DLMap component
import IncomePage from './Pages/delivery/driver/incomepage' // Import the DLList component

// Define all routes in a single Router
const router = createBrowserRouter(
Expand Down Expand Up @@ -189,6 +191,8 @@ const router = createBrowserRouter(
<Route path="/updatecoupon/:id" element={<UpdateCoupon />} />
<Route path="/coupens" element={<Coupens />} />
<Route path="/finance" element={<Finance />} />
<Route path="/adl" element={<AdminLogin />} />

{/*
<Route path="/dashboard" element={< Dashboard/>} />
*/}
Expand Down Expand Up @@ -248,6 +252,8 @@ const router = createBrowserRouter(
/>{' '}
{/* Route for viewing a specific delivery */}
<Route path="/driver/deliveries" element={<ViewDeliveries />} />
<Route path="/driver/income" element={<IncomePage />} />
<Route path="/driver/map" element={<DLMap />} />
<Route path="*" element={<NotFound />} />
</Route>

Expand Down
Loading

0 comments on commit d59d888

Please sign in to comment.