Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { Calculation } from '@amalia/core/models'; import { CalculationStatus } from '@amalia/core/types'; import { assert } from '@amalia/ext/typescript'; import { ResumeCalculationPayload, type TaskHandler } from '@amalia/kernel/queue/core'; import { CompaniesService } from '@amalia/tenants/companies/core'; import { TriggerStepUseCase } from '../usecases/trigger-step.use-case'; @Injectable() export class ResumeCalculationsHandler implements TaskHandler<ResumeCalculationPayload> { public constructor( private readonly companiesService: CompaniesService, @InjectRepository(Calculation) private readonly calculationRepository: Repository<Calculation>, private readonly triggerStepUseCase: TriggerStepUseCase, ) {} public async handle({ calculationId, companyId }: ResumeCalculationPayload) { const company = await this.companiesService.findById(companyId); const calculation = await this.calculationRepository.findOne({ where: { id: calculationId } }); assert(calculation, `Calculation ${calculationId} not found`); await this.calculationRepository.update({ id: calculationId }, { status: CalculationStatus.REFRESH }); await this.triggerStepUseCase.execute(company, calculation, 0); } } |