| Total Complexity | 2 |
| Total Lines | 22 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { Inject } from '@nestjs/common'; |
||
| 6 | |||
| 7 | @EventsHandler(SchoolCreatedEvent) |
||
| 8 | export class SchoolCreatedEventListener { |
||
| 9 | constructor( |
||
| 10 | @Inject('ICommandBus') |
||
| 11 | private readonly commandBus: ICommandBus, |
||
| 12 | @Inject('IProductRepository') |
||
| 13 | private readonly productRepository: IProductRepository |
||
| 14 | ) {} |
||
| 15 | |||
| 16 | public async handle({ schoolId }: SchoolCreatedEvent): Promise<void> { |
||
| 17 | const products = await this.productRepository.findProductsToImport(); |
||
| 18 | |||
| 19 | for (const product of products) { |
||
| 20 | const price = product.getPriceFromCents(); |
||
| 21 | |||
| 22 | await this.commandBus.execute( |
||
| 23 | new CreateSchoolProductCommand( |
||
| 24 | price, |
||
| 25 | price, |
||
| 26 | schoolId, |
||
| 27 | product.getId() |
||
| 28 | ) |
||
| 33 |