inmemory to postgres
This commit is contained in:
@@ -52,6 +52,37 @@ export class User {
|
||||
return new User(props);
|
||||
}
|
||||
|
||||
public static rehydrate(props: {
|
||||
id: string;
|
||||
displayName: string;
|
||||
email?: string;
|
||||
passwordHash?: PasswordHash;
|
||||
iracingCustomerId?: string;
|
||||
primaryDriverId?: string;
|
||||
avatarUrl?: string;
|
||||
}): User {
|
||||
const email =
|
||||
props.email !== undefined
|
||||
? (() => {
|
||||
const result: EmailValidationResult = validateEmail(props.email);
|
||||
if (!result.success) {
|
||||
throw new Error(result.error);
|
||||
}
|
||||
return result.email;
|
||||
})()
|
||||
: undefined;
|
||||
|
||||
return new User({
|
||||
id: UserId.fromString(props.id),
|
||||
displayName: props.displayName,
|
||||
...(email !== undefined ? { email } : {}),
|
||||
...(props.passwordHash !== undefined ? { passwordHash: props.passwordHash } : {}),
|
||||
...(props.iracingCustomerId !== undefined ? { iracingCustomerId: props.iracingCustomerId } : {}),
|
||||
...(props.primaryDriverId !== undefined ? { primaryDriverId: props.primaryDriverId } : {}),
|
||||
...(props.avatarUrl !== undefined ? { avatarUrl: props.avatarUrl } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
public static fromStored(stored: StoredUser): User {
|
||||
const passwordHash = stored.passwordHash
|
||||
? PasswordHash.fromHash(stored.passwordHash)
|
||||
|
||||
Reference in New Issue
Block a user