From 8a4acca7b6551a2359f43357257e9c80d6c7ab45 Mon Sep 17 00:00:00 2001 From: samuel Date: Thu, 27 Jun 2024 14:04:45 +0200 Subject: [PATCH] CR --- apps/armory/src/main.ts | 14 +------------- apps/policy-engine/src/main.ts | 14 +------------- apps/vault/src/main.ts | 14 +------------- .../src/lib/module/{ => http}/http.module.ts | 0 packages/nestjs-shared/src/lib/module/index.ts | 5 +++-- .../src/lib/module/{ => logger}/logger.module.ts | 2 +- .../{ => module/logger}/service/logger.service.ts | 0 packages/nestjs-shared/src/lib/service/index.ts | 1 - packages/nestjs-shared/src/lib/util/index.ts | 1 + .../src/lib/util/with-custom-logger.util.ts | 14 ++++++++++++++ 10 files changed, 22 insertions(+), 43 deletions(-) rename packages/nestjs-shared/src/lib/module/{ => http}/http.module.ts (100%) rename packages/nestjs-shared/src/lib/module/{ => logger}/logger.module.ts (70%) rename packages/nestjs-shared/src/lib/{ => module/logger}/service/logger.service.ts (100%) create mode 100644 packages/nestjs-shared/src/lib/util/with-custom-logger.util.ts diff --git a/apps/armory/src/main.ts b/apps/armory/src/main.ts index d98752a40..b6afafcde 100644 --- a/apps/armory/src/main.ts +++ b/apps/armory/src/main.ts @@ -1,5 +1,5 @@ import { ConfigService } from '@narval/config-module' -import { LoggerService, withCors, withSwagger } from '@narval/nestjs-shared' +import { withCors, withCustomLogger, withSwagger } from '@narval/nestjs-shared' import { ClassSerializerInterceptor, INestApplication, Logger, ValidationPipe } from '@nestjs/common' import { NestFactory, Reflector } from '@nestjs/core' import { lastValueFrom, map, of, switchMap } from 'rxjs' @@ -10,18 +10,6 @@ import { ApplicationExceptionFilter } from './shared/filter/application-exceptio import { HttpExceptionFilter } from './shared/filter/http-exception.filter' import { ZodExceptionFilter } from './shared/filter/zod-exception.filter' -/** - * Adds Narval custom logger. - * - * @param app - The INestApplication instance. - * @returns The modified INestApplication instance. - */ -const withCustomLogger = (app: INestApplication): INestApplication => { - app.useLogger(app.get(LoggerService)) - - return app -} - /** * Adds global pipes to the application. * diff --git a/apps/policy-engine/src/main.ts b/apps/policy-engine/src/main.ts index 93642e53f..76be251fe 100644 --- a/apps/policy-engine/src/main.ts +++ b/apps/policy-engine/src/main.ts @@ -1,5 +1,5 @@ import { ConfigService } from '@narval/config-module' -import { LoggerService, withCors, withSwagger } from '@narval/nestjs-shared' +import { withCors, withCustomLogger, withSwagger } from '@narval/nestjs-shared' import { INestApplication, Logger, ValidationPipe } from '@nestjs/common' import { NestFactory } from '@nestjs/core' import { lastValueFrom, map, of, switchMap } from 'rxjs' @@ -9,18 +9,6 @@ import { PolicyEngineModule, ProvisionModule } from './policy-engine.module' import { ApplicationExceptionFilter } from './shared/filter/application-exception.filter' import { HttpExceptionFilter } from './shared/filter/http-exception.filter' -/** - * Adds Narval custom logger. - * - * @param app - The INestApplication instance. - * @returns The modified INestApplication instance. - */ -const withCustomLogger = (app: INestApplication): INestApplication => { - app.useLogger(app.get(LoggerService)) - - return app -} - /** * Adds global pipes to the application. * diff --git a/apps/vault/src/main.ts b/apps/vault/src/main.ts index 84dc930fd..f4f4bca8e 100644 --- a/apps/vault/src/main.ts +++ b/apps/vault/src/main.ts @@ -1,5 +1,5 @@ import { ConfigService } from '@narval/config-module' -import { LoggerService, withCors, withSwagger } from '@narval/nestjs-shared' +import { withCors, withCustomLogger, withSwagger } from '@narval/nestjs-shared' import { INestApplication, Logger, ValidationPipe } from '@nestjs/common' import { NestFactory } from '@nestjs/core' import { lastValueFrom, map, of, switchMap } from 'rxjs' @@ -7,18 +7,6 @@ import { Config } from './main.config' import { ADMIN_API_KEY_SECURITY, GNAP_SECURITY } from './main.constant' import { MainModule, ProvisionModule } from './main.module' -/** - * Adds Narval custom logger. - * - * @param app - The INestApplication instance. - * @returns The modified INestApplication instance. - */ -const withCustomLogger = (app: INestApplication): INestApplication => { - app.useLogger(app.get(LoggerService)) - - return app -} - /** * Adds global pipes to the application. * diff --git a/packages/nestjs-shared/src/lib/module/http.module.ts b/packages/nestjs-shared/src/lib/module/http/http.module.ts similarity index 100% rename from packages/nestjs-shared/src/lib/module/http.module.ts rename to packages/nestjs-shared/src/lib/module/http/http.module.ts diff --git a/packages/nestjs-shared/src/lib/module/index.ts b/packages/nestjs-shared/src/lib/module/index.ts index 4456b09cf..3ee88ffbf 100644 --- a/packages/nestjs-shared/src/lib/module/index.ts +++ b/packages/nestjs-shared/src/lib/module/index.ts @@ -1,2 +1,3 @@ -export * from './http.module' -export * from './logger.module' +export * from './http/http.module' +export * from './logger/logger.module' +export * from './logger/service/logger.service' diff --git a/packages/nestjs-shared/src/lib/module/logger.module.ts b/packages/nestjs-shared/src/lib/module/logger/logger.module.ts similarity index 70% rename from packages/nestjs-shared/src/lib/module/logger.module.ts rename to packages/nestjs-shared/src/lib/module/logger/logger.module.ts index 319915601..7f430ae8f 100644 --- a/packages/nestjs-shared/src/lib/module/logger.module.ts +++ b/packages/nestjs-shared/src/lib/module/logger/logger.module.ts @@ -1,5 +1,5 @@ import { Module } from '@nestjs/common' -import { LoggerService } from '../service/logger.service' +import { LoggerService } from './service/logger.service' @Module({ providers: [LoggerService], diff --git a/packages/nestjs-shared/src/lib/service/logger.service.ts b/packages/nestjs-shared/src/lib/module/logger/service/logger.service.ts similarity index 100% rename from packages/nestjs-shared/src/lib/service/logger.service.ts rename to packages/nestjs-shared/src/lib/module/logger/service/logger.service.ts diff --git a/packages/nestjs-shared/src/lib/service/index.ts b/packages/nestjs-shared/src/lib/service/index.ts index 1926b14cc..49fb6ada5 100644 --- a/packages/nestjs-shared/src/lib/service/index.ts +++ b/packages/nestjs-shared/src/lib/service/index.ts @@ -1,2 +1 @@ -export * from './logger.service' export * from './null-logger.service' diff --git a/packages/nestjs-shared/src/lib/util/index.ts b/packages/nestjs-shared/src/lib/util/index.ts index 9f2f040af..999897c47 100644 --- a/packages/nestjs-shared/src/lib/util/index.ts +++ b/packages/nestjs-shared/src/lib/util/index.ts @@ -1,4 +1,5 @@ export * as coerce from './coerce.util' export * as secret from './secret.util' export * from './with-cors.util' +export * from './with-custom-logger.util' export * from './with-swagger.util' diff --git a/packages/nestjs-shared/src/lib/util/with-custom-logger.util.ts b/packages/nestjs-shared/src/lib/util/with-custom-logger.util.ts new file mode 100644 index 000000000..c2b7aa014 --- /dev/null +++ b/packages/nestjs-shared/src/lib/util/with-custom-logger.util.ts @@ -0,0 +1,14 @@ +import { INestApplication } from '@nestjs/common' +import { LoggerService } from '../module/logger/service/logger.service' + +/** + * Adds custom logger. + * + * @param app - The INestApplication instance. + * @returns The modified INestApplication instance. + */ +export const withCustomLogger = (app: INestApplication): INestApplication => { + app.useLogger(app.get(LoggerService)) + + return app +}