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(j-s): Add a mergeCaseNumber field to case table #17507

Merged
merged 4 commits into from
Jan 16, 2025
Merged

Conversation

oddsson
Copy link
Member

@oddsson oddsson commented Jan 15, 2025

Add a mergeCaseNumber field to case table

Asana

What

Add a mergeCaseNumber field to case table

Why

This is step one in enabling merging a case with a case that is not in RVG.

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

Release Notes

  • New Features

    • Added ability to specify a merge case number for cases
    • Enhanced case management with new optional merge case tracking
  • Technical Improvements

    • Updated database schema to support merge case number
    • Expanded case data model across backend and frontend systems
    • Added validation and optional handling for merge case number
  • Data Model Updates

    • Introduced new optional mergeCaseNumber field in case-related data transfer objects and models

@oddsson oddsson requested a review from a team as a code owner January 15, 2025 13:01
Copy link
Contributor

coderabbitai bot commented Jan 15, 2025

Walkthrough

This pull request introduces a new optional field mergeCaseNumber across multiple components of the judicial system application. The changes span from the API input DTOs to the database migration, backend services, and frontend GraphQL schemas. The addition allows for storing and managing a case number associated with a merged case, enhancing the application's ability to track case consolidation and relationships between different legal cases.

Changes

File Path Change Summary
apps/judicial-system/api/src/app/modules/case/dto/updateCase.input.ts Added optional mergeCaseNumber field to UpdateCaseInput class
apps/judicial-system/api/src/app/modules/case/models/case.model.ts Added nullable mergeCaseNumber field to Case model
apps/judicial-system/backend/migrations/20250115095654-update-case.js Created migration to add merge_case_number column to case table
apps/judicial-system/backend/src/app/modules/case/case.service.ts Updated UpdateCase interface to include mergeCaseNumber
apps/judicial-system/backend/src/app/modules/case/dto/updateCase.dto.ts Added optional mergeCaseNumber to UpdateCaseDto with validation
apps/judicial-system/backend/src/app/modules/case/guards/rolesRules.ts Added mergeCaseNumber to districtCourtFields array
apps/judicial-system/backend/src/app/modules/case/models/case.model.ts Updated Case model with mergeCaseNumber and documentation
apps/judicial-system/web/src/components/FormProvider/case.graphql Added mergeCaseNumber to case query response
apps/judicial-system/web/src/utils/hooks/useCase/updateCase.graphql Added mergeCaseNumber to UpdateCase mutation

Possibly related PRs

Suggested Labels

automerge

Suggested Reviewers

  • gudjong

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 0

🧹 Nitpick comments (2)
apps/judicial-system/backend/src/app/modules/case/dto/updateCase.dto.ts (1)

535-539: Add length validation for consistency.

Other string fields in this DTO have @MaxLength validation. Consider adding it to this field as well.

Apply this diff:

   @IsOptional()
   @IsString()
+  @MaxLength(255)
   @ApiPropertyOptional({ type: String })
   readonly mergeCaseNumber?: string
apps/judicial-system/web/src/components/FormProvider/case.graphql (1)

393-393: Improve schema organization and documentation.

  1. Consider moving mergeCaseNumber near the existing merge-related fields (mergeCase and mergedCases) to maintain logical grouping.
  2. Add documentation comments to describe the purpose and usage of this field.
  3. Explicitly define the field type for better schema clarity.
    mergedCases {
      # ... existing fields ...
    }
+   """
+   The case number of another case that this case will be merged into.
+   """
+   mergeCaseNumber: String
    civilClaimants {
      # ... existing fields ...
    }
-   mergeCaseNumber
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8fbbf6b and d9797e0.

📒 Files selected for processing (9)
  • apps/judicial-system/api/src/app/modules/case/dto/updateCase.input.ts (1 hunks)
  • apps/judicial-system/api/src/app/modules/case/models/case.model.ts (1 hunks)
  • apps/judicial-system/backend/migrations/20250115095654-update-case.js (1 hunks)
  • apps/judicial-system/backend/src/app/modules/case/case.service.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/case/dto/updateCase.dto.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/case/guards/rolesRules.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/case/models/case.model.ts (1 hunks)
  • apps/judicial-system/web/src/components/FormProvider/case.graphql (1 hunks)
  • apps/judicial-system/web/src/utils/hooks/useCase/updateCase.graphql (1 hunks)
🧰 Additional context used
📓 Path-based instructions (9)
apps/judicial-system/api/src/app/modules/case/dto/updateCase.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."
apps/judicial-system/backend/src/app/modules/case/dto/updateCase.dto.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/judicial-system/api/src/app/modules/case/models/case.model.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/judicial-system/web/src/utils/hooks/useCase/updateCase.graphql (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/judicial-system/web/src/components/FormProvider/case.graphql (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/judicial-system/backend/migrations/20250115095654-update-case.js (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/judicial-system/backend/src/app/modules/case/case.service.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/judicial-system/backend/src/app/modules/case/guards/rolesRules.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/judicial-system/backend/src/app/modules/case/models/case.model.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."
📓 Learnings (4)
apps/judicial-system/api/src/app/modules/case/dto/updateCase.input.ts (1)
Learnt from: unakb
PR: island-is/island.is#15508
File: apps/judicial-system/api/src/app/modules/case/dto/updateCase.input.ts:505-508
Timestamp: 2024-11-12T15:15:26.274Z
Learning: Validation for `mergeCaseId` is performed consistently in the backend API, making additional validation in the DTO class redundant.
apps/judicial-system/backend/src/app/modules/case/dto/updateCase.dto.ts (2)
Learnt from: unakb
PR: island-is/island.is#15508
File: apps/judicial-system/api/src/app/modules/case/dto/updateCase.input.ts:505-508
Timestamp: 2024-11-12T15:15:11.835Z
Learning: Validation for `mergeCaseId` is performed consistently in the backend API, making additional validation in the DTO class redundant.
Learnt from: gudjong
PR: island-is/island.is#16924
File: apps/judicial-system/backend/src/app/modules/case/dto/updateCase.dto.ts:69-74
Timestamp: 2024-11-18T15:21:28.715Z
Learning: The `policeCaseNumbers` field in `UpdateCaseDto` in `apps/judicial-system/backend/src/app/modules/case/dto/updateCase.dto.ts` already includes the `@ArrayMinSize(1)` and `@MaxLength(255)` decorators for validation.
apps/judicial-system/backend/src/app/modules/case/case.service.ts (1)
Learnt from: unakb
PR: island-is/island.is#15508
File: apps/judicial-system/api/src/app/modules/case/dto/updateCase.input.ts:505-508
Timestamp: 2024-11-12T15:15:11.835Z
Learning: Validation for `mergeCaseId` is performed consistently in the backend API, making additional validation in the DTO class redundant.
apps/judicial-system/backend/src/app/modules/case/models/case.model.ts (1)
Learnt from: unakb
PR: island-is/island.is#15508
File: apps/judicial-system/api/src/app/modules/case/dto/updateCase.input.ts:505-508
Timestamp: 2024-11-12T15:15:26.274Z
Learning: Validation for `mergeCaseId` is performed consistently in the backend API, making additional validation in the DTO class redundant.
🔇 Additional comments (9)
apps/judicial-system/backend/migrations/20250115095654-update-case.js (1)

1-24: LGTM! Migration is well-structured and follows best practices.

The migration correctly:

  • Uses a transaction for atomicity
  • Makes the column nullable
  • Follows naming conventions
  • Provides rollback functionality
apps/judicial-system/backend/src/app/modules/case/guards/rolesRules.ts (1)

109-109: LGTM! Appropriate role-based access control.

The field is correctly added to districtCourtFields, restricting updates to district court roles.

apps/judicial-system/api/src/app/modules/case/dto/updateCase.input.ts (1)

510-514: LGTM! Field is properly defined with appropriate decorators.

The implementation follows the established patterns and aligns with the retrieved learning about validation being handled in the backend API.

apps/judicial-system/backend/src/app/modules/case/case.service.ts (1)

178-178: LGTM! The mergeCaseNumber field is properly added to the UpdateCase interface.

The field is correctly included in the list of properties that can be updated, maintaining alphabetical ordering.

apps/judicial-system/web/src/utils/hooks/useCase/updateCase.graphql (1)

227-227: LGTM! The mergeCaseNumber field is properly added to the GraphQL schema.

The field is correctly included in the UpdateCase mutation response, maintaining a logical grouping with other merge-related fields.

apps/judicial-system/web/src/components/FormProvider/case.graphql (1)

393-393: Verify relationship with existing merge functionality.

Please clarify:

  1. How does mergeCaseNumber relate to the existing mergeCase.courtCaseNumber? They seem to serve similar purposes.
  2. What is the difference between RVG and non-RVG case merging that necessitates this new field?
✅ Verification successful

The fields serve different purposes for RVG vs non-RVG case merging

The two fields are intentionally distinct:

  • mergeCase.courtCaseNumber is used for displaying information about cases merged within the RVG system
  • mergeCaseNumber is specifically added to enable merging with cases that exist outside the RVG system

This separation is appropriate since merging with external cases requires different handling than internal RVG case merges.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of existing merge-related fields to understand the current merge functionality
rg -A 5 "mergeCase.*courtCaseNumber|mergeCaseNumber" --type ts

Length of output: 4087


Script:

#!/bin/bash
# Search for merge implementation and RVG-specific code
echo "=== Searching for merge implementation ==="
ast-grep --pattern 'function $FUNC($_) {
  $$$
  merge$$$
  $$$
}'

echo -e "\n=== Searching for RVG-specific code ==="
rg "RVK|RVG" --type ts -B 2 -A 2

Length of output: 118498


Script:

#!/bin/bash
# Search for merge implementation and RVG vs non-RVG handling
echo "=== Searching for merge implementation ==="
ast-grep --pattern 'function $FUNC($_) {
  $$$
  merge$$$
  $$$
}'

echo -e "\n=== Searching for RVG vs non-RVG case handling ==="
rg "RVG|non-RVG" --type ts -A 3 -B 3

echo -e "\n=== Searching for mergeCase usage ==="
rg "mergeCase" --type ts -A 3 -B 3

Length of output: 108678

apps/judicial-system/api/src/app/modules/case/models/case.model.ts (1)

457-459: LGTM! The field implementation follows GraphQL model best practices.

The new mergeCaseNumber field is properly implemented with correct typing and decorators, maintaining consistency with the codebase patterns.

apps/judicial-system/backend/src/app/modules/case/models/case.model.ts (2)

1064-1066: LGTM! Documentation update is clear and consistent.

The updated documentation for mergedCases relation follows the established documentation style and clearly describes its purpose.


1071-1077: LGTM! Field implementation follows Sequelize model best practices.

The new mergeCaseNumber field is properly implemented with:

  • Clear documentation following the file's convention
  • Correct Sequelize decorators
  • Appropriate type and nullability settings

Copy link

codecov bot commented Jan 15, 2025

Codecov Report

Attention: Patch coverage is 33.33333% with 4 lines in your changes missing coverage. Please review.

Project coverage is 35.60%. Comparing base (58b89c1) to head (36dcd42).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...m/api/src/app/modules/case/dto/updateCase.input.ts 0.00% 2 Missing ⚠️
...stem/api/src/app/modules/case/models/case.model.ts 0.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #17507   +/-   ##
=======================================
  Coverage   35.60%   35.60%           
=======================================
  Files        7015     7015           
  Lines      150300   150303    +3     
  Branches    42936    42936           
=======================================
+ Hits        53519    53522    +3     
  Misses      96781    96781           
Flag Coverage Δ
judicial-system-api 20.11% <0.00%> (-0.03%) ⬇️
judicial-system-backend 55.80% <100.00%> (+<0.01%) ⬆️
judicial-system-formatters 78.43% <ø> (ø)
judicial-system-message 66.78% <ø> (ø)
judicial-system-message-handler 48.59% <ø> (ø)
judicial-system-scheduler 71.27% <ø> (ø)
judicial-system-types 41.78% <ø> (ø)
judicial-system-web 27.88% <ø> (ø)

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

Files with missing lines Coverage Δ
...ystem/backend/src/app/modules/case/case.service.ts 88.62% <ø> (ø)
...backend/src/app/modules/case/dto/updateCase.dto.ts 86.95% <100.00%> (+0.11%) ⬆️
.../backend/src/app/modules/case/guards/rolesRules.ts 40.84% <ø> (ø)
.../backend/src/app/modules/case/models/case.model.ts 72.86% <100.00%> (+0.13%) ⬆️
...m/api/src/app/modules/case/dto/updateCase.input.ts 0.00% <0.00%> (ø)
...stem/api/src/app/modules/case/models/case.model.ts 0.00% <0.00%> (ø)

... and 3 files with indirect coverage changes


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 58b89c1...36dcd42. Read the comment docs.

Copy link
Member

@thorhildurt thorhildurt left a comment

Choose a reason for hiding this comment

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

Nice! 🙏

@datadog-island-is
Copy link

datadog-island-is bot commented Jan 15, 2025

Datadog Report

All test runs 17dfa82 🔗

9 Total Test Services: 0 Failed, 9 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.03%), 11 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
judicial-system-api 0 0 0 61 0 7.11s 1 decreased (-0.03%) Link
judicial-system-backend 0 0 0 21357 0 23m 28.98s 1 no change Link
judicial-system-formatters 0 0 0 38 0 5.87s 1 no change Link
judicial-system-message 0 0 0 41 0 12.61s 1 no change Link
judicial-system-message-handler 0 0 0 4 0 4.02s 1 no change Link
judicial-system-scheduler 0 0 0 4 0 4.54s 1 no change Link
judicial-system-types 0 0 0 23 0 7.39s 1 no change Link
judicial-system-web 0 0 0 333 0 1m 10.66s 1 no change Link
judicial-system-xrd-api 0 0 0 6 0 5.21s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • judicial-system-api - jest 21.3% (-0.03%) - Details

@oddsson oddsson added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Jan 16, 2025
@kodiakhq kodiakhq bot merged commit 2db52d8 into main Jan 16, 2025
33 checks passed
@kodiakhq kodiakhq bot deleted the j-s/merge-outside branch January 16, 2025 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants