admin area
This commit is contained in:
38
core/admin/domain/value-objects/UserId.ts
Normal file
38
core/admin/domain/value-objects/UserId.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user