Skip to content

Commit

Permalink
Allow existing sessions to be found (#537)
Browse files Browse the repository at this point in the history
Co-authored-by: zlrkw11 <[email protected]>
  • Loading branch information
choden-dev and zlrkw11 authored Jun 28, 2024
1 parent 88f78d5 commit 90ef032
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions server/src/service-layer/controllers/PaymentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,38 +265,19 @@ export class PaymentController extends Controller {
const userDataService = new UserDataService()

try {
/**
* Declare these with outer scope as they are used in most paths
*/
const { startDate, endDate } = requestBody
const userData = await userDataService.getUserData(uid)

const { newUser, stripeCustomerId } =
await stripeService.createCustomerIfNotExist(
request.user,
userData,
userDataService
)

/**
* Declare these with outer scope as they are used in most paths
*/
const { startDate, endDate } = requestBody

const dateTimestampsInBooking = timestampsInRange(startDate, endDate)
const totalDays = dateTimestampsInBooking.length

/**
* Used for formatted display to user
*/
const BOOKING_START_DATE = UTCDateToDdMmYyyy(
new Date(firestoreTimestampToDate(dateTimestampsInBooking[0]))
)

/**
* Used for formatted display to user
*/
const BOOKING_END_DATE = UTCDateToDdMmYyyy(
new Date(
firestoreTimestampToDate(dateTimestampsInBooking[totalDays - 1])
)
)

/**
* The amount of time users have to complete a session
*/
Expand Down Expand Up @@ -340,6 +321,25 @@ export class PaymentController extends Controller {
}
}

const dateTimestampsInBooking = timestampsInRange(startDate, endDate)
const totalDays = dateTimestampsInBooking.length

/**
* Used for formatted display to user
*/
const BOOKING_START_DATE = UTCDateToDdMmYyyy(
new Date(firestoreTimestampToDate(dateTimestampsInBooking[0]))
)

/**
* Used for formatted display to user
*/
const BOOKING_END_DATE = UTCDateToDdMmYyyy(
new Date(
firestoreTimestampToDate(dateTimestampsInBooking[totalDays - 1])
)
)

const MAX_BOOKING_DAYS = 10
// Validate number of dates to avoid kiddies from forging bookings
if (totalDays > MAX_BOOKING_DAYS) {
Expand Down

0 comments on commit 90ef032

Please sign in to comment.