Link guest by phone on booking create
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:
@@ -77,8 +77,11 @@ class BookingFlow(
|
|||||||
|
|
||||||
val now = nowForProperty(property.timezone)
|
val now = nowForProperty(property.timezone)
|
||||||
val shouldCheckIn = !expectedCheckInAt.isBefore(now)
|
val shouldCheckIn = !expectedCheckInAt.isBefore(now)
|
||||||
|
val phone = request.guestPhoneE164?.trim()?.takeIf { it.isNotBlank() }
|
||||||
|
val guest = resolveGuestForBooking(propertyId, property, actor, now, phone)
|
||||||
val booking = com.android.trisolarisserver.models.booking.Booking(
|
val booking = com.android.trisolarisserver.models.booking.Booking(
|
||||||
property = property,
|
property = property,
|
||||||
|
primaryGuest = guest,
|
||||||
status = if (shouldCheckIn) BookingStatus.CHECKED_IN else BookingStatus.OPEN,
|
status = if (shouldCheckIn) BookingStatus.CHECKED_IN else BookingStatus.OPEN,
|
||||||
source = request.source?.trim().takeIf { !it.isNullOrBlank() } ?: "WALKIN",
|
source = request.source?.trim().takeIf { !it.isNullOrBlank() } ?: "WALKIN",
|
||||||
checkinAt = if (shouldCheckIn) expectedCheckInAt else null,
|
checkinAt = if (shouldCheckIn) expectedCheckInAt else null,
|
||||||
@@ -99,19 +102,10 @@ class BookingFlow(
|
|||||||
)
|
)
|
||||||
|
|
||||||
val saved = bookingRepo.save(booking)
|
val saved = bookingRepo.save(booking)
|
||||||
val guest = com.android.trisolarisserver.models.booking.Guest(
|
|
||||||
property = property,
|
|
||||||
createdBy = actor,
|
|
||||||
updatedAt = now
|
|
||||||
)
|
|
||||||
val savedGuest = guestRepo.save(guest)
|
|
||||||
saved.primaryGuest = savedGuest
|
|
||||||
saved.updatedAt = now
|
|
||||||
bookingRepo.save(saved)
|
|
||||||
return BookingCreateResponse(
|
return BookingCreateResponse(
|
||||||
id = saved.id!!,
|
id = saved.id!!,
|
||||||
status = saved.status.name,
|
status = saved.status.name,
|
||||||
guestId = savedGuest.id,
|
guestId = guest.id,
|
||||||
checkInAt = saved.checkinAt?.toString(),
|
checkInAt = saved.checkinAt?.toString(),
|
||||||
expectedCheckInAt = saved.expectedCheckinAt?.toString(),
|
expectedCheckInAt = saved.expectedCheckinAt?.toString(),
|
||||||
expectedCheckOutAt = saved.expectedCheckoutAt?.toString()
|
expectedCheckOutAt = saved.expectedCheckoutAt?.toString()
|
||||||
@@ -241,6 +235,28 @@ class BookingFlow(
|
|||||||
roomBoardEvents.emit(propertyId)
|
roomBoardEvents.emit(propertyId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun resolveGuestForBooking(
|
||||||
|
propertyId: UUID,
|
||||||
|
property: com.android.trisolarisserver.models.property.Property,
|
||||||
|
actor: com.android.trisolarisserver.models.property.AppUser?,
|
||||||
|
now: OffsetDateTime,
|
||||||
|
phone: String?
|
||||||
|
): com.android.trisolarisserver.models.booking.Guest {
|
||||||
|
if (phone != null) {
|
||||||
|
val existing = guestRepo.findByPropertyIdAndPhoneE164(propertyId, phone)
|
||||||
|
if (existing != null) {
|
||||||
|
return existing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val guest = com.android.trisolarisserver.models.booking.Guest(
|
||||||
|
property = property,
|
||||||
|
phoneE164 = phone,
|
||||||
|
createdBy = actor,
|
||||||
|
updatedAt = now
|
||||||
|
)
|
||||||
|
return guestRepo.save(guest)
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/{bookingId}/cancel")
|
@PostMapping("/{bookingId}/cancel")
|
||||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||||
@Transactional
|
@Transactional
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ data class BookingCreateRequest(
|
|||||||
val source: String? = null,
|
val source: String? = null,
|
||||||
val expectedCheckInAt: String,
|
val expectedCheckInAt: String,
|
||||||
val expectedCheckOutAt: String,
|
val expectedCheckOutAt: String,
|
||||||
|
val guestPhoneE164: String? = null,
|
||||||
val transportMode: String? = null,
|
val transportMode: String? = null,
|
||||||
val adultCount: Int? = null,
|
val adultCount: Int? = null,
|
||||||
val totalGuestCount: Int? = null,
|
val totalGuestCount: Int? = null,
|
||||||
|
|||||||
Reference in New Issue
Block a user