import { Injectable , InternalServerErrorException , NotFoundException } from '@nestjs/common' ; import { CmsIntegration } from '../../integration/cms.integration' ; import { CMSTestDTO } from '../../dto/cms-test.dto' ; import { ChosenAlternativeEnum } from '../../dto/check-test.dto' ; import { PublisherService } from '../../../GameficationModule/service/publisher.service' ; @ Injectable ( ) export class TestV2Service { constructor ( private readonly cmsIntegration , private readonly publisherService ) { } public async getAll ( partId ) { const { data } = await this . cmsIntegration . getTestsByPartId ( partId ) ; return data ; } public async findById ( id ) { const errors = { 404 : ( ) => { throw new NotFoundException ( 'Course not found' ) ; } , } ; try { const { data } = await this . cmsIntegration . findTestById ( id ) ; return data ; } catch ( e ) { const error = errors [ e . response . status ] ; if ( ! error ) throw new InternalServerErrorException ( ) ; error ( ) ; } } public async checkTest ( id , chosenAlternative ) { const test = await this . findById ( id ) ; this . publisherService . emitCheckTestReward ( test , chosenAlternative ) ; return chosenAlternative === test . alternativa_certa . toUpperCase ( ) ; } }