Require roomTypeCode for room upsert
All checks were successful
build-and-deploy / build-deploy (push) Successful in 27s

This commit is contained in:
androidlover5842
2026-01-27 03:14:58 +05:30
parent 40a09d1c83
commit a39a9dcd1f
2 changed files with 6 additions and 12 deletions

View File

@@ -247,17 +247,12 @@ class Rooms(
}
private fun resolveRoomType(propertyId: UUID, request: RoomUpsertRequest): com.android.trisolarisserver.models.room.RoomType {
request.roomTypeId?.let { id ->
roomTypeRepo.findByIdAndPropertyId(id, propertyId)?.let { return it }
val code = request.roomTypeCode.trim()
if (code.isBlank()) {
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "roomTypeCode required")
}
val code = request.roomTypeCode?.trim()
if (!code.isNullOrBlank()) {
roomTypeRepo.findByPropertyIdAndCodeIgnoreCase(propertyId, code)?.let { return it }
}
if (request.roomTypeId == null && code.isNullOrBlank()) {
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "roomTypeId or roomTypeCode required")
}
throw ResponseStatusException(HttpStatus.NOT_FOUND, "Room type not found")
return roomTypeRepo.findByPropertyIdAndCodeIgnoreCase(propertyId, code)
?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Room type not found")
}
}

View File

@@ -52,8 +52,7 @@ enum class RoomBoardStatus {
data class RoomUpsertRequest(
val roomNumber: Int,
val floor: Int?,
val roomTypeId: UUID? = null,
val roomTypeCode: String? = null,
val roomTypeCode: String,
val hasNfc: Boolean,
val active: Boolean,
val maintenance: Boolean,