59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import { ValueObject } from '@core/shared/domain/ValueObject';
|
|
import { AdminDomainValidationError } from '../errors/AdminDomainError';
|
|
|
|
export type UserStatusValue = string;
|
|
|
|
export interface UserStatusProps {
|
|
value: UserStatusValue;
|
|
}
|
|
|
|
export class UserStatus implements ValueObject<UserStatusProps> {
|
|
readonly value: UserStatusValue;
|
|
|
|
private constructor(value: UserStatusValue) {
|
|
this.value = value;
|
|
}
|
|
|
|
static create(value: UserStatusValue): UserStatus {
|
|
// Handle null/undefined
|
|
if (value === null || value === undefined) {
|
|
throw new AdminDomainValidationError('Status cannot be empty');
|
|
}
|
|
|
|
const trimmed = value.trim();
|
|
|
|
if (!trimmed) {
|
|
throw new AdminDomainValidationError('Status cannot be empty');
|
|
}
|
|
|
|
return new UserStatus(trimmed);
|
|
}
|
|
|
|
static fromString(value: string): UserStatus {
|
|
return this.create(value);
|
|
}
|
|
|
|
get props(): UserStatusProps {
|
|
return { value: this.value };
|
|
}
|
|
|
|
toString(): UserStatusValue {
|
|
return this.value;
|
|
}
|
|
|
|
equals(other: ValueObject<UserStatusProps>): boolean {
|
|
return this.value === other.props.value;
|
|
}
|
|
|
|
isActive(): boolean {
|
|
return this.value === 'active';
|
|
}
|
|
|
|
isSuspended(): boolean {
|
|
return this.value === 'suspended';
|
|
}
|
|
|
|
isDeleted(): boolean {
|
|
return this.value === 'deleted';
|
|
}
|
|
} |