admin area
This commit is contained in:
59
core/admin/domain/value-objects/UserStatus.ts
Normal file
59
core/admin/domain/value-objects/UserStatus.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { IValueObject } from '@core/shared/domain';
|
||||
import { AdminDomainValidationError } from '../errors/AdminDomainError';
|
||||
|
||||
export type UserStatusValue = string;
|
||||
|
||||
export interface UserStatusProps {
|
||||
value: UserStatusValue;
|
||||
}
|
||||
|
||||
export class UserStatus implements IValueObject<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: IValueObject<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';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user