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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user