|
| 1 | +import { Controller, Get, Param, ParseIntPipe, UseFilters, UseGuards, UseInterceptors } from '@nestjs/common'; |
| 2 | +import { flush } from '@sentry/nestjs'; |
| 3 | +import { AppService } from './app.service'; |
| 4 | +import { AsyncInterceptor } from './async-example.interceptor'; |
| 5 | +import { ExampleInterceptor1 } from './example-1.interceptor'; |
| 6 | +import { ExampleInterceptor2 } from './example-2.interceptor'; |
| 7 | +import { ExampleExceptionGlobalFilter } from './example-global-filter.exception'; |
| 8 | +import { ExampleExceptionLocalFilter } from './example-local-filter.exception'; |
| 9 | +import { ExampleLocalFilter } from './example-local.filter'; |
| 10 | +import { ExampleGuard } from './example.guard'; |
| 11 | + |
| 12 | +@Controller() |
| 13 | +@UseFilters(ExampleLocalFilter) |
| 14 | +export class AppController { |
| 15 | + constructor(private readonly appService: AppService) {} |
| 16 | + |
| 17 | + @Get('test-transaction') |
| 18 | + testTransaction() { |
| 19 | + return this.appService.testTransaction(); |
| 20 | + } |
| 21 | + |
| 22 | + @Get('test-middleware-instrumentation') |
| 23 | + testMiddlewareInstrumentation() { |
| 24 | + return this.appService.testSpan(); |
| 25 | + } |
| 26 | + |
| 27 | + @Get('test-guard-instrumentation') |
| 28 | + @UseGuards(ExampleGuard) |
| 29 | + testGuardInstrumentation() { |
| 30 | + return {}; |
| 31 | + } |
| 32 | + |
| 33 | + @Get('test-interceptor-instrumentation') |
| 34 | + @UseInterceptors(ExampleInterceptor1, ExampleInterceptor2) |
| 35 | + testInterceptorInstrumentation() { |
| 36 | + return this.appService.testSpan(); |
| 37 | + } |
| 38 | + |
| 39 | + @Get('test-async-interceptor-instrumentation') |
| 40 | + @UseInterceptors(AsyncInterceptor) |
| 41 | + testAsyncInterceptorInstrumentation() { |
| 42 | + return this.appService.testSpan(); |
| 43 | + } |
| 44 | + |
| 45 | + @Get('test-pipe-instrumentation/:id') |
| 46 | + testPipeInstrumentation(@Param('id', ParseIntPipe) id: number) { |
| 47 | + return { value: id }; |
| 48 | + } |
| 49 | + |
| 50 | + @Get('test-exception/:id') |
| 51 | + async testException(@Param('id') id: string) { |
| 52 | + return this.appService.testException(id); |
| 53 | + } |
| 54 | + |
| 55 | + @Get('test-expected-400-exception/:id') |
| 56 | + async testExpected400Exception(@Param('id') id: string) { |
| 57 | + return this.appService.testExpected400Exception(id); |
| 58 | + } |
| 59 | + |
| 60 | + @Get('test-expected-500-exception/:id') |
| 61 | + async testExpected500Exception(@Param('id') id: string) { |
| 62 | + return this.appService.testExpected500Exception(id); |
| 63 | + } |
| 64 | + |
| 65 | + @Get('test-expected-rpc-exception/:id') |
| 66 | + async testExpectedRpcException(@Param('id') id: string) { |
| 67 | + return this.appService.testExpectedRpcException(id); |
| 68 | + } |
| 69 | + |
| 70 | + @Get('test-span-decorator-async') |
| 71 | + async testSpanDecoratorAsync() { |
| 72 | + return { result: await this.appService.testSpanDecoratorAsync() }; |
| 73 | + } |
| 74 | + |
| 75 | + @Get('test-span-decorator-sync') |
| 76 | + async testSpanDecoratorSync() { |
| 77 | + return { result: await this.appService.testSpanDecoratorSync() }; |
| 78 | + } |
| 79 | + |
| 80 | + @Get('kill-test-cron/:job') |
| 81 | + async killTestCron(@Param('job') job: string) { |
| 82 | + this.appService.killTestCron(job); |
| 83 | + } |
| 84 | + |
| 85 | + @Get('flush') |
| 86 | + async flush() { |
| 87 | + await flush(); |
| 88 | + } |
| 89 | + |
| 90 | + @Get('example-exception-global-filter') |
| 91 | + async exampleExceptionGlobalFilter() { |
| 92 | + throw new ExampleExceptionGlobalFilter(); |
| 93 | + } |
| 94 | + |
| 95 | + @Get('example-exception-local-filter') |
| 96 | + async exampleExceptionLocalFilter() { |
| 97 | + throw new ExampleExceptionLocalFilter(); |
| 98 | + } |
| 99 | + |
| 100 | + @Get('test-service-use') |
| 101 | + testServiceWithUseMethod() { |
| 102 | + return this.appService.use(); |
| 103 | + } |
| 104 | + |
| 105 | + @Get('test-service-transform') |
| 106 | + testServiceWithTransform() { |
| 107 | + return this.appService.transform(); |
| 108 | + } |
| 109 | + |
| 110 | + @Get('test-service-intercept') |
| 111 | + testServiceWithIntercept() { |
| 112 | + return this.appService.intercept(); |
| 113 | + } |
| 114 | + |
| 115 | + @Get('test-service-canActivate') |
| 116 | + testServiceWithCanActivate() { |
| 117 | + return this.appService.canActivate(); |
| 118 | + } |
| 119 | + |
| 120 | + @Get('test-function-name') |
| 121 | + testFunctionName() { |
| 122 | + return this.appService.getFunctionName(); |
| 123 | + } |
| 124 | +} |
0 commit comments