Close booking on single-stay specific checkout
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s

This commit is contained in:
androidlover5842
2026-02-02 08:25:14 +05:30
parent e81a656254
commit a7aa842cbb

View File

@@ -566,9 +566,18 @@ class BookingFlow(
if (booking.status != BookingStatus.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)
?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Room stay not found for booking")
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
}
@@ -597,7 +606,7 @@ class BookingFlow(
)
val remainingActive = roomStayRepo.findActiveByBookingId(bookingId)
if (remainingActive.isEmpty()) {
if (singleStayBooking || remainingActive.isEmpty()) {
booking.status = BookingStatus.CHECKED_OUT
booking.checkoutAt = checkOutAt
booking.updatedAt = now