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,
};
}
}
Related articles
app.controller.ts
app.controller.ts — typescript source code from the nest.js learning materials (nest.js/01-beginner/code/app.controller.ts).
Read article →app.module.ts
app.module.ts — typescript source code from the nest.js learning materials (nest.js/01-beginner/code/app.module.ts).
Read article →app.service.ts
app.service.ts — typescript source code from the nest.js learning materials (nest.js/01-beginner/code/app.service.ts).
Read article →main.ts
main.ts — typescript source code from the nest.js learning materials (nest.js/01-beginner/code/main.ts).
Read article →todos.controller.ts
todos.controller.ts — typescript source code from the nest.js learning materials (nest.js/01-beginner/code/todos/todos.controller.ts).
Read article →todos.module.ts
todos.module.ts — typescript source code from the nest.js learning materials (nest.js/01-beginner/code/todos/todos.module.ts).
Read article →