Skip to content

Commit

Permalink
fix: arruma validação do id da task
Browse files Browse the repository at this point in the history
  • Loading branch information
lauanegcsilva committed Dec 5, 2023
1 parent 6ab0fb6 commit d3c5403
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
4 changes: 3 additions & 1 deletion src/globals/responses/exceptions/database.exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export class P2002Exception extends UnprocessableEntityException {

export class P2025Exception extends UnprocessableEntityException {
constructor(target: string) {
super(formatException(`O campo ${target} não pode ser acessado.`, target));
super(
formatException(`O campo ${target || ''} não pode ser acessado.`, target),
);
}
}
10 changes: 7 additions & 3 deletions src/modules/task/task.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Controller,
Get,
HttpCode,
ParseIntPipe,
Patch,
Post,
Query,
Expand All @@ -13,7 +12,12 @@ import {
import { ApiBearerAuth, ApiResponse, ApiTags } from '@nestjs/swagger';
import { responses } from 'src/globals/responses/docs';
import { TaskService } from './task.service';
import { TaskCreateDto, readTaskNewDto, UpdateTaskDto } from './task.dto';
import {
TaskCreateDto,
readTaskNewDto,
UpdateTaskDto,
ValidateIdTask,
} from './task.dto';
import { AuthorizationGuard, RequestToken } from 'src/guard';
import { iAuthTokenPayload } from '../account/account.entity';
import { sessionPayloadKey } from 'src/globals/constants';
Expand Down Expand Up @@ -83,7 +87,7 @@ export class TaskController {
@ApiResponse(responses.unprocessable)
@ApiResponse(responses.internalError)
async update(
@Query('id_task', ParseIntPipe) id_task: number,
@Query() { id_task }: ValidateIdTask,
@Body() updateTaskDto: UpdateTaskDto,
@Req() request: Request,
) {
Expand Down
9 changes: 9 additions & 0 deletions src/modules/task/task.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,12 @@ export class UpdateTaskDto extends PickType(TaskCreateDto, ['childrenId']) {
@IsOptional()
order?: number = 0;
}

export class ValidateIdTask {
@Transform((param) => Number(param.value))
@ApiProperty({ example: 1 })
@IsNotEmpty({ message: messages.notEmpty })
@IsNumber({}, { message: messages.number })
@IsInt({ message: messages.integer })
id_task: number;
}
30 changes: 16 additions & 14 deletions src/modules/task/task.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,22 @@ export class TaskRepository {
}

async updateTask(task: iTaskRepositoryUpadateInput) {
await this.prisma.task.update({
where: {
id: task.id,
children: {
parentId: task.parentId,
id: task.childrenId,
await this.prisma.task
.update({
where: {
id: task.id,
children: {
parentId: task.parentId,
id: task.childrenId,
},
},
},
data: {
shift: task.shift,
frequency: task.frequency,
order: task.order,
categoryId: task.categoryId,
},
});
data: {
shift: task.shift,
frequency: task.frequency,
order: task.order,
categoryId: task.categoryId,
},
})
.catch((error) => handleErrors(error));
}
}

0 comments on commit d3c5403

Please sign in to comment.