Skip to content

Instantly share code, notes, and snippets.

@Vivek205
Last active October 4, 2022 11:35
Show Gist options
  • Save Vivek205/25e1dda1f8cfca64faf2c1cc8f301b05 to your computer and use it in GitHub Desktop.
Save Vivek205/25e1dda1f8cfca64faf2c1cc8f301b05 to your computer and use it in GitHub Desktop.
Task controller to map the service handlers for the http methods
import {
Body,
Controller,
Delete,
Get,
Param,
Patch,
Post,
Query,
} from '@nestjs/common';
import { CreateTaskDto } from './dto/create-task.dto';
import { FilterTasksDto } from './dto/filter-tasks.dto';
import { UpdateTaskStatusDto } from './dto/update-task-status.dto';
import { TasksService } from './tasks.service';
@Controller('tasks')
export class TasksController {
constructor(private tasksService: TasksService) {}
@Get()
getTasks(@Query() filterTasksDto: FilterTasksDto) {
return this.tasksService.getTasks(filterTasksDto);
}
@Get(':id')
getTask(@Param('id') id: string) {
return this.tasksService.getTaskById(id);
}
@Post()
createTask(@Body() createTaskDto: CreateTaskDto) {
return this.tasksService.createTask(createTaskDto);
}
@Patch(':id/status')
updateTaskStatus(
@Param('id') id: string,
@Body() updateTaskStatusDto: UpdateTaskStatusDto,
) {
return this.tasksService.updateTaskStatus(id, updateTaskStatusDto);
}
@Delete(':id')
deleteTask(@Param('id') id: string) {
return this.tasksService.deleteTask(id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment