S SmartDocs
Serie: nest.js typescript 38 líneas · Actualizado 2026-02-03

app.controller.ts

nest.js/03-advanced/code/app.controller.ts

import { Controller, Get, UseInterceptors, CacheInterceptor } from '@nestjs/common';
import { AppService } from './app.service';
import { CurrentUser } from './common/decorators/current-user.decorator';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';

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

  @Get()
  @ApiOperation({ summary: 'Get hello message' })
  @ApiResponse({ status: 200, description: 'Returns hello message' })
  getHello(): string {
    return this.appService.getHello();
  }

  @Get('health')
  @ApiOperation({ summary: 'Health check' })
  getHealth() {
    return {
      status: 'ok',
      message: 'Server is running',
      timestamp: new Date().toISOString(),
    };
  }

  @Get('profile')
  @UseInterceptors(CacheInterceptor)
  @ApiOperation({ summary: 'Get current user profile' })
  getProfile(@CurrentUser() user: any) {
    return {
      message: 'User profile',
      user,
    };
  }
}

Artículos relacionados