matcher/src/modules/ad/domain/usecases/create-ad.usecase.ts

30 lines
902 B
TypeScript
Raw Normal View History

import { CommandHandler } from '@nestjs/cqrs';
import { CreateAdCommand } from '../../commands/create-ad.command';
import { Ad } from '../entities/ad';
import { AdRepository } from '../../adapters/secondaries/ad.repository';
2023-04-26 10:10:22 +00:00
import { InjectMapper } from '@automapper/nestjs';
import { Mapper } from '@automapper/core';
import { CreateAdRequest } from '../dtos/create-ad.request';
@CommandHandler(CreateAdCommand)
export class CreateAdUseCase {
2023-04-26 10:10:22 +00:00
constructor(
@InjectMapper() private readonly mapper: Mapper,
private readonly adRepository: AdRepository,
) {}
async execute(command: CreateAdCommand): Promise<Ad> {
try {
2023-04-26 10:10:22 +00:00
const adToCreate: Ad = this.mapper.map(
command.createAdRequest,
CreateAdRequest,
Ad,
);
return adToCreate;
// return await this.adRepository.createAd(adToCreate);
} catch (error) {
throw error;
}
}
}