Allow card revoke by UUID or cardId
All checks were successful
build-and-deploy / build-deploy (push) Successful in 32s

This commit is contained in:
androidlover5842
2026-01-28 18:18:18 +05:30
parent 8ba77232c3
commit 8c69a18e75
2 changed files with 18 additions and 2 deletions

View File

@@ -153,11 +153,11 @@ class IssuedCards(
@PostMapping("/cards/{cardId}/revoke")
fun revoke(
@PathVariable propertyId: UUID,
@PathVariable cardId: UUID,
@PathVariable cardId: String,
@AuthenticationPrincipal principal: MyPrincipal?
): CardRevokeResponse {
requireRevokeActor(propertyId, principal)
val card = issuedCardRepo.findByIdAndPropertyId(cardId, propertyId)
val card = findCardForRevoke(cardId, propertyId)
?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Card not found")
if (card.revokedAt == null) {
val now = nowForProperty(card.property.timezone)
@@ -238,6 +238,21 @@ class IssuedCards(
propertyAccess.requireAnyRole(propertyId, principal.userId, Role.ADMIN)
}
private fun findCardForRevoke(cardId: String, propertyId: UUID): IssuedCard? {
val trimmed = cardId.trim()
if (trimmed.isBlank()) return null
val uuid = try {
java.util.UUID.fromString(trimmed)
} catch (_: Exception) {
null
}
return if (uuid != null) {
issuedCardRepo.findByIdAndPropertyId(uuid, propertyId)
} else {
issuedCardRepo.findByCardIdIgnoreCaseAndPropertyId(trimmed, propertyId)
}
}
private fun nextCardIndex(propertyId: UUID): Int {
var counter = counterRepo.findByPropertyIdForUpdate(propertyId)
if (counter == null) {