0
0
NestJSframework~10 mins

CRUD operations in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the necessary decorator for creating a controller in NestJS.

NestJS
import { [1] } from '@nestjs/common';

@Controller('items')
export class ItemsController {}
Drag options to blanks, or click blank then click option'
AController
BInjectable
CModule
DGet
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Injectable instead of @Controller
Importing a decorator not related to controllers
2fill in blank
medium

Complete the code to define a GET route handler method named 'findAll' in the controller.

NestJS
@Controller('items')
export class ItemsController {
  @[1]()
  findAll() {
    return 'This action returns all items';
  }
}
Drag options to blanks, or click blank then click option'
APost
BDelete
CPut
DGet
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Post instead of @Get
Forgetting the parentheses after the decorator
3fill in blank
hard

Fix the error in the method to accept an 'id' parameter from the URL path.

NestJS
@Get(':id')
findOne(@[1]('id') id: string) {
  return `This action returns item #${id}`;
}
Drag options to blanks, or click blank then click option'
ABody
BParam
CQuery
DHeaders
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Body instead of @Param
Using @Query for path parameters
4fill in blank
hard

Fill both blanks to create a POST method that accepts a data object from the request body and returns it.

NestJS
@Post()
create(@[1]() createItemDto: any) {
  return [2];
}
Drag options to blanks, or click blank then click option'
ABody
BcreateItemDto
CRequest
DResponse
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Request instead of @Body
Returning the wrong variable
5fill in blank
hard

Fill all three blanks to create a DELETE method that accepts an 'id' parameter and returns a confirmation string.

NestJS
@Delete(':id')
remove(@[1]('id') id: string) {
  return `Item with id ${id} has been [2]`;
}

// Use this method in the controller to handle deletion requests.
Drag options to blanks, or click blank then click option'
AParam
Bdeleted
Cremoved
DBody
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Body instead of @Param
Using 'deleted' instead of 'removed' in the message