Include active room numbers in booking list
All checks were successful
build-and-deploy / build-deploy (push) Successful in 35s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 35s
This commit is contained in:
@@ -159,6 +159,14 @@ class BookingFlow(
|
|||||||
} else {
|
} else {
|
||||||
bookingRepo.findByPropertyIdAndStatusInOrderByCreatedAtDesc(propertyId, statuses)
|
bookingRepo.findByPropertyIdAndStatusInOrderByCreatedAtDesc(propertyId, statuses)
|
||||||
}
|
}
|
||||||
|
val bookingIds = bookings.mapNotNull { it.id }
|
||||||
|
val roomNumbersByBooking = if (bookingIds.isEmpty()) {
|
||||||
|
emptyMap()
|
||||||
|
} else {
|
||||||
|
roomStayRepo.findActiveRoomNumbersByBookingIds(bookingIds)
|
||||||
|
.groupBy { it.bookingId }
|
||||||
|
.mapValues { (_, rows) -> rows.map { it.roomNumber }.distinct().sorted() }
|
||||||
|
}
|
||||||
return bookings.map { booking ->
|
return bookings.map { booking ->
|
||||||
val guest = booking.primaryGuest
|
val guest = booking.primaryGuest
|
||||||
BookingListItem(
|
BookingListItem(
|
||||||
@@ -167,6 +175,7 @@ class BookingFlow(
|
|||||||
guestId = guest?.id,
|
guestId = guest?.id,
|
||||||
guestName = guest?.name,
|
guestName = guest?.name,
|
||||||
guestPhone = guest?.phoneE164,
|
guestPhone = guest?.phoneE164,
|
||||||
|
roomNumbers = roomNumbersByBooking[booking.id] ?: emptyList(),
|
||||||
source = booking.source,
|
source = booking.source,
|
||||||
expectedCheckInAt = booking.expectedCheckinAt?.toString(),
|
expectedCheckInAt = booking.expectedCheckinAt?.toString(),
|
||||||
expectedCheckOutAt = booking.expectedCheckoutAt?.toString(),
|
expectedCheckOutAt = booking.expectedCheckoutAt?.toString(),
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ data class BookingListItem(
|
|||||||
val guestId: UUID?,
|
val guestId: UUID?,
|
||||||
val guestName: String?,
|
val guestName: String?,
|
||||||
val guestPhone: String?,
|
val guestPhone: String?,
|
||||||
|
val roomNumbers: List<Int>,
|
||||||
val source: String?,
|
val source: String?,
|
||||||
val expectedCheckInAt: String?,
|
val expectedCheckInAt: String?,
|
||||||
val expectedCheckOutAt: String?,
|
val expectedCheckOutAt: String?,
|
||||||
|
|||||||
@@ -89,4 +89,20 @@ interface RoomStayRepo : JpaRepository<RoomStay, UUID> {
|
|||||||
where rs.room.id = :roomId
|
where rs.room.id = :roomId
|
||||||
""")
|
""")
|
||||||
fun existsByRoomId(@Param("roomId") roomId: UUID): Boolean
|
fun existsByRoomId(@Param("roomId") roomId: UUID): Boolean
|
||||||
|
|
||||||
|
@Query("""
|
||||||
|
select rs.booking.id as bookingId, r.roomNumber as roomNumber
|
||||||
|
from RoomStay rs
|
||||||
|
join rs.room r
|
||||||
|
where rs.booking.id in :bookingIds
|
||||||
|
and rs.toAt is null
|
||||||
|
""")
|
||||||
|
fun findActiveRoomNumbersByBookingIds(
|
||||||
|
@Param("bookingIds") bookingIds: List<UUID>
|
||||||
|
): List<BookingRoomNumberRow>
|
||||||
|
}
|
||||||
|
|
||||||
|
interface BookingRoomNumberRow {
|
||||||
|
val bookingId: UUID
|
||||||
|
val roomNumber: Int
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user