Skip to content

Commit

Permalink
Restrict deleteTask
Browse files Browse the repository at this point in the history
  • Loading branch information
gbgabiola committed Oct 18, 2021
1 parent 71a3fc8 commit 6ae28ed
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/tasks/tasks.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export class TasksController {
}

@Delete('/:id')
deleteTask(@Param('id') id: string): Promise<void> {
return this.tasksService.deleteTask(id);
deleteTask(@Param('id') id: string, @GetUser() user: User): Promise<void> {
return this.tasksService.deleteTask(id, user);
}

@Patch('/:id/status')
Expand Down
8 changes: 3 additions & 5 deletions src/tasks/tasks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ export class TasksService {
}

async getTaskById(id: string, user: User): Promise<Task> {
const foundTask = await this.tasksRepository.findOne({
where: { id, user },
});
const foundTask = await this.tasksRepository.findOne({ id, user });

if (!foundTask) {
throw new NotFoundException(`Task with ID ${id} is not found.`);
Expand All @@ -33,8 +31,8 @@ export class TasksService {
return this.tasksRepository.createTask(createTaskDto, user);
}

async deleteTask(id: string): Promise<void> {
const result = await this.tasksRepository.delete(id);
async deleteTask(id: string, user: User): Promise<void> {
const result = await this.tasksRepository.delete({ id, user });
if (result.affected === 0) {
throw new NotFoundException(`Task with ID "${id}" is not found.`);
}
Expand Down

0 comments on commit 6ae28ed

Please sign in to comment.