diff --git a/apps/server/src/auth/domain/value-objects/auth-user-roles.ts b/apps/server/src/auth/domain/value-objects/auth-user-roles.ts index a4d75e56..435ba6b4 100644 --- a/apps/server/src/auth/domain/value-objects/auth-user-roles.ts +++ b/apps/server/src/auth/domain/value-objects/auth-user-roles.ts @@ -17,6 +17,6 @@ export class UserRoles extends ValueObject { } hasRole(role: string): boolean { - return this.value.includes(role); + return this._value.includes(role); } } diff --git a/apps/server/src/auth/domain/value-objects/email-address.ts b/apps/server/src/auth/domain/value-objects/email-address.ts index aa9f6aec..ed583e37 100644 --- a/apps/server/src/auth/domain/value-objects/email-address.ts +++ b/apps/server/src/auth/domain/value-objects/email-address.ts @@ -16,8 +16,4 @@ export class EmailAddress extends ValueObject { const schema = z.string().email({ message: "Invalid email format" }).or(z.null()); return schema.safeParse(email); } - - isEmpty(): boolean { - return this.value === null; - } } diff --git a/apps/server/src/auth/domain/value-objects/password-hash.ts b/apps/server/src/auth/domain/value-objects/password-hash.ts index 504ec196..9e9402d5 100644 --- a/apps/server/src/auth/domain/value-objects/password-hash.ts +++ b/apps/server/src/auth/domain/value-objects/password-hash.ts @@ -30,6 +30,6 @@ export class PasswordHash extends ValueObject { } async compare(plainPassword: string): Promise { - return await bcrypt.compare(plainPassword, this.value); + return await bcrypt.compare(plainPassword, this._value); } } diff --git a/apps/server/src/common/domain/value-object.ts b/apps/server/src/common/domain/value-object.ts index 7550064d..95ed02d6 100644 --- a/apps/server/src/common/domain/value-object.ts +++ b/apps/server/src/common/domain/value-object.ts @@ -1,13 +1,10 @@ import { shallowEqual } from "shallow-equal-object"; export abstract class ValueObject { - protected readonly value: T; + protected readonly _value: T; protected constructor(value: T) { - if (value === null || value === undefined) { - throw new Error("ValueObject value cannot be null or undefined"); - } - this.value = typeof value === "object" ? Object.freeze(value) : value; + this._value = typeof value === "object" && value !== null ? Object.freeze(value) : value; Object.freeze(this); } @@ -17,22 +14,22 @@ export abstract class ValueObject { return false; } - if (other.value === undefined) { + if (other._value === undefined || other._value === null) { return false; } - return shallowEqual(this.value, other.value); + return shallowEqual(this._value, other._value); } getValue(): T { - return this.value; + return this._value; + } + + isEmpty(): boolean { + return this._value === null || this._value === undefined; } toString(): string { - return String(this.value); - } - - clone(): this { - return Object.create(this); + return this._value !== null && this._value !== undefined ? String(this._value) : ""; } } diff --git a/apps/server/tests/setup.ts b/apps/server/tests/setup.ts new file mode 100644 index 00000000..e69de29b