WIP: Updates test html snapshots, working on validation when delegating airflow to a different room.
Some checks failed
CI / Linux Tests (push) Has been cancelled

This commit is contained in:
2026-02-06 17:01:43 -05:00
parent f2c79ad56f
commit 0775474f57
6 changed files with 179 additions and 47 deletions

View File

@@ -84,6 +84,14 @@ extension DatabaseClient.Rooms: TestDependencyKey {
extension Room.Create {
func toModel(projectID: Project.ID) throws -> RoomModel {
var registerCount = registerCount
// Set register count appropriately when delegatedTo is set / changes.
if delegatedTo != nil {
registerCount = 0
} else if registerCount == 0 {
registerCount = 1
}
return .init(
name: name,
heatingLoad: heatingLoad,
@@ -229,13 +237,28 @@ final class RoomModel: Model, @unchecked Sendable, Validatable {
Validator.validate(\.coolingLoad)
.errorLabel("Cooling Load", inline: true)
Validator.validate(\.registerCount, with: .greaterThanOrEquals(1))
Validator.validate(\.registerCount, with: .greaterThanOrEquals($room.id == nil ? 1 : 0))
.errorLabel("Register Count", inline: true)
Validator.validate(\.rectangularSizes)
}
}
func validateAndSave(on database: Database) async throws {
try self.validate()
if let delegateTo = $room.id {
guard let parent = try await RoomModel.find(delegateTo, on: database) else {
throw ValidationError("Can not find room: \(delegateTo), to delegate airflow to.")
}
guard parent.$room.id == nil else {
throw ValidationError(
"Can not delegate airflow to a room that also delegates it's own airflow."
)
}
}
try await save(on: database)
}
}
extension Room.CoolingLoad: Validatable {