Files
gridpilot.gg/core/identity/domain/value-objects/UserId.ts
2025-12-16 11:52:26 +01:00

37 lines
805 B
TypeScript

import { v4 as uuidv4 } from 'uuid';
import type { IValueObject } from '@core/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 create(): UserId {
return new UserId(uuidv4());
}
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;
}
}