In this commit (lines 27, 28) for your UserMap.ts mapper, you are attempting to access the Result value from the ValueObjects when they might not necessarily have been created properly:
public static toDomain (raw: any): User {
const userEmailOrError = UserEmail.create(raw.user_email);
const userPasswordOrError = UserPassword.create(raw.user_password);
const userOrError = User.create({
email: userEmailOrError.getValue(),
password: userPasswordOrError.getValue(),
firstName: raw.first_name,
lastName: raw.last_name,
isEmailVerified: raw.is_email_verified,
username: raw.username
}, new UniqueEntityID(raw.base_user_id))
userOrError.isFailure ? console.log(userOrError.error) : '';
return userOrError.isSuccess ? userOrError.getValue() : null;
}
If either UserEmail.create(): Result<UserEmail> or UserPassword.create(): Result<UserPassword> fail, then you'll see the following error when you call getValue on the Result instance:
"Can't get the value of an error result. Use 'errorValue' instead."
I'm interested in your architecture, so I was wondering if this is something you intend to rectify, and if so, how you'll do it.
Might you combine the results, perhaps:
public static toDomain (raw: any): User {
const userEmailOrError = UserEmail.create(raw.user_email);
const userPasswordOrError = UserPassword.create(raw.user_password);
if (!Result.combine([userEmailOrError, userPasswordOrError])) return null;
const userOrError = User.create({
email: userEmailOrError.getValue(),
password: userPasswordOrError.getValue(),
firstName: raw.first_name,
lastName: raw.last_name,
isEmailVerified: raw.is_email_verified,
username: raw.username
}, new UniqueEntityID(raw.base_user_id))
userOrError.isFailure ? console.log(userOrError.error) : '';
return userOrError.isSuccess ? userOrError.getValue() : null;
}
Or, are you asserting that both value objects will never be erroneous because they are coming straight from the database where the integrity and validation of data are guaranteed?
Thank you.
In this commit (lines 27, 28) for your
UserMap.tsmapper, you are attempting to access the Result value from the ValueObjects when they might not necessarily have been created properly:If either
UserEmail.create(): Result<UserEmail>orUserPassword.create(): Result<UserPassword>fail, then you'll see the following error when you callgetValueon theResultinstance:"Can't get the value of an error result. Use 'errorValue' instead."
I'm interested in your architecture, so I was wondering if this is something you intend to rectify, and if so, how you'll do it.
Might you combine the results, perhaps:
Or, are you asserting that both value objects will never be erroneous because they are coming straight from the database where the integrity and validation of data are guaranteed?
Thank you.