Files
gridpilot.gg/core/identity/domain/value-objects/UserId.ts
2026-01-16 16:46:57 +01:00

37 lines
814 B
TypeScript

import { v4 as uuidv4 } from 'uuid';
import type { ValueObject } from '@core/shared/domain/ValueObject';
export interface UserIdProps {
value: string;
}
export class UserId implements ValueObject<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: ValueObject<UserIdProps>): boolean {
return this.props.value === other.props.value;
}
}