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 { private fun resolveRoomType(propertyId: UUID, request: RoomUpsertRequest): com.android.trisolarisserver.models.room.RoomType {
request.roomTypeId?.let { id -> val code = request.roomTypeCode.trim()
roomTypeRepo.findByIdAndPropertyId(id, propertyId)?.let { return it } if (code.isBlank()) {
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "roomTypeCode required")
} }
val code = request.roomTypeCode?.trim() return roomTypeRepo.findByPropertyIdAndCodeIgnoreCase(propertyId, code)
if (!code.isNullOrBlank()) { ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Room type not found")
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")
} }
} }

View File

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