refactor to adapters
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
import type { EmailValidationResult } from '../types/EmailAddress';
|
||||
import { validateEmail } from '../types/EmailAddress';
|
||||
import { UserId } from '../value-objects/UserId';
|
||||
import { PasswordHash } from '../value-objects/PasswordHash';
|
||||
import { StoredUser } from '../repositories/IUserRepository';
|
||||
|
||||
export interface UserProps {
|
||||
id: UserId;
|
||||
displayName: string;
|
||||
email?: string;
|
||||
passwordHash?: PasswordHash;
|
||||
iracingCustomerId?: string;
|
||||
primaryDriverId?: string;
|
||||
avatarUrl?: string;
|
||||
@@ -15,6 +18,7 @@ export class User {
|
||||
private readonly id: UserId;
|
||||
private displayName: string;
|
||||
private email: string | undefined;
|
||||
private passwordHash: PasswordHash | undefined;
|
||||
private iracingCustomerId: string | undefined;
|
||||
private primaryDriverId: string | undefined;
|
||||
private avatarUrl: string | undefined;
|
||||
@@ -47,6 +51,22 @@ export class User {
|
||||
return new User(props);
|
||||
}
|
||||
|
||||
public static fromStored(stored: StoredUser): User {
|
||||
const passwordHash = stored.passwordHash ? PasswordHash.fromHash(stored.passwordHash) : undefined;
|
||||
const userProps: any = {
|
||||
id: UserId.fromString(stored.id),
|
||||
displayName: stored.displayName,
|
||||
email: stored.email,
|
||||
};
|
||||
if (passwordHash) {
|
||||
userProps.passwordHash = passwordHash;
|
||||
}
|
||||
if (stored.primaryDriverId) {
|
||||
userProps.primaryDriverId = stored.primaryDriverId;
|
||||
}
|
||||
return new User(userProps);
|
||||
}
|
||||
|
||||
public getId(): UserId {
|
||||
return this.id;
|
||||
}
|
||||
@@ -59,6 +79,10 @@ export class User {
|
||||
return this.email;
|
||||
}
|
||||
|
||||
public getPasswordHash(): PasswordHash | undefined {
|
||||
return this.passwordHash;
|
||||
}
|
||||
|
||||
public getIracingCustomerId(): string | undefined {
|
||||
return this.iracingCustomerId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user