admin area
This commit is contained in:
46
core/admin/domain/value-objects/Email.ts
Normal file
46
core/admin/domain/value-objects/Email.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { IValueObject } from '@core/shared/domain';
|
||||
import { AdminDomainValidationError } from '../errors/AdminDomainError';
|
||||
|
||||
export interface EmailProps {
|
||||
value: string;
|
||||
}
|
||||
|
||||
export class Email implements IValueObject<EmailProps> {
|
||||
readonly value: string;
|
||||
|
||||
private constructor(value: string) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
static create(value: string): Email {
|
||||
// Handle null/undefined
|
||||
if (value === null || value === undefined) {
|
||||
throw new AdminDomainValidationError('Email cannot be empty');
|
||||
}
|
||||
|
||||
const trimmed = value.trim();
|
||||
|
||||
if (!trimmed) {
|
||||
throw new AdminDomainValidationError('Email cannot be empty');
|
||||
}
|
||||
|
||||
// No format validation - accept any non-empty string
|
||||
return new Email(trimmed);
|
||||
}
|
||||
|
||||
static fromString(value: string): Email {
|
||||
return this.create(value);
|
||||
}
|
||||
|
||||
get props(): EmailProps {
|
||||
return { value: this.value };
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
equals(other: IValueObject<EmailProps>): boolean {
|
||||
return this.value === other.props.value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user