import { IQueryHandler , QueryHandler } from '@nestjs/cqrs' ; import { InjectRepository } from '@nestjs/typeorm' ; import { In , Repository } from 'typeorm' ; import { CertificationRequest , GetAllCertificationRequestsQuery , GetAllCertificationRequestsHandler as OriginalHandler } from '@energyweb/issuer-api' ; import { FullCertificationRequestDTO } from '../full-certification-request.dto' ; import { IrecCertificationRequest } from '../irec-certification-request.entity' ; @ QueryHandler ( GetAllCertificationRequestsQuery ) export class GetAllCertificationRequestsHandler extends OriginalHandler implements IQueryHandler < GetAllCertificationRequestsQuery > { constructor ( @ InjectRepository ( CertificationRequest ) readonly repository , @ InjectRepository ( IrecCertificationRequest ) readonly irecRepository ) { super ( repository ) ; } async execute ( { query } ) { const certificationRequests = await super . execute ( { query } ) ; const irecCertificationRequests = await this . irecRepository . find ( { certificationRequestId : In ( certificationRequests . map ( ( c ) => c . id ) ) } ) ; return certificationRequests . map ( ( certificationRequest ) => { const irecCertificationRequest = irecCertificationRequests . find ( ( cr ) => cr . certificationRequestId === certificationRequest . id ) ; return { ... certificationRequest , irecIssueRequestId : irecCertificationRequest ?. irecIssueRequestId , organizationId : irecCertificationRequest ?. organizationId , irecAssetId : irecCertificationRequest ?. irecAssetId , irecTradeAccountCode : irecCertificationRequest ?. irecTradeAccountCode } ; } ) ; } }