feat(shared): add shared module with domain primitives, infrastructure services, and utils

Domain primitives: BaseEntity, AggregateRoot, ValueObject, DomainEvent, Result<T,E>
Infrastructure: PrismaService, RedisService, LoggerService (pino), EventBusService
Utils: Vietnam phone validator/normalizer, VND currency formatter, Vietnamese slug generator
Includes 45 unit tests covering all domain primitives, validators, and formatters.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-08 00:07:27 +07:00
parent 83d55de65b
commit 1fb7bb39d2
30 changed files with 282 additions and 92 deletions

View File

@@ -0,0 +1,22 @@
import { Injectable } from '@nestjs/common';
import { type EventEmitter2 } from '@nestjs/event-emitter';
import { type DomainEvent } from '../domain/domain-event';
@Injectable()
export class EventBusService {
constructor(private readonly eventEmitter: EventEmitter2) {}
publish(event: DomainEvent): void {
this.eventEmitter.emit(event.eventName, event);
}
publishAll(events: DomainEvent[]): void {
for (const event of events) {
this.publish(event);
}
}
async publishAsync(event: DomainEvent): Promise<void> {
await this.eventEmitter.emitAsync(event.eventName, event);
}
}