Files
gridpilot.gg/core/admin/domain/value-objects/UserId.ts
2026-01-01 12:10:35 +01:00

38 lines
825 B
TypeScript

import { IValueObject } from '@core/shared/domain';
import { AdminDomainValidationError } from '../errors/AdminDomainError';
export interface UserIdProps {
value: string;
}
export class UserId implements IValueObject<UserIdProps> {
readonly value: string;
private constructor(value: string) {
this.value = value;
}
static create(id: string): UserId {
if (!id || id.trim().length === 0) {
throw new AdminDomainValidationError('User ID cannot be empty');
}
return new UserId(id.trim());
}
static fromString(id: string): UserId {
return this.create(id);
}
get props(): UserIdProps {
return { value: this.value };
}
equals(other: IValueObject<UserIdProps>): boolean {
return this.value === other.props.value;
}
toString(): string {
return this.value;
}
}