diff --git a/src/app.module.ts b/src/app.module.ts index 33ea38e..20ec1ff 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,15 +1,11 @@ import { Module } from '@nestjs/common'; -import { ClientsModule } from '@nestjs/microservices'; + import { ConfigModule } from '@nestjs/config'; -import { TransformationsController } from './modules/transformations/transformations.controller'; + import { HealthController } from './modules/health/health.controller'; -import { TransformationsService } from './modules/transformations/transformations.service'; import { HealthService } from './modules/health/health.service'; -import { TransformationsClientService } from './clients/transformations/client.service'; - -import { TransformationsClientConfiguration } from './clients/transformations/client.config'; import { CatalogController } from './modules/catalog/catalog.controller'; import { CatalogService } from './modules/catalog/catalog.service'; import { getOauthSecrets } from './utils/OauthSecrets'; @@ -35,17 +31,14 @@ import { NetworkConfigModule } from './modules/network-config/network-config.mod import { InputsModule } from './modules/inputs/inputs.module'; import { OauthModule } from './modules/oauth/oauth.module'; import { PipelinesModule } from './modules/pipelines/pipelines.module'; - -const transformationClient = new TransformationsClientConfiguration(); +import { TransformationsModule } from './modules/transformations/transformations.module'; @Module({ - controllers: [TransformationsController, HealthController, CatalogController], + controllers: [HealthController, CatalogController], providers: [ DadosferaLogger, { provide: 'OAUTH_SECRETS', useValue: getOauthSecrets() }, - TransformationsService, HealthService, - TransformationsClientService, CatalogService, HubspotStrategy, FacebookStrategy, @@ -69,13 +62,7 @@ const transformationClient = new TransformationsClientConfiguration(); NetworkConfigModule, ConnectionTestModule, PipelinesModule, - - ClientsModule.register([ - { - name: 'TRANSFORMATIONS_PACKAGE', - ...transformationClient.config(), - }, - ]), + TransformationsModule, UsersModule, diff --git a/src/clients/pipelines/client.config.ts b/src/clients/pipelines/client.config.ts deleted file mode 100644 index 3f5b72d..0000000 --- a/src/clients/pipelines/client.config.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { ClientOptions, Transport } from '@nestjs/microservices'; -import { PipelinePackages, PipelineProtoFilePath } from 'protospack'; -import { credentials } from '@grpc/grpc-js'; - -export class PipelinesClientConfiguration { - config(): ClientOptions { - return { - transport: Transport.GRPC, - options: { - url: process.env.PIFACTORY_URL, - package: PipelinePackages, - credentials: process.env.LOCAL_ENV - ? undefined - : credentials.createSsl(), - protoPath: PipelineProtoFilePath, - loader: { - enums: String, - objects: true, - arrays: true, - }, - }, - }; - } -} diff --git a/src/clients/transformations/client.config.ts b/src/clients/transformations/client.config.ts deleted file mode 100644 index 26c52f1..0000000 --- a/src/clients/transformations/client.config.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { ClientOptions, Transport } from '@nestjs/microservices'; -import { - TransformationPackages, - TransformationProtoFilePath, -} from 'protospack'; -import { credentials } from '@grpc/grpc-js'; - -export class TransformationsClientConfiguration { - config(): ClientOptions { - return { - transport: Transport.GRPC, - options: { - url: process.env.INFACTORY_URL, - package: TransformationPackages, - credentials: credentials.createSsl(), - protoPath: TransformationProtoFilePath, - loader: { - enums: String, - objects: true, - arrays: true, - }, - }, - }; - } -} diff --git a/src/clients/transformations/client.service.ts b/src/modules/transformations/client.service.ts similarity index 96% rename from src/clients/transformations/client.service.ts rename to src/modules/transformations/client.service.ts index 8f70965..5cc86f9 100644 --- a/src/clients/transformations/client.service.ts +++ b/src/modules/transformations/client.service.ts @@ -7,6 +7,7 @@ import { objectSnakeToCamel, } from 'src/utils/CaseConverter'; import { ICreateTransformationsRequest, IIdRequest } from './interfaces'; +import { TransformationsClientConfiguration } from './transformations-client'; @Controller('transformation') export class TransformationsClientService implements OnModuleInit { @@ -15,7 +16,8 @@ export class TransformationsClientService implements OnModuleInit { constructor( @Inject(DadosferaLogger) dadosferaLogger: DadosferaLogger, - @Inject('TRANSFORMATIONS_PACKAGE') private readonly grpcClient: ClientGrpc, + @Inject(TransformationsClientConfiguration.name) + private readonly grpcClient: ClientGrpc, ) { this.logger = dadosferaLogger.logger; } diff --git a/src/clients/transformations/interfaces.d.ts b/src/modules/transformations/interfaces.d.ts similarity index 100% rename from src/clients/transformations/interfaces.d.ts rename to src/modules/transformations/interfaces.d.ts diff --git a/src/modules/transformations/transformations-client.ts b/src/modules/transformations/transformations-client.ts new file mode 100644 index 0000000..bb15b3e --- /dev/null +++ b/src/modules/transformations/transformations-client.ts @@ -0,0 +1,33 @@ +import { + ClientsProviderAsyncOptions, + GrpcOptions, + Transport, +} from '@nestjs/microservices'; +import { + TransformationPackages, + TransformationProtoFilePath, +} from 'protospack'; +import { credentials } from '@grpc/grpc-js'; + +export class TransformationsClientConfiguration { + public name = 'TransformationsClientConfiguration'; + private config: GrpcOptions = { + transport: Transport.GRPC, + options: { + url: process.env.INFACTORY_URL, + package: TransformationPackages, + credentials: credentials.createSsl(), + protoPath: TransformationProtoFilePath, + loader: { + enums: String, + objects: true, + arrays: true, + }, + }, + }; + + providerOptions: ClientsProviderAsyncOptions = { + name: this.name, + ...this.config, + }; +} diff --git a/src/modules/transformations/transformations.controller.ts b/src/modules/transformations/transformations.controller.ts index 1095aaf..fb84079 100644 --- a/src/modules/transformations/transformations.controller.ts +++ b/src/modules/transformations/transformations.controller.ts @@ -10,8 +10,8 @@ import { } from '@nestjs/common'; import { Payload } from '@nestjs/microservices'; import { ApiTags } from '@nestjs/swagger'; -import { TransformationsClientService } from 'src/clients/transformations/client.service'; -import { IIdRequest } from 'src/clients/transformations/interfaces'; +import { TransformationsClientService } from './client.service'; +import { IIdRequest } from './interfaces'; import { AuthenticateCondition } from 'src/authentication/authentication.decorator'; import { PERMISSIONS } from '../../authentication/permissions.enum'; import { TransformationsService } from './transformations.service'; diff --git a/src/modules/transformations/transformations.module.ts b/src/modules/transformations/transformations.module.ts new file mode 100644 index 0000000..3545fd4 --- /dev/null +++ b/src/modules/transformations/transformations.module.ts @@ -0,0 +1,22 @@ +import { Module } from '@nestjs/common'; +import { ClientsModule } from '@nestjs/microservices'; +import { DadosferaLogger } from '@dadosfera/dadosfera-logs'; + +import { TransformationsController } from './transformations.controller'; +import { TransformationsService } from './transformations.service'; + +import { TransformationsClientConfiguration } from './transformations-client'; +import { TransformationsClientService } from './client.service'; +const client = new TransformationsClientConfiguration(); + +@Module({ + imports: [ClientsModule.register([client.providerOptions])], + controllers: [TransformationsController], + providers: [ + TransformationsService, + TransformationsClientService, + DadosferaLogger, + ], + exports: [TransformationsService], +}) +export class TransformationsModule {} diff --git a/src/modules/transformations/transformations.service.ts b/src/modules/transformations/transformations.service.ts index 0672eb2..dca9d61 100644 --- a/src/modules/transformations/transformations.service.ts +++ b/src/modules/transformations/transformations.service.ts @@ -1,9 +1,6 @@ import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; -import { TransformationsClientService } from 'src/clients/transformations/client.service'; -import { - ICreateTransformationsRequest, - IIdRequest, -} from 'src/clients/transformations/interfaces'; +import { TransformationsClientService } from './client.service'; +import { ICreateTransformationsRequest, IIdRequest } from './interfaces'; import { trSnakeToCamel } from 'src/utils/CaseConverter'; @Injectable()