38 lines
834 B
TypeScript
38 lines
834 B
TypeScript
import { ValueObject } from '@core/shared/domain/ValueObject';
|
|
import { AdminDomainValidationError } from '../errors/AdminDomainError';
|
|
|
|
export interface UserIdProps {
|
|
value: string;
|
|
}
|
|
|
|
export class UserId implements ValueObject<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: ValueObject<UserIdProps>): boolean {
|
|
return this.value === other.props.value;
|
|
}
|
|
|
|
toString(): string {
|
|
return this.value;
|
|
}
|
|
} |