Skip to content

Commit

Permalink
hotfix: convert properties (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciuscosmome authored Jan 26, 2024
1 parent 7cb2f54 commit 93d414e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
25 changes: 11 additions & 14 deletions src/modules/Task/task.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { TaskService } from './task.service';
import {
CreateTaskInput,
FindATaskControllerDto,
TarkIdDto,
FindTasksControllerDto,
UpdateTaskInput,
} from './task.dtos';
Expand Down Expand Up @@ -44,22 +44,22 @@ export class TaskController {

@ApiTags('Tasks')
@ApiBearerAuth()
@Put(':id')
@Put('/:id')
@UseGuards(RolesGuard)
@RequirePermissions([Permissions['302']])
async updateById(
@Param('id') id: number,
@Param() input: TarkIdDto,
@Body() updateTaskInput: UpdateTaskInput,
@Req() req: Request
) {
const cred = req[CREDENTIALS_KEY];

const accountId = await this.taskService.getAccountById(id);
const accountId = await this.taskService.getAccountById(input.id);

// Authorization
if (accountId != cred.accountId) throw new ForbiddenException();

const updatedTask = await this.taskService.updateById(id, {
const updatedTask = await this.taskService.updateById(input.id, {
...updateTaskInput,
accountId: cred.accountId,
});
Expand All @@ -69,19 +69,19 @@ export class TaskController {

@ApiTags('Tasks')
@ApiBearerAuth()
@Delete(':id')
@Delete('/:id')
@UseGuards(RolesGuard)
@RequirePermissions([Permissions['303']])
@HttpCode(200)
async deleteById(@Param('id') id: number, @Req() req: Request) {
async deleteById(@Param() input: TarkIdDto, @Req() req: Request) {
const cred = req[CREDENTIALS_KEY];

const accountId = await this.taskService.getAccountById(id);
const accountId = await this.taskService.getAccountById(input.id);

// Authorization
if (accountId != cred.accountId) throw new ForbiddenException();

await this.taskService.deleteById(id);
await this.taskService.deleteById(input.id);
return;
}

Expand All @@ -106,14 +106,11 @@ export class TaskController {

@ApiTags('Tasks')
@ApiBearerAuth()
@Get('/:taskId')
@Get('/:id')
@HttpCode(200)
@UseGuards(RolesGuard)
@RequirePermissions([Permissions['301']])
async getATaskInfo(
@Param() input: FindATaskControllerDto,
@Req() request: Request
) {
async getATaskInfo(@Param() input: TarkIdDto, @Req() request: Request) {
const { accountId } = request[CREDENTIALS_KEY];

return await this.taskService.findTaskByid({
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Task/task.dtos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class FindTasksControllerDto {
year: number;
}

export class FindATaskControllerDto {
export class TarkIdDto {
@ApiProperty()
@IsNotEmpty()
@Transform((params) => Number(params.value))
Expand Down
19 changes: 13 additions & 6 deletions src/modules/Task/task.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,20 @@ export class TaskRepository {
}

async findAccountByTaskId(id: number) {
const task = await this.prisma.task.findUnique({
where: {
id: id,
},
});
const accountId = await this.prisma.task
.findUnique({
where: {
id: id,
},
select: {
accountId: true,
},
})
.then((result) => {
return result?.accountId;
});

return task.accountId;
return accountId;
}

async findTasks(filters: FindTasksRepositoryInput['filters']) {
Expand Down

0 comments on commit 93d414e

Please sign in to comment.