rating
This commit is contained in:
48
core/identity/domain/value-objects/RatingEventId.ts
Normal file
48
core/identity/domain/value-objects/RatingEventId.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import type { IValueObject } from '@core/shared/domain';
|
||||
import { IdentityDomainValidationError } from '../errors/IdentityDomainError';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
export interface RatingEventIdProps {
|
||||
value: string;
|
||||
}
|
||||
|
||||
export class RatingEventId implements IValueObject<RatingEventIdProps> {
|
||||
readonly value: string;
|
||||
|
||||
private constructor(value: string) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
static create(value: string): RatingEventId {
|
||||
if (!value || value.trim().length === 0) {
|
||||
throw new IdentityDomainValidationError('RatingEventId cannot be empty');
|
||||
}
|
||||
|
||||
const trimmed = value.trim();
|
||||
// Basic UUID v4 validation
|
||||
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||
if (!uuidRegex.test(trimmed)) {
|
||||
throw new IdentityDomainValidationError(
|
||||
`Invalid UUID format: ${value}`
|
||||
);
|
||||
}
|
||||
|
||||
return new RatingEventId(trimmed);
|
||||
}
|
||||
|
||||
static generate(): RatingEventId {
|
||||
return new RatingEventId(uuidv4());
|
||||
}
|
||||
|
||||
get props(): RatingEventIdProps {
|
||||
return { value: this.value };
|
||||
}
|
||||
|
||||
equals(other: IValueObject<RatingEventIdProps>): boolean {
|
||||
return this.value === other.props.value;
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user