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

fix(skilavottord): Handle null value in model year #16220

Merged
merged 5 commits into from
Oct 2, 2024

Conversation

birkirkristmunds
Copy link
Member

@birkirkristmunds birkirkristmunds commented Oct 1, 2024

TS-921

What

Handle null value in modelYear

Why

Samgöngustofa service is returning null value for the modelYear when getting owners vehicles.

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features

    • Introduced a nullable firstRegistrationDate field when creating vehicle inputs, allowing for more flexible data entry.
    • Added an optional modelYear property to the vehicle data structure for enhanced vehicle recycling applications.
  • Bug Fixes

    • Improved error handling and logging in vehicle creation and application submission processes to enhance reliability.
  • Refactor

    • Updated date handling to prevent default values when no valid date is provided, improving the accuracy of year extraction.

@birkirkristmunds birkirkristmunds requested a review from a team as a code owner October 1, 2024 11:05
Copy link
Contributor

coderabbitai bot commented Oct 1, 2024

Walkthrough

The pull request introduces several changes across multiple files, primarily focusing on enhancing input handling and error management. Key modifications include adding a null check in the getYear function, making the firstRegistrationDate field nullable in the CreateVehicleInput class, and updating the CarRecyclingService and CarRecyclingClientService classes to improve error handling and support for optional parameters like modelYear.

Changes

File Change Summary
apps/skilavottord/web/utils/dateUtils.ts Modified getYear function to return an empty string if dateTime is null or undefined, preventing a default return of 1970.
apps/skilavottord/ws/src/app/modules/vehicle/dto/createVehicle.input.ts Changed firstRegistrationDate from non-nullable to nullable, allowing it to be omitted in vehicle input creation.
libs/application/template-api-modules/src/lib/modules/templates/car-recycling/car-recycling.service.ts Updated createVehicle method to handle modelYear, enhanced error handling in sendApplication, and improved promise handling for vehicle processing.
libs/application/templates/car-recycling/src/shared/types.ts Added a new optional property modelYear of type number to the VehicleDto interface.
libs/clients/car-recycling/src/lib/carRecyclingClient.service.ts Changed firstRegistrationDate parameter in createVehicle method to nullable `Date

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • veronikasif

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
apps/skilavottord/web/utils/dateUtils.ts (1)

23-27: Approved with suggestions for improvement

The changes successfully address the PR objective of handling null values for model years. Good job on improving the robustness of the function. Here are some suggestions for further improvement:

  1. Consider updating the type annotation for better type safety:

    export const getYear = (dateTime: string | null | undefined): string => {
  2. Update the return type annotation to explicitly include the empty string:

    export const getYear = (dateTime: string | null | undefined): string => {
  3. You could simplify the conditional check using the nullish coalescing operator:

    export const getYear = (dateTime: string | null | undefined): string => {
      return dateTime ? format(new Date(dateTime), 'yyyy') : '';
    }

These changes will enhance type safety and make the function more concise while maintaining the desired behavior.

libs/clients/car-recycling/src/lib/carRecyclingClient.service.ts (1)

94-94: Approved: Improved error messages with a suggestion for consistency

The error messages have been corrected for grammar, enhancing clarity. The use of permno.slice(-3) in the error messages is a good practice for identifying the specific vehicle without exposing the full permit number.

For consistency, consider using a template literal for the error message on line 94, similar to line 99:

throw new Error(`Failed to create vehicle ${permno.slice(-3)}`)

This would make both error messages identical and easier to maintain.

Also applies to: 99-99

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9ef986b and bc2c473.

📒 Files selected for processing (5)
  • apps/skilavottord/web/utils/dateUtils.ts (1 hunks)
  • apps/skilavottord/ws/src/app/modules/vehicle/dto/createVehicle.input.ts (1 hunks)
  • libs/application/template-api-modules/src/lib/modules/templates/car-recycling/car-recycling.service.ts (1 hunks)
  • libs/application/templates/car-recycling/src/shared/types.ts (1 hunks)
  • libs/clients/car-recycling/src/lib/carRecyclingClient.service.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
apps/skilavottord/web/utils/dateUtils.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/skilavottord/ws/src/app/modules/vehicle/dto/createVehicle.input.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
libs/application/template-api-modules/src/lib/modules/templates/car-recycling/car-recycling.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/car-recycling/src/shared/types.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/clients/car-recycling/src/lib/carRecyclingClient.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments (6)
apps/skilavottord/ws/src/app/modules/vehicle/dto/createVehicle.input.ts (1)

17-18: LGTM: Nullable field aligns with PR objectives

The change to make firstRegistrationDate nullable aligns well with the PR objective of handling null values from the Samgöngustofa service. This modification improves the robustness of vehicle data handling as intended.

A few points to note:

  1. The use of TypeScript decorators (@Field) adheres to best practices for type safety in GraphQL schemas.
  2. The nullable option { nullable: true } is correctly applied, allowing the field to be omitted when creating a vehicle input.
  3. This change maintains type safety while adding flexibility, which is a good balance.

To ensure consistency, let's check if similar changes are needed in related files:

libs/application/templates/car-recycling/src/shared/types.ts (1)

9-9: Addition of modelYear property aligns with PR objectives and follows best practices.

The new modelYear property in the VehicleDto interface is a good addition that addresses the PR objective of handling null values for model years from the Samgöngustofa service. This change enhances the robustness of vehicle data handling.

Observations:

  1. The property is correctly typed as an optional number, which allows for null or undefined values.
  2. The change adheres to the coding guidelines for library files:
    • It maintains reusability across different NextJS apps.
    • It uses TypeScript for defining types.
    • The optional nature of the property supports effective tree-shaking.
  3. The impact on existing codebase should be minimal due to the property being optional.

To ensure this change doesn't introduce any breaking changes, let's verify its usage:

✅ Verification successful

[/run_scripts]


Verified Addition of modelYear Property

The addition of the modelYear property to the VehicleDto interface has been successfully verified across all usages. Since modelYear is optional, it does not introduce any breaking changes to the existing codebase. All instances where VehicleDto is used remain compatible with this addition.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of VehicleDto to ensure compatibility
rg --type typescript "VehicleDto" -C 5

Length of output: 73


Script:

#!/bin/bash
# Search for usages of VehicleDto in TypeScript files to ensure compatibility
rg "VehicleDto" --glob "*.ts" --glob "*.tsx" -C 5

Length of output: 25043

libs/clients/car-recycling/src/lib/carRecyclingClient.service.ts (2)

75-76: Approved: Improved flexibility for firstRegistrationDate parameter

The change from Date to Date | null for the firstRegistrationDate parameter enhances the method's flexibility. This modification aligns well with the PR objective of handling null values for the model year, making the component more reusable across different scenarios where the registration date might not be available.


Line range hint 1-132: Overall assessment: Changes align with coding guidelines and improve service robustness

The modifications to the CarRecyclingClientService align well with the coding guidelines for the libs directory:

  1. Reusability: The changes enhance the flexibility of the createVehicle method, making it more reusable across different NextJS apps that may or may not have the registration date available.

  2. TypeScript usage: The update to the firstRegistrationDate parameter type (Date | null) demonstrates effective use of TypeScript for defining props and types.

  3. Tree-shaking and bundling: The changes don't introduce any new imports or exports, maintaining the current tree-shaking and bundling effectiveness.

The error handling improvements and the ability to handle null registration dates enhance the overall robustness of the service. These changes successfully address the PR objective of handling null values for the model year returned by the Samgöngustofa service.

libs/application/template-api-modules/src/lib/modules/templates/car-recycling/car-recycling.service.ts (2)

45-45: Initialization of modelYear is appropriate

Setting modelYear to null ensures that it has a default value before conditional assignment.


64-64: Verify the createVehicle method accepts modelYear correctly

Please confirm that the createVehicle method in CarRecyclingClientService accepts modelYear as a parameter and that the data type matches the method's expectations.

Run the following script to verify the method signature:

Copy link

codecov bot commented Oct 1, 2024

Codecov Report

Attention: Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.

Project coverage is 36.96%. Comparing base (8b3808e) to head (b254573).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...s/templates/car-recycling/car-recycling.service.ts 0.00% 5 Missing ⚠️
...ar-recycling/src/lib/carRecyclingClient.service.ts 0.00% 2 Missing ⚠️
...src/app/modules/vehicle/dto/createVehicle.input.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16220      +/-   ##
==========================================
- Coverage   36.96%   36.96%   -0.01%     
==========================================
  Files        6779     6779              
  Lines      139875   139879       +4     
  Branches    39777    39778       +1     
==========================================
  Hits        51700    51700              
- Misses      88175    88179       +4     
Flag Coverage Δ
api 3.37% <ø> (ø)
application-system-api 41.66% <0.00%> (-0.01%) ⬇️
application-template-api-modules 24.40% <0.00%> (+<0.01%) ⬆️
application-templates-car-recycling 3.12% <ø> (ø)
application-ui-shell 21.29% <ø> (ø)
skilavottord-ws 24.24% <0.00%> (ø)
web 1.83% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...src/app/modules/vehicle/dto/createVehicle.input.ts 0.00% <0.00%> (ø)
...ar-recycling/src/lib/carRecyclingClient.service.ts 32.14% <0.00%> (ø)
...s/templates/car-recycling/car-recycling.service.ts 43.83% <0.00%> (-2.55%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8b3808e...b254573. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Oct 1, 2024

Datadog Report

All test runs 0c7fa94 🔗

6 Total Test Services: 0 Failed, 6 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.01%), 10 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 3.22s 1 no change Link
application-system-api 0 0 0 120 2 3m 0.52s 1 decreased (-0.01%) Link
application-template-api-modules 0 0 0 135 0 2m 7.42s 1 no change Link
application-ui-shell 0 0 0 74 0 36.91s 1 no change Link
skilavottord-ws 0 0 0 1 0 13.82s 1 no change Link
web 0 0 0 84 0 33.1s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • application-system-api - jest 37.08% (-0.01%) - Details

Copy link
Member

@veronikasif veronikasif left a comment

Choose a reason for hiding this comment

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

lgtm 🥇

@birkirkristmunds birkirkristmunds added the automerge Merge this PR as soon as all checks pass label Oct 2, 2024
@kodiakhq kodiakhq bot merged commit 0e45aa5 into main Oct 2, 2024
46 checks passed
@kodiakhq kodiakhq bot deleted the fix/skilavottord-handle-null-model-year branch October 2, 2024 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants