Close booking on single-stay specific checkout
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s
This commit is contained in:
@@ -566,9 +566,18 @@ class BookingFlow(
|
|||||||
if (booking.status != BookingStatus.CHECKED_IN) {
|
if (booking.status != BookingStatus.CHECKED_IN) {
|
||||||
throw ResponseStatusException(HttpStatus.CONFLICT, "Booking not checked in")
|
throw ResponseStatusException(HttpStatus.CONFLICT, "Booking not checked in")
|
||||||
}
|
}
|
||||||
|
val staysForBooking = roomStayRepo.findByBookingId(bookingId)
|
||||||
|
val singleStayBooking = staysForBooking.size == 1
|
||||||
val stay = roomStayRepo.findByIdAndBookingId(roomStayId, bookingId)
|
val stay = roomStayRepo.findByIdAndBookingId(roomStayId, bookingId)
|
||||||
?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Room stay not found for booking")
|
?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Room stay not found for booking")
|
||||||
if (stay.toAt != null) {
|
if (stay.toAt != null) {
|
||||||
|
if (singleStayBooking) {
|
||||||
|
booking.status = BookingStatus.CHECKED_OUT
|
||||||
|
booking.checkoutAt = stay.toAt
|
||||||
|
booking.updatedAt = OffsetDateTime.now()
|
||||||
|
bookingRepo.save(booking)
|
||||||
|
bookingEvents.emit(propertyId, bookingId)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -597,7 +606,7 @@ class BookingFlow(
|
|||||||
)
|
)
|
||||||
|
|
||||||
val remainingActive = roomStayRepo.findActiveByBookingId(bookingId)
|
val remainingActive = roomStayRepo.findActiveByBookingId(bookingId)
|
||||||
if (remainingActive.isEmpty()) {
|
if (singleStayBooking || remainingActive.isEmpty()) {
|
||||||
booking.status = BookingStatus.CHECKED_OUT
|
booking.status = BookingStatus.CHECKED_OUT
|
||||||
booking.checkoutAt = checkOutAt
|
booking.checkoutAt = checkOutAt
|
||||||
booking.updatedAt = now
|
booking.updatedAt = now
|
||||||
|
|||||||
Reference in New Issue
Block a user