feat: Adds ability to toggle an employee's active status (#3)

Reviewed-on: #3
This commit is contained in:
2025-01-28 17:27:00 +00:00
parent 027c7037a6
commit a76d523541
7 changed files with 54 additions and 5 deletions

View File

@@ -37,6 +37,7 @@ public extension DatabaseClient.Employees {
guard let model = try await EmployeeModel.find(id, on: database) else {
throw NotFoundError()
}
database.logger.debug("Applying updates to employee: \(updates)")
try model.applyUpdate(updates)
try await model.save(on: database)
return try model.toDTO()
@@ -170,8 +171,10 @@ final class EmployeeModel: Model, @unchecked Sendable {
if let lastName = updates.lastName {
self.lastName = lastName
}
if let active = updates.active {
self.active = active
// NB: When html forms are submitted with a checkbox then active is nil
// in the update context.
if active, updates.active == nil || updates.active == false {
active = false
}
}
}