Allow guest creation without phone; auto-create guest on booking
All checks were successful
build-and-deploy / build-deploy (push) Successful in 39s

This commit is contained in:
androidlover5842
2026-01-29 07:10:03 +05:30
parent 97f09f6f75
commit 1033035f7d
3 changed files with 21 additions and 11 deletions

View File

@@ -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()