Complete the code to define a NestJS controller using the correct decorator.
import { [1] } from '@nestjs/common'; @[1]('cats') export class CatsController { // controller methods }
The @Controller decorator defines a controller class in NestJS.
Complete the code to create a GET route handler in a NestJS controller.
import { Controller, [1] } from '@nestjs/common'; @Controller('dogs') export class DogsController { @[1]() findAll() { return 'This action returns all dogs'; } }
The @Get() decorator defines a handler for HTTP GET requests.
Fix the error in the service class by adding the correct decorator.
import { [1] } from '@nestjs/common'; export class CatsService { getCats() { return ['cat1', 'cat2']; } }
The @Injectable decorator marks the class as a provider that can be injected.
Fill both blanks to define a NestJS module with a controller and a provider.
import { Module } from '@nestjs/common'; import { CatsController } from './cats.controller'; import { CatsService } from './cats.service'; @Module({ controllers: [[1]], providers: [[2]], }) export class CatsModule {}
The controllers array should include the controller class, and the providers array should include the service class.
Fill all three blanks to create a route handler that accepts a dynamic parameter and injects a service.
import { Controller, Get, Param, [1] } from '@nestjs/common'; import { [3] } from '@nestjs/common'; @[3]() export class CatsService { [2](id) { return 'Cat ' + id; } } @Controller('cats') export class CatsController { constructor(@[1]() private readonly catsService: CatsService) {} @Get(':id') getCat(@Param('id') id: string) { return this.catsService.[2](id); } }
@Inject is used to inject dependencies manually, findOne is a typical service method to get one item, and @Injectable decorates the service class.