Allow guest creation without phone; auto-create guest on booking
All checks were successful
build-and-deploy / build-deploy (push) Successful in 39s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 39s
This commit is contained in:
@@ -10,6 +10,7 @@ import com.android.trisolarisserver.controller.dto.BookingCreateResponse
|
||||
import com.android.trisolarisserver.controller.dto.BookingNoShowRequest
|
||||
import com.android.trisolarisserver.controller.dto.RoomStayPreAssignRequest
|
||||
import com.android.trisolarisserver.db.repo.BookingRepo
|
||||
import com.android.trisolarisserver.db.repo.GuestRepo
|
||||
import com.android.trisolarisserver.models.booking.BookingStatus
|
||||
import com.android.trisolarisserver.models.booking.TransportMode
|
||||
import com.android.trisolarisserver.models.room.RoomStay
|
||||
@@ -38,6 +39,7 @@ import java.util.UUID
|
||||
class BookingFlow(
|
||||
private val propertyAccess: PropertyAccess,
|
||||
private val bookingRepo: BookingRepo,
|
||||
private val guestRepo: GuestRepo,
|
||||
private val roomRepo: RoomRepo,
|
||||
private val roomStayRepo: RoomStayRepo,
|
||||
private val appUserRepo: AppUserRepo,
|
||||
@@ -90,6 +92,15 @@ class BookingFlow(
|
||||
)
|
||||
|
||||
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(
|
||||
id = saved.id!!,
|
||||
status = saved.status.name,
|
||||
|
||||
@@ -48,10 +48,7 @@ class Guests(
|
||||
requireMember(propertyAccess, propertyId, principal)
|
||||
val property = requireProperty(propertyRepo, propertyId)
|
||||
|
||||
val phone = request.phoneE164.trim()
|
||||
if (phone.isBlank()) {
|
||||
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "phoneE164 required")
|
||||
}
|
||||
val phone = request.phoneE164?.trim()?.takeIf { it.isNotBlank() }
|
||||
val booking = bookingRepo.findById(request.bookingId).orElseThrow {
|
||||
ResponseStatusException(HttpStatus.NOT_FOUND, "Booking not found")
|
||||
}
|
||||
@@ -61,12 +58,14 @@ class Guests(
|
||||
if (booking.primaryGuest != null) {
|
||||
throw ResponseStatusException(HttpStatus.CONFLICT, "Booking already linked to guest")
|
||||
}
|
||||
val existing = guestRepo.findByPropertyIdAndPhoneE164(propertyId, phone)
|
||||
if (existing != null) {
|
||||
booking.primaryGuest = existing
|
||||
booking.updatedAt = OffsetDateTime.now()
|
||||
bookingRepo.save(booking)
|
||||
return setOf(existing).toResponse(propertyId, guestVehicleRepo, guestRatingRepo).first()
|
||||
if (phone != null) {
|
||||
val existing = guestRepo.findByPropertyIdAndPhoneE164(propertyId, phone)
|
||||
if (existing != null) {
|
||||
booking.primaryGuest = existing
|
||||
booking.updatedAt = OffsetDateTime.now()
|
||||
bookingRepo.save(booking)
|
||||
return setOf(existing).toResponse(propertyId, guestVehicleRepo, guestRatingRepo).first()
|
||||
}
|
||||
}
|
||||
|
||||
val now = OffsetDateTime.now()
|
||||
|
||||
@@ -51,8 +51,8 @@ data class GuestResponse(
|
||||
)
|
||||
|
||||
data class GuestCreateRequest(
|
||||
val phoneE164: String,
|
||||
val bookingId: UUID,
|
||||
val phoneE164: String? = null,
|
||||
val name: String? = null,
|
||||
val nationality: String? = null,
|
||||
val addressText: String? = null
|
||||
|
||||
Reference in New Issue
Block a user