Skip to content

Commit 21c35d7

Browse files
committed
Fixed some bugs in bookingCompleteController
1 parent f6a9084 commit 21c35d7

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

controllers/bookingCompleteController.mjs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async function getBookingComplete(req, res, next) {
4949
if (req.session.bookingToken !== bookingToken) {
5050
const error_comment = "Booking token mismatch, invalid or expired.";
5151
console.error(error_comment);
52-
next(new Error("Booking token mismatch, invalid or expired."));
52+
next(new Error(error_comment));
5353
}
5454
// get show details
5555
model.getES_E_V(showID, async (err, result) => {
@@ -93,7 +93,6 @@ async function getBookingComplete(req, res, next) {
9393
discountCategoryName = ticket.discountCategory.split(',')[0];
9494
}
9595
const discountCategory = await model.getDiscountFromType(discountCategoryName);
96-
console.log("Discount Category", discountCategory)
9796
const discountID = discountCategory[0].discountID;
9897

9998
// get the categoryID from the seating category
@@ -104,13 +103,10 @@ async function getBookingComplete(req, res, next) {
104103
const date_booked = new Date().toISOString().slice(0, 19).replace('T', ' ');
105104
// console.log("discountID", discountID, "categoryID", categoryID, "showID", showID, "date_booked", date_booked, "userID", req.session.loggedUserId);
106105

107-
if (req.session.bookingToken) {
108-
const lastInsertedTicketID = await model.insertTicket(ticket.ticketNumber, 'BOOKED', categoryID, req.session.loggedUserId, date_booked, discountID, showID);
109-
// destroy the booking token
110-
req.session.bookingToken = null;
111-
ticket.ticketID = lastInsertedTicketID;
112-
console.log("Ticket stored in the database", ticket.ticketID);
113-
}
106+
const lastInsertedTicketID = await model.insertTicket(ticket.ticketNumber, 'BOOKED', categoryID, req.session.loggedUserId, date_booked, discountID, showID);
107+
// destroy the booking token
108+
ticket.ticketID = lastInsertedTicketID;
109+
console.log("Ticket stored in the database", ticket.ticketID);
114110
} catch (err) {
115111
const error_comment = "Failed to store ticket in the database";
116112
console.error(error_comment);
@@ -159,15 +155,14 @@ async function getBookingComplete(req, res, next) {
159155
ticket.discountCategory = ticket.discountCategory.replace('%25', '%');
160156
}
161157
});
162-
// console.log("Booking Info",bookingInfo);
163158
}
164159
let error_comment;
165160
let error_message;
166161
if (!success) {
167162
error_comment = "Network error while processing payment."; // generic dummy comment
168163
error_message = "Payment processing failed. Please try again."; // generic dummy message
169164
}
170-
165+
req.session.bookingToken = "Token used";
171166
res.render('booking_complete', {success: bookingInfo[0].success, eventInfo: eventShowInfo, tickets: bookingInfo, totalAmount, error_comment, error_message});
172167
}
173168
});

index.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const port = process.env.PORT || '3000';
1414

1515
const server = application.listen(port, () => {
1616
console.log(`Server listening at http://localhost:${port}`);
17+
console.log(`Server running in ${process.env.NODE_ENV} mode`);
1718
});
1819

1920
process.on('SIGTERM', () => {

0 commit comments

Comments
 (0)