harden business rules

This commit is contained in:
2025-12-27 19:18:54 +01:00
parent 0e7a01d81c
commit 8d2b17d9a8
11 changed files with 343 additions and 55 deletions

View File

@@ -0,0 +1,36 @@
import { z } from "zod";
const CarClassSchema = z
.string()
.trim()
.min(1, "Car class cannot be empty")
.max(50, "Car class must be 50 characters or less");
export class CarClass {
private readonly _value: string;
private constructor(value: string) {
this._value = value;
}
static create(value: string): CarClass {
const validated = CarClassSchema.parse(value);
return new CarClass(validated);
}
static fromString(value: string): CarClass {
return new CarClass(value);
}
get value(): string {
return this._value;
}
equals(other: CarClass): boolean {
return this._value === other._value;
}
toString(): string {
return this._value;
}
}