import { Controller, Post, Body, UsePipes, Get, Param, Delete, } from '@nestjs/common'; import { TaskService } from './task.service'; import { CreateTaskDTO, EditTaskDTO, DeleteTaskDTO } from './task.dto'; import { Roles } from '../shared/guard.decorator'; import { ValidationPipe } from '../shared/validation.pipe'; import { User } from '../user/user.decorator'; @Controller('task') export class TaskController { constructor(private taskService: TaskService) {} // creates a new task if the user has admin role in the game // :id is the id of the game @Post('new-task/:id') @Roles('admin') @UsePipes(new ValidationPipe()) async newTask(@Param('id') id: string, @Body() task: CreateTaskDTO) { return this.taskService.newTask(task); } // edits a created task if the user has admin role in the game // :id is the id of the game @Post('edit-task/:id') @Roles('admin') @UsePipes(new ValidationPipe()) async editTask(@Param('id') id: string, @Body() data: EditTaskDTO) { return this.taskService.editTask(data); } // deletes a created task if the user has admin role in the game // :id is the id of the game @Delete('delete-task/:id') @Roles('admin') @UsePipes(new ValidationPipe()) async deleteTask(@Param('id') id: string, @Body() data: DeleteTaskDTO) { return this.taskService.deleteTask(data); } // lists all the tasks for the game if the user has game_person entry // :id is the id of the game @Get('get-tasks/:id') @Roles('soldier', 'factionleader', 'admin') async fetchTasks(@User('id') person, @Param('id') id: string) { return this.taskService.fetchTasks(person, id); } }