18 lines
545 B
TypeScript
18 lines
545 B
TypeScript
import { CommandHandler } from '@nestjs/cqrs';
|
|
import { CreateAdCommand } from '../../commands/create-ad.command';
|
|
import { Ad } from '../entities/ad';
|
|
import { AdRepository } from '../../adapters/secondaries/ad.repository';
|
|
|
|
@CommandHandler(CreateAdCommand)
|
|
export class CreateAdUseCase {
|
|
constructor(private readonly adRepository: AdRepository) {}
|
|
|
|
async execute(command: CreateAdCommand): Promise<Ad> {
|
|
try {
|
|
return await this.adRepository.createAd(command.createAdRequest);
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
}
|