update booking request object

This commit is contained in:
Roba Boru
2026-06-17 20:22:09 +03:00
parent 1dc7766078
commit 6d73359b8e

View File

@@ -144,9 +144,14 @@ export default function ReviewPage() {
const createBookingMutation = useMutation({ const createBookingMutation = useMutation({
mutationFn: (data: any) => { mutationFn: (data: any) => {
const endpoint = isAuthenticated ? '/bookings' : '/bookings/guest'; const endpoint = isAuthenticated ? '/bookings' : '/bookings/guest';
console.log('=== API REQUEST ===');
console.log('Endpoint:', endpoint);
console.log('Request Data:', JSON.stringify(data, null, 2));
return apiClient.post(endpoint, data); return apiClient.post(endpoint, data);
}, },
onSuccess: (data: any) => { onSuccess: (data: any) => {
console.log('=== API RESPONSE SUCCESS ===');
console.log('Response Data:', JSON.stringify(data, null, 2));
console.log('Booking created successfully:', data); console.log('Booking created successfully:', data);
const bookingIdValue = data.bookingId || data.id; const bookingIdValue = data.bookingId || data.id;
const pnrValue = data.pnr || data.bookingReference || data.bookingRef; const pnrValue = data.pnr || data.bookingReference || data.bookingRef;
@@ -178,7 +183,12 @@ export default function ReviewPage() {
}, 100); }, 100);
}, },
onError: (error: any) => { onError: (error: any) => {
console.error('Booking creation failed:', error); console.log('=== API RESPONSE ERROR ===');
console.error('Error Object:', error);
console.error('Error Response:', error?.response);
console.error('Error Response Data:', JSON.stringify(error?.response?.data, null, 2));
console.error('Error Status:', error?.response?.status);
console.error('Error Message:', error?.message);
const errorMessage = error?.response?.data?.message || error?.message || 'Failed to create booking. Please try again.'; const errorMessage = error?.response?.data?.message || error?.message || 'Failed to create booking. Please try again.';
alert(errorMessage); alert(errorMessage);
}, },
@@ -196,7 +206,7 @@ export default function ReviewPage() {
console.log('Inbound schedule:', inboundSchedule); console.log('Inbound schedule:', inboundSchedule);
console.log('Passengers:', passengers); console.log('Passengers:', passengers);
if (!seatHold?.holdId) { if (!seatHold?.holdId && (passengers.some(p => p.seatId) || passengers.some(p => (p as any).outboundSeatId || (p as any).inboundSeatId))) {
console.error('No seat hold found'); console.error('No seat hold found');
alert('Please select seats before continuing.'); alert('Please select seats before continuing.');
router.push('/booking/seats'); router.push('/booking/seats');
@@ -285,6 +295,7 @@ export default function ReviewPage() {
const isEthiopian = p.nationality === 'ETHIOPIAN' || p.nationality === 'Ethiopian'; const isEthiopian = p.nationality === 'ETHIOPIAN' || p.nationality === 'Ethiopian';
return { return {
seatId: isRoundTrip ? (p as any).outboundSeatId : (p.seatId || ''), seatId: isRoundTrip ? (p as any).outboundSeatId : (p.seatId || ''),
...(isRoundTrip && { returnSeatId: (p as any).inboundSeatId || '' }),
passengerName: p.name, passengerName: p.name,
dateOfBirth: p.dateOfBirth, dateOfBirth: p.dateOfBirth,
idDocumentType: isEthiopian ? 'NATIONAL_ID' : 'PASSPORT', idDocumentType: isEthiopian ? 'NATIONAL_ID' : 'PASSPORT',
@@ -323,6 +334,7 @@ export default function ReviewPage() {
const isEthiopian = p.nationality === 'ETHIOPIAN' || p.nationality === 'Ethiopian'; const isEthiopian = p.nationality === 'ETHIOPIAN' || p.nationality === 'Ethiopian';
return { return {
seatId: isRoundTrip ? (p as any).outboundSeatId : (p.seatId || ''), seatId: isRoundTrip ? (p as any).outboundSeatId : (p.seatId || ''),
...(isRoundTrip && { returnSeatId: (p as any).inboundSeatId || '' }),
passengerName: p.name, passengerName: p.name,
dateOfBirth: p.dateOfBirth, dateOfBirth: p.dateOfBirth,
idDocumentType: isEthiopian ? 'NATIONAL_ID' : 'PASSPORT', idDocumentType: isEthiopian ? 'NATIONAL_ID' : 'PASSPORT',
@@ -358,7 +370,8 @@ export default function ReviewPage() {
localStorage.setItem('deviceId', bookingData.deviceId); localStorage.setItem('deviceId', bookingData.deviceId);
} }
console.log('Creating booking with payload:', bookingData); console.log('Creating booking with payload:', JSON.stringify(bookingData, null, 2));
console.log('API endpoint:', isAuthenticated ? '/bookings' : '/bookings/guest');
await createBookingMutation.mutateAsync(bookingData); await createBookingMutation.mutateAsync(bookingData);
} catch (error) { } catch (error) {
console.error('Error in handleConfirm:', error); console.error('Error in handleConfirm:', error);