refactor to adapters

This commit is contained in:
2025-12-15 18:34:20 +01:00
parent fc671482c8
commit c817d76092
145 changed files with 906 additions and 361 deletions

View File

@@ -0,0 +1,41 @@
import bcrypt from 'bcrypt';
import type { IValueObject } from '@gridpilot/shared/domain';
export interface PasswordHashProps {
value: string;
}
/**
* Value Object: PasswordHash
*
* Wraps a bcrypt-hashed password string and provides verification.
*/
export class PasswordHash implements IValueObject<PasswordHashProps> {
public readonly props: PasswordHashProps;
private constructor(value: string) {
this.props = { value };
}
static async create(plain: string): Promise<PasswordHash> {
const saltRounds = 12;
const hash = await bcrypt.hash(plain, saltRounds);
return new PasswordHash(hash);
}
static fromHash(hash: string): PasswordHash {
return new PasswordHash(hash);
}
get value(): string {
return this.props.value;
}
async verify(plain: string): Promise<boolean> {
return bcrypt.compare(plain, this.props.value);
}
equals(other: IValueObject<PasswordHashProps>): boolean {
return this.props.value === other.props.value;
}
}

View File

@@ -1,3 +1,4 @@
import { v4 as uuidv4 } from 'uuid';
import type { IValueObject } from '@gridpilot/shared/domain';
export interface UserIdProps {
@@ -14,6 +15,10 @@ export class UserId implements IValueObject<UserIdProps> {
this.props = { value };
}
public static create(): UserId {
return new UserId(uuidv4());
}
public static fromString(value: string): UserId {
return new UserId(value);
}