@@ -17,15 +17,21 @@ import { CreateNodeTrafficUsageHistoryCommand } from '@modules/nodes-traffic-usa
1717import { NodesTrafficUsageHistoryEntity } from '@modules/nodes-traffic-usage-history/entities/nodes-traffic-usage-history.entity' ;
1818import { GetConfigProfileByUuidQuery } from '@modules/config-profiles/queries/get-config-profile-by-uuid' ;
1919
20+ import { StartAllNodesByProfileQueueService } from '@queue/start-all-nodes-by-profile' ;
2021import { StartNodeQueueService } from '@queue/start-node/start-node.service' ;
2122import { StopNodeQueueService } from '@queue/stop-node/stop-node.service' ;
2223
24+ import {
25+ CreateNodeRequestDto ,
26+ ProfileModificationRequestDto ,
27+ ReorderNodeRequestDto ,
28+ UpdateNodeRequestDto ,
29+ } from './dtos' ;
2330import {
2431 BaseEventResponseModel ,
2532 DeleteNodeResponseModel ,
2633 RestartNodeResponseModel ,
2734} from './models' ;
28- import { CreateNodeRequestDto , ReorderNodeRequestDto , UpdateNodeRequestDto } from './dtos' ;
2935import { NodesRepository } from './repositories/nodes.repository' ;
3036import { NodesEntity } from './entities' ;
3137
@@ -37,6 +43,7 @@ export class NodesService {
3743 private readonly nodesRepository : NodesRepository ,
3844 private readonly eventEmitter : EventEmitter2 ,
3945 private readonly startAllNodesQueue : StartAllNodesQueueService ,
46+ private readonly startAllNodesByProfileQueueService : StartAllNodesByProfileQueueService ,
4047 private readonly startNodeQueue : StartNodeQueueService ,
4148 private readonly stopNodeQueue : StopNodeQueueService ,
4249 private readonly queryBus : QueryBus ,
@@ -541,4 +548,54 @@ export class NodesService {
541548 return { isOk : false , ...ERRORS . INTERNAL_SERVER_ERROR } ;
542549 }
543550 }
551+
552+ public async profileModification (
553+ body : ProfileModificationRequestDto ,
554+ ) : Promise < ICommandResponse < BaseEventResponseModel > > {
555+ try {
556+ const { uuids, configProfile } = body ;
557+
558+ const configProfileResponse = await this . queryBus . execute (
559+ new GetConfigProfileByUuidQuery ( configProfile . activeConfigProfileUuid ) ,
560+ ) ;
561+
562+ if ( ! configProfileResponse . isOk || ! configProfileResponse . response ) {
563+ return {
564+ isOk : false ,
565+ ...ERRORS . CONFIG_PROFILE_NOT_FOUND ,
566+ } ;
567+ }
568+
569+ const inbounds = configProfileResponse . response . inbounds ;
570+
571+ const allActiveInboundsExistInProfile = configProfile . activeInbounds . every (
572+ ( activeInboundUuid ) =>
573+ inbounds . some ( ( inbound ) => inbound . uuid === activeInboundUuid ) ,
574+ ) ;
575+
576+ if ( ! allActiveInboundsExistInProfile ) {
577+ return {
578+ isOk : false ,
579+ ...ERRORS . CONFIG_PROFILE_INBOUND_NOT_FOUND_IN_SPECIFIED_PROFILE ,
580+ } ;
581+ }
582+
583+ await this . nodesRepository . removeInboundsFromNodes ( uuids ) ;
584+
585+ await this . nodesRepository . addInboundsToNodes ( uuids , configProfile . activeInbounds ) ;
586+
587+ await this . startAllNodesByProfileQueueService . startAllNodesByProfile ( {
588+ profileUuid : configProfile . activeConfigProfileUuid ,
589+ emitter : 'bulkProfileModification' ,
590+ } ) ; // no need to restart all nodes
591+
592+ return {
593+ isOk : true ,
594+ response : new BaseEventResponseModel ( true ) ,
595+ } ;
596+ } catch ( error ) {
597+ this . logger . error ( error ) ;
598+ return { isOk : false , ...ERRORS . INTERNAL_SERVER_ERROR } ;
599+ }
600+ }
544601}
0 commit comments