Skip to content
Snippets Groups Projects
Commit 2fc46a05 authored by Ronnie Friman's avatar Ronnie Friman
Browse files

added delete-task path&service

parent 464925e2
No related branches found
No related tags found
3 merge requests!59Development to master,!36Development,!33Small fixes
import { Controller, Post, Body, UsePipes, Get, Param } from '@nestjs/common'; import {
Controller,
Post,
Body,
UsePipes,
Get,
Param,
Delete,
} from '@nestjs/common';
import { TaskService } from './task.service'; import { TaskService } from './task.service';
import { CreateTaskDTO, EditTaskDTO } from './task.dto'; import { CreateTaskDTO, EditTaskDTO, DeleteTaskDTO } from './task.dto';
import { Roles } from '../shared/guard.decorator'; import { Roles } from '../shared/guard.decorator';
import { ValidationPipe } from '../shared/validation.pipe'; import { ValidationPipe } from '../shared/validation.pipe';
import { User } from '../user/user.decorator'; import { User } from '../user/user.decorator';
...@@ -28,7 +36,16 @@ export class TaskController { ...@@ -28,7 +36,16 @@ export class TaskController {
return this.taskService.editTask(data); return this.taskService.editTask(data);
} }
// lists all the tasks for the game if user has game_person entry // 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 // :id is the id of the game
@Get('get-tasks/:id') @Get('get-tasks/:id')
@Roles('soldier', 'factionleader', 'admin') @Roles('soldier', 'factionleader', 'admin')
......
...@@ -3,7 +3,7 @@ import { Repository } from 'typeorm'; ...@@ -3,7 +3,7 @@ import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { TaskEntity } from './task.entity'; import { TaskEntity } from './task.entity';
import { CreateTaskDTO, EditTaskDTO } from './task.dto'; import { CreateTaskDTO, EditTaskDTO, DeleteTaskDTO } from './task.dto';
import { FactionEntity } from '../faction/faction.entity'; import { FactionEntity } from '../faction/faction.entity';
import { Game_PersonEntity } from '../game/game.entity'; import { Game_PersonEntity } from '../game/game.entity';
import { NotificationGateway } from '../notifications/notifications.gateway'; import { NotificationGateway } from '../notifications/notifications.gateway';
...@@ -69,6 +69,18 @@ export class TaskService { ...@@ -69,6 +69,18 @@ export class TaskService {
}; };
} }
async deleteTask(data: DeleteTaskDTO) {
const task = await this.taskRepository.findOne({ taskId: data.taskId });
if (task) {
await this.taskRepository.delete({ taskId: task.taskId });
return {
code: 200,
message: 'Task deleted',
};
}
throw new HttpException('Task not found', HttpStatus.BAD_REQUEST);
}
async fetchTasks(user, taskGame) { async fetchTasks(user, taskGame) {
const gamePerson = await this.gamePersonRepository.findOne({ const gamePerson = await this.gamePersonRepository.findOne({
where: { where: {
...@@ -95,6 +107,7 @@ export class TaskService { ...@@ -95,6 +107,7 @@ export class TaskService {
faction: null, faction: null,
}, },
], ],
order: { taskIsActive: 'DESC' },
}); });
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment