0.0.14 • Published 1 year ago

@williamkoller/structure-as-common v0.0.14

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago
yarn add @williamkoller/structure-as-common
import { Module } from '@nestjs/common';
import { LoggerModule } from '@williamkoller/structure-as-common';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  imports: [LoggerModule.register()],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
import { Injectable } from '@nestjs/common';
import { LoggerService } from '@williamkoller/structure-as-common';

@Injectable()
export class AppService {
  constructor(private readonly logger: LoggerService) {}
  getHello(id: number): string {
    this.logger.log('AppService', `getHello: ${id}`);
    return `id: ${id}`;
  }
}
import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import {
  HttpExceptionFilter,
  LoggerService,
} from '@williamkoller/structure-as-common';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  app.useGlobalPipes(new ValidationPipe({ transform: true }));
  app.useGlobalFilters(new HttpExceptionFilter(new LoggerService()));

  await app.listen(3001);
}
bootstrap();
app.useGlobalInterceptors(new TimeoutInterceptor(), new LoggingInterceptor());
import { Controller, Get, Param, ParseIntPipe } from '@nestjs/common';
import { ValidationParamsPipe } from '@williamkoller/structure-as-common';
import { AppService } from './app.service';

@Controller('app')
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get('find-by-id/:id')
  getHello(
    @Param('id', ValidationParamsPipe, ParseIntPipe)
    id: number
  ): string {
    return this.appService.getHello(id);
  }
}
import { Module } from '@nestjs/common';
import {
  ExceptionModule,
  LoggerModule,
} from '@williamkoller/structure-as-common';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  imports: [LoggerModule.register(), ExceptionModule.register()],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
import { Injectable } from '@nestjs/common';
import {
  ExceptionService,
  LoggerService,
} from '@williamkoller/structure-as-common';

@Injectable()
export class AppService {
  constructor(
    private readonly logger: LoggerService,
    private readonly exception: ExceptionService
  ) {}
  getHello(id: number): string {
    this.logger.log('AppService', `getHello: ${id}`);

    if (id === 1) {
      this.exception.badRequestException({
        message: 'id cannot be one',
      });
    }

    return `id: ${id}`;
  }
}
{
  "statusCode": 400,
  "timestamp": "2023-03-03T14:51:09.486Z",
  "path": "/app/find-by-id/1",
  "message": "id cannot be one"
}

Made with 🖤 by williamkoller :wave:

0.0.14

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago