Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
Binary file added Screenshot 2025-10-26 at 00.51.22.png
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 Screenshot 2025-10-31 at 21.00.15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ const helmet = require("helmet");
app.use(helmet());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use((req, res, next) => {
console.log(`${req.method} ${req.url}`);
next();
});

app.use(cors({
origin: process.env.FRONTEND_URL ? process.env.FRONTEND_URL.split(',') : ['http://localhost:3000', 'http://localhost:3001', 'http://localhost:3002', 'https://ambulance-booking-phi.vercel.app'],
Expand Down
9 changes: 9 additions & 0 deletions backend/controllers/booking.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,25 @@ module.exports.createBooking = async (req, res, next) => {
}

module.exports.updateBookingStatus = async (req, res, next) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() });
}
console.log('Update Status Request:', { params: req.params, body: req.body });
try {
const { status } = req.body;
const { id } = req.params;
const driverId = req.driver ? req.driver._id : null;
console.log('Searching for booking with:', { id, status, driverId });
const booking = await bookingService.updateBookingStatus(id, status, driverId);
if (!booking) {
console.log('Booking NOT found for ID:', id);
return res.status(404).json({ message: 'Booking not found' });
}
console.log('Booking found and updated:', booking._id);
res.status(200).json(booking);
} catch (err) {
console.error('Update Status Error:', err);
res.status(500).json({ message: err.message });
}
}
Expand Down
6 changes: 6 additions & 0 deletions backend/routes/booking.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ router.put('/:id/status',
bookingController.updateBookingStatus
);

router.patch('/:id/status',
authMiddleware.authDriver,
body('status').isIn(['accepted', 'arrived', 'completed', 'cancelled']).withMessage('Invalid status'),
bookingController.updateBookingStatus
);

router.get('/pending',
authMiddleware.authDriver,
query('lat').optional().isNumeric().withMessage('Latitude must be a number'),
Expand Down
9 changes: 3 additions & 6 deletions frontend/app/driver/request/[id]/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ const MapComponent = dynamic(() => import('@/common/components/MapComponent'), {

export default function RequestDetails({ params }) {
const router = useRouter();
// In Next.js App Router (prior to 15), params is a prop. In 15, it's a promise.
// Assuming 14 or lower based on previous code usually accessing params directly.
// If it breaks, I'll fix it to await params.
const id = params.id;
const { id } = React.use(params);
const [booking, setBooking] = useState(null);

const driverTabs = [
Expand All @@ -38,7 +35,7 @@ export default function RequestDetails({ params }) {

const handleAccept = async () => {
try {
await api.patch(`/bookings/${id}/status`, { status: "accepted" });
await api.put(`/bookings/${id}/status`, { status: "accepted" });
router.push(`/driver/trip/${id}`);
} catch (error) {
console.error("Failed to accept booking:", error);
Expand All @@ -47,7 +44,7 @@ export default function RequestDetails({ params }) {

const handleDecline = async () => {
try {
await api.patch(`/bookings/${id}/status`, { status: "declined" });
await api.put(`/bookings/${id}/status`, { status: "declined" });
router.push('/driver/dashboard');
} catch (error) {
console.error("Failed to decline booking:", error);
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/driver/trip/[id]/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const MapComponent = dynamic(() => import('@/common/components/MapComponent'), {

export default function TripDetailsAccepted({ params }) {
const router = useRouter();
const id = params.id;
const { id } = React.use(params);
const [booking, setBooking] = useState(null);
const [vehicleLocation, setVehicleLocation] = useState(null);
const [socket, setSocket] = useState(null);
Expand Down Expand Up @@ -65,7 +65,7 @@ export default function TripDetailsAccepted({ params }) {

const handleCompleteTrip = async () => {
try {
await api.patch(`/bookings/${id}/status`, { status: "completed" });
await api.put(`/bookings/${id}/status`, { status: "completed" });
router.push('/driver/dashboard');
} catch (error) {
console.error("Failed to complete trip:", error);
Expand Down
Loading