Files
gridpilot.gg/packages/identity/domain/value-objects/UserId.ts
2025-12-11 13:50:38 +01:00

32 lines
700 B
TypeScript

import type { IValueObject } from '@gridpilot/shared/domain';
export interface UserIdProps {
value: string;
}
export class UserId implements IValueObject<UserIdProps> {
public readonly props: UserIdProps;
private constructor(value: string) {
if (!value || !value.trim()) {
throw new Error('UserId cannot be empty');
}
this.props = { value };
}
public static fromString(value: string): UserId {
return new UserId(value);
}
get value(): string {
return this.props.value;
}
public toString(): string {
return this.props.value;
}
public equals(other: IValueObject<UserIdProps>): boolean {
return this.props.value === other.props.value;
}
}