Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/backend validation #26

Merged
merged 3 commits into from
Nov 5, 2023
Merged

Feat/backend validation #26

merged 3 commits into from
Nov 5, 2023

Conversation

usatie
Copy link
Owner

@usatie usatie commented Nov 5, 2023

Prismaの公式チュートリアルPart2でやった内容を反映させました。
https://www.prisma.io/blog/nestjs-prisma-validation-7D056s1kOla1

こんな感じでレスポンスでvalidationの結果が返ってきます。
Screenshot 2023-11-05 at 19 17 24
Screenshot 2023-11-05 at 19 17 35

Summary by CodeRabbit

  • New Features
    • Introduced global validation for better data integrity.
  • Bug Fixes
    • Enhanced user data validation to ensure correct data format and prevent empty fields.
    • Updated user controller to handle numerical IDs, improving data consistency.

Copy link
Contributor

coderabbitai bot commented Nov 5, 2023

Walkthrough

The changes introduced in this commit primarily revolve around enhancing data validation and refining data types in the user module of a NestJS application. The updates include the implementation of global validation, addition of validation decorators to the CreateUserDto class, and modification of parameter types in the user.controller.ts file.

Changes

File Path Summary
backend/src/main.ts Enabled global validation using ValidationPipe from @nestjs/common.
backend/src/user/dto/.../create-user.dto.ts Added validation decorators to email, name, and password properties of CreateUserDto class.
backend/src/user/.../user.controller.ts Updated id parameter type to number in findOne, update, and remove functions.

Poem

🐇 Hopping through the code, making changes bold, 🍂

Validation now global, data integrity uphold. 🛡️

From string to number, the types take a leap, 🔄

In the autumn code garden, we sow what we reap. 🌾

Celebrating the season, with a carrot brew in hand, 🥕☕

We cheer for the updates, in coderabbit's land! 🎉🎈


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4aad149 and 811bfcf.
Files ignored due to filter (2)
  • backend/package.json
  • backend/yarn.lock
Files selected for processing (3)
  • backend/src/main.ts (1 hunks)
  • backend/src/user/dto/create-user.dto.ts (1 hunks)
  • backend/src/user/user.controller.ts (2 hunks)
Files skipped from review due to trivial changes (1)
  • backend/src/main.ts
Additional comments: 8
backend/src/user/dto/create-user.dto.ts (4)
  • 1-9: The import statements for the validation decorators and ApiPropertyOptional are correctly placed and imported from the right modules.

  • 12-21: The email property of the CreateUserDto class is correctly decorated with validation decorators to enforce email format, non-empty value, string type, and maximum length. The ApiProperty decorator is also correctly used to provide additional metadata for Swagger.

  • 23-31: The name property of the CreateUserDto class is correctly decorated with validation decorators to enforce string type, optional value, minimum length, and maximum length. The ApiPropertyOptional decorator is also correctly used to provide additional metadata for Swagger.

  • 33-38: The password property of the CreateUserDto class is correctly decorated with validation decorators to enforce non-empty value, string type, minimum length, and maximum length. The ApiProperty decorator is also correctly used to provide additional metadata for Swagger.

backend/src/user/user.controller.ts (4)
  • 6-10: The import of ParseIntPipe is correct and necessary for the changes in this file.

  • 39-44: The findOne function now correctly expects the id parameter to be of type number instead of string. The ParseIntPipe is correctly used to enforce this.

  • 46-50: The update function now correctly expects the id parameter to be of type number instead of string. The ParseIntPipe is correctly used to enforce this.

  • 52-56: The remove function now correctly expects the id parameter to be of type number instead of string. The ParseIntPipe is correctly used to enforce this.

Please ensure that all calls to these functions throughout the codebase have been updated to match the new signatures.

@usatie usatie merged commit 7f760e5 into main Nov 5, 2023
1 check passed
@usatie usatie deleted the feat/backend-validation branch November 5, 2023 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant