Auto-generate property codes and join by code
All checks were successful
build-and-deploy / build-deploy (push) Successful in 40s

This commit is contained in:
androidlover5842
2026-02-01 22:58:25 +05:30
parent 7aca2361ca
commit 5df019ed6e
5 changed files with 19 additions and 9 deletions

View File

@@ -97,10 +97,12 @@ class PropertyAccessCodes(
throw ResponseStatusException(HttpStatus.NOT_FOUND, "Invalid code")
}
val now = OffsetDateTime.now()
val accessCode = accessCodeRepo.findActiveByPropertyAndCode(request.propertyId, code, now)
val property = propertyRepo.findByCode(request.propertyCode.trim())
?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Property not found")
val accessCode = accessCodeRepo.findActiveByPropertyAndCode(property.id!!, code, now)
?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Invalid code")
val membershipId = PropertyUserId(propertyId = request.propertyId, userId = resolved.userId)
val membershipId = PropertyUserId(propertyId = property.id, userId = resolved.userId)
if (propertyUserRepo.existsById(membershipId)) {
throw ResponseStatusException(HttpStatus.CONFLICT, "User already a member")
}
@@ -111,7 +113,7 @@ class PropertyAccessCodes(
val propertyUser = PropertyUser(
id = membershipId,
property = accessCode.property,
property = property,
user = user,
roles = accessCode.roles.toMutableSet()
)