2025-05-02 21:43:51 +00:00
|
|
|
import { DomainEntity, EmailAddress } from "@/core/common/domain";
|
2025-05-09 10:45:32 +00:00
|
|
|
import { Result } from "@repo/rdx-utils";
|
2025-02-21 10:06:27 +00:00
|
|
|
import { HashPassword, Username } from "../value-objects";
|
2025-02-15 21:30:12 +00:00
|
|
|
|
|
|
|
|
export interface IRegisterDataProps {
|
|
|
|
|
username: Username;
|
|
|
|
|
email: EmailAddress;
|
|
|
|
|
hashPassword: HashPassword;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-16 19:30:20 +00:00
|
|
|
export interface IRegisterDataPrimitives {
|
|
|
|
|
username: string;
|
|
|
|
|
email: string;
|
|
|
|
|
plainPassword: string;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-15 21:30:12 +00:00
|
|
|
export interface IRegisterData {
|
|
|
|
|
username: Username;
|
|
|
|
|
email: EmailAddress;
|
|
|
|
|
hashPassword: HashPassword;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class RegisterData extends DomainEntity<IRegisterDataProps> implements IRegisterData {
|
|
|
|
|
static create(props: IRegisterDataProps): Result<RegisterData, Error> {
|
|
|
|
|
return Result.ok(new this(props));
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-16 19:30:20 +00:00
|
|
|
static createFromPrimitives(props: IRegisterDataPrimitives): Result<RegisterData, Error> {
|
2025-02-15 21:30:12 +00:00
|
|
|
const { username, email, plainPassword } = props;
|
|
|
|
|
|
|
|
|
|
const userNameOrError = Username.create(username);
|
|
|
|
|
const emailOrError = EmailAddress.create(email);
|
|
|
|
|
const hashPasswordOrError = HashPassword.createFromPlainText(plainPassword);
|
|
|
|
|
|
|
|
|
|
const result = Result.combine([userNameOrError, emailOrError, hashPasswordOrError]);
|
|
|
|
|
|
|
|
|
|
if (result.isFailure) {
|
|
|
|
|
return Result.fail(result.error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return RegisterData.create({
|
|
|
|
|
username: userNameOrError.data,
|
|
|
|
|
email: emailOrError.data,
|
|
|
|
|
hashPassword: hashPasswordOrError.data,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get username(): Username {
|
2025-02-20 18:55:24 +00:00
|
|
|
return this.props.username;
|
2025-02-15 21:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get email(): EmailAddress {
|
2025-02-20 18:55:24 +00:00
|
|
|
return this.props.email;
|
2025-02-15 21:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get hashPassword(): HashPassword {
|
2025-02-20 18:55:24 +00:00
|
|
|
return this.props.hashPassword;
|
2025-02-15 21:30:12 +00:00
|
|
|
}
|
|
|
|
|
}
|