@@ -3,6 +3,7 @@ import _ from 'lodash';
33
44import { Transactional } from '@nestjs-cls/transactional' ;
55import { Injectable , Logger } from '@nestjs/common' ;
6+ import { QueryBus } from '@nestjs/cqrs' ;
67
78import { ICommandResponse } from '@common/types/command-response.type' ;
89import { XRayConfig } from '@common/helpers/xray-config' ;
@@ -17,6 +18,7 @@ import { GetConfigProfilesResponseModel } from './models/get-config-profiles.res
1718import { ConfigProfileInboundEntity } from './entities/config-profile-inbound.entity' ;
1819import { ConfigProfileRepository } from './repositories/config-profile.repository' ;
1920import { ConfigProfileEntity } from './entities/config-profile.entity' ;
21+ import { GetSnippetsQuery } from './queries/get-snippets' ;
2022
2123@Injectable ( )
2224export class ConfigProfileService {
@@ -26,6 +28,7 @@ export class ConfigProfileService {
2628 private readonly configProfileRepository : ConfigProfileRepository ,
2729 private readonly startAllNodesByProfileQueueService : StartAllNodesByProfileQueueService ,
2830 private readonly stopNodeQueueService : StopNodeQueueService ,
31+ private readonly queryBus : QueryBus ,
2932 ) { }
3033
3134 public async getConfigProfiles ( ) : Promise < ICommandResponse < GetConfigProfilesResponseModel > > {
@@ -81,6 +84,51 @@ export class ConfigProfileService {
8184 }
8285 }
8386
87+ public async getComputedConfigProfileByUUID (
88+ uuid : string ,
89+ ) : Promise < ICommandResponse < GetConfigProfileByUuidResponseModel > > {
90+ try {
91+ const configProfile = await this . configProfileRepository . getConfigProfileByUUID ( uuid ) ;
92+
93+ if ( ! configProfile ) {
94+ return {
95+ isOk : false ,
96+ ...ERRORS . CONFIG_PROFILE_NOT_FOUND ,
97+ } ;
98+ }
99+
100+ const snippetsMap : Map < string , unknown > = new Map ( ) ;
101+ const snippetsResponse = await this . queryBus . execute ( new GetSnippetsQuery ( ) ) ;
102+
103+ if ( ! snippetsResponse . isOk || ! snippetsResponse . response ) {
104+ return {
105+ isOk : false ,
106+ ...ERRORS . INTERNAL_SERVER_ERROR ,
107+ } ;
108+ }
109+
110+ for ( const snippet of snippetsResponse . response ) {
111+ snippetsMap . set ( snippet . name , snippet . snippet ) ;
112+ }
113+
114+ const config = new XRayConfig ( configProfile . config as object ) ;
115+ config . replaceSnippets ( snippetsMap ) ;
116+
117+ configProfile . config = config . getSortedConfig ( ) ;
118+
119+ return {
120+ isOk : true ,
121+ response : new GetConfigProfileByUuidResponseModel ( configProfile ) ,
122+ } ;
123+ } catch ( error ) {
124+ this . logger . error ( error ) ;
125+ return {
126+ isOk : false ,
127+ ...ERRORS . GET_COMPUTED_CONFIG_PROFILE_BY_UUID_ERROR ,
128+ } ;
129+ }
130+ }
131+
84132 public async deleteConfigProfileByUUID (
85133 uuid : string ,
86134 ) : Promise < ICommandResponse < DeleteConfigProfileByUuidResponseModel > > {
0 commit comments