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

chore(j-s): Notifications to advocates in civil claims cases #16264

Merged
merged 40 commits into from
Oct 11, 2024

Conversation

oddsson
Copy link
Member

@oddsson oddsson commented Oct 3, 2024

Notifications to advocates in civil claims cases

Asana

What

Send notifications to lawyers and legal rights protectors in civil claim cases. The notifications are the same ones we send to defenders when they are assigned

Why

These advocates need these notifications.

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

    • Introduced a new notification type for advocate assignments, enhancing clarity in notifications.
    • Added support for different advocate types in email notifications, improving information conveyed.
    • Implemented a structured AdvocateType enum for better type safety in components.
  • Bug Fixes

    • Updated notification logic to ensure correct notifications are sent based on advocate roles.
  • Tests

    • Expanded test coverage for advocate assignment notifications, including scenarios for civil claimants.

Copy link
Contributor

coderabbitai bot commented Oct 3, 2024

Walkthrough

This pull request introduces multiple changes across the judicial system application, primarily focusing on updating the notification system to accommodate a new role designation for advocates. Key modifications include a migration script for updating the database enum values, adjustments to notification types and related logic in various services and components, and the introduction of a new AdvocateType enum. These changes enhance the specificity and clarity of notifications sent within the system.

Changes

File Path Change Summary
apps/judicial-system/backend/migrations/20241003213354-update-notification.js Introduces a migration script to update the type column of the notification table, adding 'ADVOCATE_ASSIGNED' and providing a rollback mechanism.
apps/judicial-system/backend/src/app/formatters/formatters.ts Adds AdvocateType to imports and updates formatDefenderAssignedEmailNotification to utilize advocateType in email formatting.
apps/judicial-system/backend/src/app/messages/notifications.ts Updates defenderAssignedEmail message ID and modifies the body to include advocateType, enhancing notification specificity.
apps/judicial-system/backend/src/app/modules/notification/internalNotification.service.ts Renames methods to reflect advocate assignments and updates logic to handle notifications for advocates, including civil claimants.
apps/judicial-system/backend/src/app/modules/notification/notification.service.ts Updates addNotificationMessagesToQueue method to replace NotificationType.DEFENDER_ASSIGNED with NotificationType.ADVOCATE_ASSIGNED.
apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAdvocateAssignedNotifications.spec.ts Renames notification type in tests and adds scenarios for civil claims involving advocates.
apps/judicial-system/web/src/components/Inputs/InputAdvocate.tsx Updates advocateType prop to use AdvocateType enum for improved type safety and modifies rendering logic accordingly.
apps/judicial-system/web/src/routes/Court/Indictments/Advocates/Advocates.tsx Changes notification type in handleNavigationTo function from NotificationType.DEFENDER_ASSIGNED to NotificationType.ADVOCATE_ASSIGNED.
libs/judicial-system/types/src/index.ts Updates export for Lawyer type to include AdvocateType, reflecting a shift in source module.
libs/judicial-system/types/src/lib/advocate.ts Introduces a new enum AdvocateType with values DEFENDER, LAWYER, and LEGAL_RIGHTS_PROTECTOR.
libs/judicial-system/types/src/lib/notification.ts Updates NotificationType enum by replacing DEFENDER_ASSIGNED with ADVOCATE_ASSIGNED.

Possibly related PRs

  • fix(j-s): Modified notifications for defenders #14844: Modifies notifications for defenders, specifically updating the logic for sending notifications related to the defender's assignment, which aligns with the changes in the main PR regarding the notification system.
  • fix(j-s): Notification typos #14936: This PR addresses notification messages related to completed cases, which may connect to the notification updates in the main PR as they both involve changes to how notifications are structured and sent.
  • fix(j-s): Merge Email #16011: Focuses on merging emails and includes changes to notification handling, which could be relevant to the changes in the main PR regarding notification types.
  • fix(j-s): Civil claimant view for courts #16171: Enhances the functionality for judges to input and edit information regarding civil claimant advocates, which aligns with the changes in the main PR that involve updating notifications related to advocate assignments.
  • fix(j-s): Indictment Cleanup #16286: Addresses indictment cleanup, which includes changes to notification handling related to indictment cases, potentially connecting to the changes in the main PR regarding notification types.
  • fix(j-s): Show verdict appeal date for defenders #16312: Adds a new field for the verdict appeal deadline for defendants, which may relate to the notification updates in the main PR regarding advocate assignments and their implications for defendants.

Suggested reviewers

  • unakb

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between aa96f55 and a3439ff.

📒 Files selected for processing (1)
  • apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx (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 (1)
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx (2)
Learnt from: gudjong
PR: island-is/island.is#15421
File: apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx:55-61
Timestamp: 2024-07-03T15:43:13.884Z
Learning: The `updateCase` method in the `apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx` file has its own error handling, and additional error handling in the `initialize` function is not necessary.
Learnt from: gudjong
PR: island-is/island.is#15421
File: apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx:55-61
Timestamp: 2024-10-08T15:39:04.351Z
Learning: The `updateCase` method in the `apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx` file has its own error handling, and additional error handling in the `initialize` function is not necessary.
🔇 Additional comments (3)
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Processing/Processing.tsx (3)

13-16: LGTM: Import statement updated correctly

The addition of AdvocateType to the import statement is appropriate and aligns with the PR objective of implementing notifications for advocates in civil claims cases.


602-603: LGTM: Improved type safety with AdvocateType enum

The use of the AdvocateType enum for the advocateType prop enhances type safety and code clarity. The ternary operator correctly assigns the advocate type based on civilClaimant.spokespersonIsLawyer.


Line range hint 1-703: Overall changes align with PR objective and coding guidelines

The changes in this file effectively implement the use of the AdvocateType enum for advocates in civil claims cases. The code adheres to NextJS best practices, uses TypeScript for type safety, and manages state efficiently. These modifications support the PR objective of implementing notifications for advocates in civil claims cases.


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

codecov bot commented Oct 3, 2024

Codecov Report

Attention: Patch coverage is 88.88889% with 5 lines in your changes missing coverage. Please review.

Project coverage is 36.75%. Comparing base (4309e6f) to head (740a16d).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ictments/Advocates/SelectCivilClaimantAdvocate.tsx 0.00% 2 Missing ⚠️
...s/Prosecutor/Indictments/Processing/Processing.tsx 0.00% 2 Missing ⚠️
...c/routes/Court/Indictments/Advocates/Advocates.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16264   +/-   ##
=======================================
  Coverage   36.74%   36.75%           
=======================================
  Files        6804     6804           
  Lines      140882   140934   +52     
  Branches    40124    40217   +93     
=======================================
+ Hits        51765    51798   +33     
- Misses      89117    89136   +19     
Flag Coverage Δ
air-discount-scheme-backend 54.04% <ø> (ø)
air-discount-scheme-web 0.00% <ø> (ø)
api 3.37% <ø> (ø)
api-catalogue-services 77.85% <ø> (ø)
api-domains-air-discount-scheme 36.90% <ø> (ø)
api-domains-assets 26.71% <ø> (ø)
api-domains-auth-admin 48.48% <ø> (ø)
api-domains-communications 39.90% <ø> (ø)
api-domains-criminal-record 47.96% <ø> (ø)
api-domains-driving-license 44.39% <ø> (ø)
api-domains-education 31.48% <ø> (ø)
api-domains-health-insurance 34.72% <ø> (ø)
api-domains-mortgage-certificate 34.92% <ø> (ø)
api-domains-payment-schedule 41.13% <ø> (ø)
application-api-files 57.97% <ø> (ø)
application-core 71.51% <ø> (ø)
application-system-api 41.44% <ø> (ø)
application-template-api-modules 27.97% <ø> (ø)
application-templates-accident-notification 29.29% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 26.35% <ø> (ø)
application-templates-driving-license 18.29% <ø> (ø)
application-templates-estate 12.31% <ø> (ø)
application-templates-example-payment 25.14% <ø> (ø)
application-templates-financial-aid 14.27% <ø> (ø)
application-templates-general-petition 23.43% <ø> (ø)
application-templates-health-insurance 26.41% <ø> (ø)
application-templates-inheritance-report 6.43% <ø> (ø)
application-templates-marriage-conditions 15.09% <ø> (ø)
application-templates-mortgage-certificate 43.75% <ø> (ø)
application-templates-parental-leave 29.97% <ø> (ø)
application-types 6.71% <ø> (ø)
application-ui-components 1.28% <ø> (ø)
application-ui-shell 21.27% <ø> (ø)
auth-admin-web 2.43% <ø> (ø)
auth-nest-tools 29.84% <ø> (ø)
auth-react 22.77% <ø> (ø)
auth-shared 75.00% <ø> (ø)
clients-charge-fjs-v2 24.11% <ø> (ø)
clients-driving-license 40.63% <ø> (ø)
clients-driving-license-book 43.77% <ø> (ø)
clients-financial-statements-inao 49.29% <ø> (ø)
clients-license-client 1.83% <ø> (ø)
clients-middlewares 72.79% <ø> (+0.08%) ⬆️
clients-regulations 42.76% <ø> (ø)
clients-rsk-company-registry 29.76% <ø> (ø)
clients-rsk-personal-tax-return 38.00% <ø> (ø)
clients-smartsolutions 12.77% <ø> (ø)
clients-syslumenn 49.42% <ø> (ø)
clients-zendesk 54.61% <ø> (ø)
cms 0.43% <ø> (ø)
cms-translations 39.03% <ø> (ø)
content-search-index-manager 95.65% <ø> (ø)
content-search-toolkit 8.16% <ø> (ø)
contentful-apps 5.57% <ø> (ø)
dokobit-signing 63.29% <ø> (ø)
download-service 44.20% <ø> (ø)
email-service 61.05% <ø> (ø)
feature-flags 91.04% <ø> (ø)
file-storage 53.59% <ø> (ø)
financial-aid-backend 56.39% <ø> (ø)
financial-aid-shared 19.03% <ø> (ø)
icelandic-names-registry-backend 53.97% <ø> (ø)
infra-nest-server 48.17% <ø> (ø)
infra-tracing 43.24% <ø> (ø)
island-ui-core 28.39% <ø> (ø)
judicial-system-api 18.39% <100.00%> (+0.10%) ⬆️
judicial-system-audit-trail 69.27% <ø> (ø)
judicial-system-backend 55.19% <100.00%> (+0.05%) ⬆️
judicial-system-formatters 80.00% <100.00%> (+0.09%) ⬆️
judicial-system-message 67.18% <ø> (ø)
judicial-system-message-handler 48.26% <ø> (ø)
judicial-system-scheduler 69.51% <100.00%> (+0.10%) ⬆️
judicial-system-types 47.12% <0.00%> (-0.33%) ⬇️
judicial-system-web 27.94% <0.00%> (ø)
license-api 42.66% <ø> (ø)
localization 10.15% <ø> (ø)
logging 48.43% <ø> (ø)
message-queue 68.50% <ø> (ø)
nest-audit 68.20% <ø> (ø)
nest-config 78.38% <ø> (ø)
nest-feature-flags 51.46% <ø> (ø)
nest-problem 45.85% <ø> (ø)
nest-sequelize 94.44% <ø> (ø)
nest-swagger 51.71% <ø> (ø)
nova-sms 62.65% <ø> (ø)
portals-admin-regulations-admin 1.85% <ø> (ø)
portals-core 16.15% <ø> (ø)
reference-backend 49.79% <ø> (ø)
regulations 16.78% <ø> (ø)
residence-history 85.00% <ø> (ø)
services-auth-admin-api 51.81% <ø> (-0.03%) ⬇️
services-auth-delegation-api 57.32% <ø> (ø)
services-auth-ids-api 51.41% <ø> (-0.01%) ⬇️
services-auth-personal-representative 45.12% <ø> (-0.04%) ⬇️
services-auth-personal-representative-public 41.27% <ø> (+0.01%) ⬆️
services-auth-public-api 48.91% <ø> (ø)
services-documents 60.58% <ø> (ø)
services-endorsements-api 54.18% <ø> (ø)
services-sessions 65.36% <ø> (ø)
services-university-gateway 48.30% <ø> (-0.09%) ⬇️
services-user-notification 47.04% <ø> (ø)
services-user-profile 62.17% <ø> (ø)
shared-components 27.65% <ø> (ø)
shared-form-fields 31.59% <ø> (ø)
shared-mocking 64.62% <ø> (ø)
shared-pii 92.85% <ø> (ø)
shared-problem 87.50% <ø> (ø)
shared-utils 27.90% <ø> (ø)
skilavottord-ws 24.24% <ø> (ø)
testing-e2e 66.66% <ø> (ø)
web 1.83% <ø> (ø)

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

Files with missing lines Coverage Δ
...al-system/backend/src/app/formatters/formatters.ts 97.57% <100.00%> (+0.06%) ⬆️
...udicial-system/backend/src/app/formatters/index.ts 100.00% <100.00%> (ø)
...l-system/backend/src/app/messages/notifications.ts 100.00% <ø> (ø)
.../src/app/modules/notification/guards/rolesRules.ts 100.00% <ø> (ø)
...dules/notification/internalNotification.service.ts 81.03% <100.00%> (+0.35%) ⬆️
...c/app/modules/notification/notification.service.ts 94.44% <100.00%> (ø)
...system/web/src/components/Inputs/InputAdvocate.tsx 0.69% <ø> (ø)
libs/judicial-system/types/src/index.ts 100.00% <100.00%> (ø)
libs/judicial-system/types/src/lib/advocate.ts 83.33% <100.00%> (ø)
libs/judicial-system/types/src/lib/notification.ts 100.00% <100.00%> (ø)
... and 3 more

... and 9 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 4309e6f...740a16d. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Oct 3, 2024

Datadog Report

All test runs daf3737 🔗

24 Total Test Services: 1 Failed, 23 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.38%), 6 increased, 37 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
judicial-system-backend 2 0 0 21213 0 18m 46.27s 1 increased (+0.03%) Link
air-discount-scheme-web 0 0 0 2 0 8.08s 1 no change Link
api 0 0 0 4 0 3.14s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 14.83s 1 no change Link
application-system-api 0 0 0 120 2 3m 0.66s 1 no change Link
application-template-api-modules 0 0 0 124 0 1m 49.93s 1 no change Link
auth-api-lib 0 0 0 20 0 31.6s 1 no change Link
judicial-system-api 0 0 0 57 0 6.2s 1 increased (+0.11%) Link
judicial-system-formatters 0 0 0 38 0 5.26s 1 increased (+0.06%) Link
judicial-system-message 0 0 0 32 0 10.86s 1 no change Link

❌ Failed Tests (2)

  • InternalNotificationController - Send defender assigned notifications when the case has civil claims and the advocate is a lawyer should send correct email - apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAdvocateAssignedNotifications.spec.ts - Details

    Expand for error
     expect(jest.fn()).toHaveBeenCalledWith(...expected)
     
     - Expected
     + Received
     
     @@ -1,18 +1,21 @@
       Object {
         "attachments": undefined,
     +   "cc": undefined,
         "from": Object {
     ...
    
  • InternalNotificationController - Send defender assigned notifications when the case has civil claims and the advocate is a legal rights protector should send correct email - apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAdvocateAssignedNotifications.spec.ts - Details

    Expand for error
     expect(jest.fn()).toHaveBeenCalledWith(...expected)
     
     - Expected
     + Received
     
     @@ -1,18 +1,21 @@
       Object {
         "attachments": undefined,
     +   "cc": undefined,
         "from": Object {
     ...
    

🔻 Code Coverage Decreases vs Default Branch (1)

  • judicial-system-types - jest 50.73% (-0.38%) - Details

@oddsson oddsson changed the title Change DEFENDER_ASSIGNED to ADVOCATE_ASSIGNED chore(j-s): Notifications to advocates in civil claims cases Oct 4, 2024
@oddsson oddsson marked this pull request as ready for review October 4, 2024 15:16
@oddsson oddsson requested a review from a team as a code owner October 4, 2024 15:16
@oddsson oddsson marked this pull request as draft October 4, 2024 15:17
@oddsson oddsson marked this pull request as ready for review October 7, 2024 13:35
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: 7

🧹 Outside diff range and nitpick comments (16)
libs/judicial-system/types/src/lib/advocate.ts (1)

45-49: LGTM! Consider adding JSDoc comments for better documentation.

The AdvocateType enum is a good addition that aligns with the PR objectives and provides type safety for different advocate roles. The naming convention and export are correct, allowing for reuse across different NextJS apps.

Consider adding JSDoc comments to describe the purpose of this enum and each of its values. This would enhance the self-documentation of the code. For example:

/**
 * Represents the different types of advocates in the judicial system.
 */
export enum AdvocateType {
  /** A defender appointed to represent the accused. */
  DEFENDER = 'DEFENDER',
  /** A lawyer representing a party in a civil case. */
  LAWYER = 'LAWYER',
  /** A legal professional protecting the rights of involved parties. */
  LEGAL_RIGHTS_PROTECTOR = 'LEGAL_RIGHTS_PROTECTOR',
}
apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendDefenderAssignedNotifications.spec.ts (1)

42-42: LGTM! Consider updating the test description for clarity.

The change from DEFENDER_ASSIGNED to ADVOCATE_ASSIGNED aligns with the PR objective of implementing notifications for advocates in civil claims cases. Good job on maintaining type safety with TypeScript.

Consider updating the test description to reflect the new notification type:

-describe('NotificationController - Send defender assigned notification', () => {
+describe('NotificationController - Send advocate assigned notification', () => {

This will make the test description more accurate and consistent with the new functionality.

apps/judicial-system/backend/migrations/20241003213354-update-notification.js (3)

1-3: Remove redundant 'use strict' directive

The 'use strict' directive is unnecessary in ES6 modules as they are automatically in strict mode.

Apply this diff to remove the redundant directive:

-'use strict'
 const replaceEnum = require('sequelize-replace-enum-postgres').default
🧰 Tools
🪛 Biome

[error] 1-1: Redundant use strict directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.

(lint/suspicious/noRedundantUseStrict)


5-33: Approve changes with a minor suggestion

The up method correctly implements the new 'ADVOCATE_ASSIGNED' enum value, aligning with the PR objective. The enum values are comprehensive and include all necessary notification types.

Consider enhancing the comment about transaction support for better clarity:

-    // replaceEnum does not support transactions
+    // Note: replaceEnum does not support transactions. Ensure the migration is run in isolation.

36-65: Approve rollback logic with a minor suggestion

The down method correctly reverts the changes, replacing 'ADVOCATE_ASSIGNED' with 'DEFENDER_ASSIGNED'. This ensures proper rollback functionality and maintains backwards compatibility.

As suggested for the up method, consider enhancing the comment about transaction support:

-    // replaceEnum does not support transactions
+    // Note: replaceEnum does not support transactions. Ensure the migration is run in isolation.
apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendCourtDateNotification.spec.ts (1)

85-85: LGTM! Consider adding a test for the original DEFENDER_ASSIGNED type.

The change from DEFENDER_ASSIGNED to ADVOCATE_ASSIGNED aligns well with the PR objectives of implementing notifications for advocates in civil claims cases. This update ensures that the test suite covers the new notification type.

To maintain comprehensive test coverage, consider adding a separate test case for the DEFENDER_ASSIGNED notification type if it's still in use elsewhere in the system. This would ensure both notification types are properly tested.

apps/judicial-system/backend/src/app/modules/notification/guards/rolesRules.ts (1)

53-53: LGTM: Consistent update across all district court roles

The addition of NotificationType.ADVOCATE_ASSIGNED for the District Court Assistant role completes the consistent update across all three district court roles (Judge, Registrar, and Assistant). This change ensures that all relevant roles can send advocate assignment notifications, fully aligning with the PR objective.

Consider adding a unit test to verify that all district court roles (Judge, Registrar, and Assistant) have the same notification types in their dtoFieldValues arrays. This will help catch any future inconsistencies if one role is updated but others are missed.

apps/judicial-system/backend/src/app/modules/notification/notification.service.ts (3)

Line range hint 65-69: LGTM! Consider adding a comment for clarity.

The change from NotificationType.DEFENDER_ASSIGNED to NotificationType.ADVOCATE_ASSIGNED is correct and aligns with the PR objectives. This ensures that advocates receive notifications when assigned to a case, similar to defenders.

Consider adding a brief comment explaining why we're sending an ADVOCATE_ASSIGNED notification in the COURT_DATE case when eventOnly is true. This would improve code readability and maintainability.

 if (eventOnly) {
   this.eventService.postEvent('SCHEDULE_COURT_DATE', theCase, true)

+  // Send an advocate assignment notification even when not sending a calendar invitation
   messages = [
     this.getNotificationMessage(
       NotificationType.ADVOCATE_ASSIGNED,
       user,
       theCase,
     ),
   ]
 } else {

75-78: LGTM! Consider grouping related notification types.

The addition of NotificationType.ADVOCATE_ASSIGNED to this case block is correct and aligns with the PR objectives. This ensures that advocate assignment notifications are processed consistently with other notification types.

For better code organization and readability, consider grouping related notification types together. For example:

-case NotificationType.HEADS_UP:
-case NotificationType.ADVOCATE_ASSIGNED:
-case NotificationType.APPEAL_JUDGES_ASSIGNED:
-case NotificationType.APPEAL_CASE_FILES_UPDATED:
+// Assignment notifications
+case NotificationType.ADVOCATE_ASSIGNED:
+case NotificationType.APPEAL_JUDGES_ASSIGNED:
+// Update notifications
+case NotificationType.HEADS_UP:
+case NotificationType.APPEAL_CASE_FILES_UPDATED:

This grouping can make it easier to understand the different categories of notifications at a glance.


Line range hint 1-92: Overall, the changes look good and align with the PR objectives.

The modifications to the NotificationService class successfully implement notifications for advocates in civil claims cases. The changes are consistent with the existing code structure and maintain proper error handling.

To further improve the code, consider the following suggestion:

  1. Extract the notification type mapping logic into a separate method or configuration object. This would make it easier to add or modify notification types in the future without changing the main switch statement. For example:
private getNotificationConfig(type: NotificationType): { eventOnly: boolean, messages: Message[] } {
  // Define configuration for each notification type
  // Return the appropriate configuration
}

// In addNotificationMessagesToQueue
const config = this.getNotificationConfig(type);
if (config.eventOnly) {
  this.eventService.postEvent('SCHEDULE_COURT_DATE', theCase, true);
}
messages = config.messages;

This refactoring would improve the maintainability and scalability of the notification system.

apps/judicial-system/web/src/routes/Court/Indictments/Advocates/Advocates.tsx (1)

36-36: Approved: Notification type updated correctly.

The change from NotificationType.DEFENDER_ASSIGNED to NotificationType.ADVOCATE_ASSIGNED aligns with the PR objective of implementing notifications for advocates in civil claims cases. This update ensures that the correct notification type is sent when an advocate is assigned.

To improve clarity, consider adding a comment explaining the reason for this change:

// Use ADVOCATE_ASSIGNED notification type to cover both defenders and civil claimant advocates
await sendNotification(workingCase.id, NotificationType.ADVOCATE_ASSIGNED)

This comment would help future developers understand the broader context of this notification type.

apps/judicial-system/web/src/components/Inputs/InputAdvocate.tsx (2)

42-42: LGTM: Prop type updated to use AdvocateType enum

The change to use the AdvocateType enum for the advocateType prop improves type safety and clarity. This aligns well with TypeScript best practices.

Consider adding a default value for the advocateType prop in the component's declaration to improve its usability:

const InputAdvocate: FC<Props> = ({
  // ... other props
  advocateType = AdvocateType.DEFENDER,
  // ... rest of the component
}) => {
  // ...
}

Line range hint 1-497: Summary: InputAdvocate component successfully updated to use AdvocateType enum

The changes to the InputAdvocate component have successfully integrated the new AdvocateType enum, improving type safety and code clarity. These updates include:

  1. Importing the AdvocateType enum
  2. Updating the advocateType prop type
  3. Modifying label rendering logic to use the enum

These changes align well with NextJS and TypeScript best practices, and indirectly support the PR objective of updating notifications for advocates in civil claims cases by improving the robustness of the advocate input component.

Consider reviewing other components that may interact with this one to ensure consistent use of the AdvocateType enum throughout the application. This will help maintain the improved type safety across the entire codebase.

apps/judicial-system/backend/src/app/formatters/formatters.ts (1)

Line range hint 674-683: Approve changes with a minor suggestion

The addition of the advocateType parameter to the formatDefenderAssignedEmailNotification function allows for more specific email notifications based on the type of advocate. This change aligns well with the PR objectives of implementing notifications for lawyers and legal rights protectors in civil claim cases.

However, I suggest adding a type annotation for the advocateType parameter to improve type safety and code clarity.

Consider adding a type annotation to the advocateType parameter:

 export const formatDefenderAssignedEmailNotification = (
   formatMessage: FormatMessage,
   theCase: Case,
-  advocateType: AdvocateType,
+  advocateType: AdvocateType,
   overviewUrl?: string,
 ): SubjectAndBody => {
apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAdvocateAssignedNotifications.spec.ts (1)

Line range hint 301-312: Ensure defendant is defined before use

In the it('should record notification', () => { ... }) block, ensure that the defendant variable is defined in the test scope before being used in the expectations to prevent reference errors.

If defendant is defined in an outer scope or a beforeEach block, consider declaring it within the test scope or ensuring it's accessible where needed.

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

Line range hint 1547-1552: Incorrect Email Parameter in Notification Check

In the shouldSendAdvocateAssignedNotification method, when checking if the advocate has already been notified, the code uses theCase.defenderEmail instead of the advocateEmail parameter. This could lead to incorrect behavior if the advocate's email differs from the defender's email. To ensure the correct advocate is checked, you should use advocateEmail in the hasReceivedNotification call.

Apply this diff to fix the issue:

          const hasDefenderBeenNotified = this.hasReceivedNotification(
            [
              NotificationType.READY_FOR_COURT,
              NotificationType.COURT_DATE,
              NotificationType.ADVOCATE_ASSIGNED,
            ],
-           theCase.defenderEmail,
+           advocateEmail,
            theCase.notifications,
          )

          if (hasDefenderBeenNotified) {
            return false
          }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b1623cc and d0e3d38.

📒 Files selected for processing (14)
  • apps/judicial-system/backend/migrations/20241003213354-update-notification.js (1 hunks)
  • apps/judicial-system/backend/src/app/formatters/formatters.ts (3 hunks)
  • apps/judicial-system/backend/src/app/messages/notifications.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/guards/rolesRules.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/internalNotification.service.ts (8 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/notification.service.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAdvocateAssignedNotifications.spec.ts (11 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendCourtDateNotification.spec.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendDefenderAssignedNotifications.spec.ts (2 hunks)
  • apps/judicial-system/web/src/components/Inputs/InputAdvocate.tsx (5 hunks)
  • apps/judicial-system/web/src/routes/Court/Indictments/Advocates/Advocates.tsx (1 hunks)
  • libs/judicial-system/types/src/index.ts (1 hunks)
  • libs/judicial-system/types/src/lib/advocate.ts (1 hunks)
  • libs/judicial-system/types/src/lib/notification.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (14)
apps/judicial-system/backend/migrations/20241003213354-update-notification.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/formatters/formatters.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/messages/notifications.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/notification/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/notification/internalNotification.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/notification/notification.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/notification/test/internalNotificationController/sendAdvocateAssignedNotifications.spec.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/notification/test/notificationController/sendCourtDateNotification.spec.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/notification/test/notificationController/sendDefenderAssignedNotifications.spec.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/components/Inputs/InputAdvocate.tsx (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/routes/Court/Indictments/Advocates/Advocates.tsx (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/judicial-system/types/src/index.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/judicial-system/types/src/lib/advocate.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/judicial-system/types/src/lib/notification.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."
🪛 Biome
apps/judicial-system/backend/migrations/20241003213354-update-notification.js

[error] 1-1: Redundant use strict directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.

(lint/suspicious/noRedundantUseStrict)

🔇 Additional comments (14)
libs/judicial-system/types/src/lib/advocate.ts (1)

Line range hint 1-64: Great job on maintaining code quality and following guidelines!

The file structure and content adhere well to the coding guidelines for the libs directory:

  1. The types and utility function are reusable across different NextJS apps.
  2. TypeScript is effectively used for defining props and exporting types.
  3. The exported entities support effective tree-shaking and bundling.

The addition of the AdvocateType enum enhances the type system without breaking existing code, and the overall file structure remains clean and logical.

apps/judicial-system/backend/src/app/modules/notification/test/notificationController/sendDefenderAssignedNotifications.spec.ts (1)

64-64: LGTM! Verify consistency across the codebase.

The change from DEFENDER_ASSIGNED to ADVOCATE_ASSIGNED in the message body is consistent with the previous modification and aligns with the PR objective.

To ensure consistency across the codebase, let's verify that all occurrences of DEFENDER_ASSIGNED have been updated to ADVOCATE_ASSIGNED where appropriate:

This will help identify any places where the notification type might have been missed during the update.

✅ Verification successful

Verified! All instances of DEFENDER_ASSIGNED have been successfully updated to ADVOCATE_ASSIGNED.

The shell script results show that there are no remaining occurrences of DEFENDER_ASSIGNED and that ADVOCATE_ASSIGNED is consistently used across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining instances of DEFENDER_ASSIGNED that might need updating

# Test: Search for DEFENDER_ASSIGNED in TypeScript files
rg --type typescript 'DEFENDER_ASSIGNED'

# Test: Search for ADVOCATE_ASSIGNED to confirm the changes
rg --type typescript 'ADVOCATE_ASSIGNED'

Length of output: 151


Script:

#!/bin/bash
# Description: Check for any remaining instances of DEFENDER_ASSIGNED that might need updating

# Test: Search for DEFENDER_ASSIGNED in TypeScript files
rg 'DEFENDER_ASSIGNED' -g '*.ts' -g '*.tsx'

# Test: Search for ADVOCATE_ASSIGNED to confirm the changes
rg 'ADVOCATE_ASSIGNED' -g '*.ts' -g '*.tsx'

Length of output: 4580

apps/judicial-system/backend/migrations/20241003213354-update-notification.js (1)

1-66: Overall assessment: Well-implemented migration with minor suggestions

This migration script effectively implements the required changes for the new advocate notification feature. It correctly updates the enum values in the notification table, adding 'ADVOCATE_ASSIGNED' and providing a proper rollback mechanism.

Key points:

  1. The changes align well with the PR objectives.
  2. Both up and down methods are correctly implemented.
  3. The use of sequelize-replace-enum-postgres is appropriate for this task.

Minor suggestions have been made to improve code quality and documentation. Once these are addressed, the migration script will be ready for implementation.

🧰 Tools
🪛 Biome

[error] 1-1: Redundant use strict directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.

(lint/suspicious/noRedundantUseStrict)

libs/judicial-system/types/src/index.ts (1)

100-100: LGTM: Export changes align with PR objectives and coding guidelines.

The modification to export Lawyer, mapToLawyer, and the new AdvocateType from ./lib/advocate instead of ./lib/defender aligns well with the PR objectives of implementing notifications for advocates in civil claims cases. This change enhances the specificity of the types and functions related to advocates.

The update adheres to the coding guidelines for libs/**/* files:

  1. Reusability: By exporting these types and functions from a central location, it promotes reusability across different NextJS apps in the judicial system.
  2. TypeScript usage: The export statement correctly uses TypeScript syntax for type exports.
  3. Tree-shaking and bundling: The specific export of named entities (Lawyer, mapToLawyer, AdvocateType) allows for effective tree-shaking in the bundling process.

To ensure the Lawyer type is no longer exported from the defender module, run the following script:

apps/judicial-system/backend/src/app/modules/notification/guards/rolesRules.ts (1)

42-42: LGTM: Consistent update for District Court Registrar

The addition of NotificationType.ADVOCATE_ASSIGNED for the District Court Registrar role is consistent with the change made for the District Court Judge. This update maintains uniformity across roles and aligns with the PR objective.

apps/judicial-system/web/src/routes/Court/Indictments/Advocates/Advocates.tsx (1)

Line range hint 1-103: Overall assessment: Well-structured component with appropriate change.

The Advocates component is well-structured and follows NextJS and TypeScript best practices. The use of hooks, context, and TypeScript typing is appropriate throughout the file. The single change made to update the notification type is correct and aligns with the PR objectives.

Key observations:

  1. Proper use of NextJS routing with useRouter.
  2. Effective use of React hooks and context.
  3. Type-safe usage of enums and props.
  4. Clear separation of concerns within the component.

The change doesn't introduce any new warnings or errors and maintains the overall code quality of the file.

apps/judicial-system/web/src/components/Inputs/InputAdvocate.tsx (3)

15-15: LGTM: Import statement updated correctly

The import of AdvocateType from the types package is appropriate and aligns with NextJS best practices for type imports.


Line range hint 322-327: LGTM: Label rendering logic updated correctly

The condition for rendering the label has been properly updated to use the AdvocateType.LEGAL_RIGHTS_PROTECTOR enum value. This change maintains the existing logic while improving type safety and readability.


Line range hint 370-375: LGTM: Email and phone number label rendering logic updated correctly

The conditions for rendering the email and phone number labels have been properly updated to use the AdvocateType.LEGAL_RIGHTS_PROTECTOR enum value. These changes maintain the existing logic while improving type safety and readability, and are consistent with the previous label rendering logic update.

Also applies to: 484-489

apps/judicial-system/backend/src/app/formatters/formatters.ts (1)

17-21: LGTM: Import statement updated correctly

The addition of AdvocateType to the import statement is consistent with the changes made to the formatDefenderAssignedEmailNotification function. The reorganization of the import statement improves code readability by grouping related types together.

apps/judicial-system/backend/src/app/messages/notifications.ts (1)

618-620: LGTM! Improved notification specificity for different advocate types.

The changes to the defenderAssignedEmail.body message enhance the notification system by distinguishing between different types of advocates (LAWYER, LEGAL_RIGHTS_PROTECTOR, and others). This improvement aligns well with the PR objectives to implement notifications for lawyers and legal rights protectors in civil claims cases.

The update provides more specific and relevant information to the recipients, which should improve clarity and reduce potential confusion about their role in the case.

apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAdvocateAssignedNotifications.spec.ts (3)

83-83: Change NotificationType to ADVOCATE_ASSIGNED is appropriate

The update from NotificationType.DEFENDER_ASSIGNED to NotificationType.ADVOCATE_ASSIGNED correctly reflects the new notification logic for advocate assignments.


Line range hint 570-588: Confirm that no email is sent for investigation cases

The test correctly checks that no email is sent when handling investigation cases with NotificationType.ADVOCATE_ASSIGNED. This behavior aligns with the expected logic.


128-176: Ensure consistency in email content and variables

The new test case for when the case has civil claims and the advocate is a lawyer is well-structured. However, consider verifying that all variable names and email content accurately reflect the role of an advocate instead of a defender to maintain consistency and avoid confusion.

Run the following script to check for instances of 'defender' in the advocate test cases:

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

🧹 Outside diff range and nitpick comments (2)
apps/judicial-system/backend/src/app/modules/notification/internalNotification.service.ts (2)

Line range hint 1523-1566: Approved with a minor suggestion for improvement

The shouldSendAdvocateAssignedNotification function looks well-implemented and covers different case types appropriately. It correctly checks for previous notifications to avoid duplicates.

To improve readability, consider extracting the session arrangement check into a separate constant:

+ const isDefenderIncludedInSessionArrangements = [
+   SessionArrangements.ALL_PRESENT,
+   SessionArrangements.ALL_PRESENT_SPOKESPERSON,
+ ].includes(theCase.sessionArrangements);

- if (!isDefenderIncludedInSessionArrangements) return false
+ if (!isDefenderIncludedInSessionArrangements) {
+   return false;
+ }

This change would make the condition more self-explanatory and consistent with the coding style used elsewhere in the file.


Line range hint 1593-1679: Approved with suggestions for improvement

The sendAdvocateAssignedNotifications function is well-implemented and correctly handles different case types. However, there are a few suggestions to improve its structure and efficiency:

  1. Consider extracting the logic for sending notifications to defendants and civil claimants into separate functions to reduce nesting and improve readability.

  2. The civil claimant notification logic can be optimized. Instead of checking shouldSend inside the loop, you can filter the civil claimants first:

const eligibleCivilClaimants = theCase.civilClaimants?.filter(
  (claimant) =>
    this.shouldSendAdvocateAssignedNotification(theCase, claimant.spokespersonEmail) &&
    claimant.hasSpokesperson
) ?? [];

eligibleCivilClaimants.forEach((claimant) => {
  promises.push(
    this.sendAdvocateAssignedNotification(
      theCase,
      claimant.spokespersonIsLawyer ? AdvocateType.LAWYER : AdvocateType.LEGAL_RIGHTS_PROTECTOR,
      claimant.spokespersonNationalId,
      claimant.spokespersonName,
      claimant.spokespersonEmail
    )
  );
});
  1. Consider using Promise.all for defendants as well, similar to how it's used for civil claimants, to process all notifications in parallel.

These changes would make the function more efficient and easier to read without changing its core functionality.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5c54105 and b41853e.

📒 Files selected for processing (1)
  • apps/judicial-system/backend/src/app/modules/notification/internalNotification.service.ts (8 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/backend/src/app/modules/notification/internalNotification.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."
🔇 Additional comments (2)
apps/judicial-system/backend/src/app/modules/notification/internalNotification.service.ts (2)

1568-1590: LGTM! Well-implemented function

The sendAdvocateAssignedNotification function is implemented correctly and follows the established pattern for notification functions in this file. It properly uses the formatter function to generate email content and handles the case where an advocate might not have a national ID. The function is concise and clear in its purpose.


2568-2569: LGTM! Proper integration of new notification type

The addition of the NotificationType.ADVOCATE_ASSIGNED case in the sendCaseNotification function is implemented correctly. It follows the existing pattern in the switch statement and properly calls the sendAdvocateAssignedNotifications function for this new notification type. This change seamlessly integrates the new advocate assigned notifications into the existing notification system.

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

🧹 Outside diff range and nitpick comments (1)
apps/judicial-system/backend/src/app/messages/notifications.ts (1)

610-634: LGTM! Consider adding comments for clarity.

The restructuring of the advocateAssignedEmail object enhances the flexibility of the notification system. The new fields allow for more specific messages based on the advocate type and their access to case files, which is a good improvement.

Consider adding brief comments above each field to explain when each message is used. This would improve code readability and maintainability. For example:

advocateAssignedEmail: defineMessages({
  // Used when the advocate has access to case files
  subjectAccessToCaseFiles: {
    // ... existing code ...
  },
  // Used when notifying about general case access
  subjectAccess: {
    // ... existing code ...
  },
  // ... add comments for other fields ...
}),
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b41853e and 5fa9870.

📒 Files selected for processing (2)
  • apps/judicial-system/backend/src/app/formatters/formatters.ts (2 hunks)
  • apps/judicial-system/backend/src/app/messages/notifications.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
apps/judicial-system/backend/src/app/formatters/formatters.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/messages/notifications.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."
🔇 Additional comments (4)
apps/judicial-system/backend/src/app/formatters/formatters.ts (4)

17-21: Import statement updated to include AdvocateType

The import statement has been updated to include AdvocateType from the @island.is/judicial-system/types module. This change is necessary to support the new parameter in the formatAdvocateAssignedEmailNotification function.


671-709: Summary of changes to advocate notification system

The modifications to the formatAdvocateAssignedEmailNotification function significantly enhance the flexibility and specificity of the notification system for different advocate types in civil claims cases. By introducing the AdvocateType parameter and implementing conditional logic, the function now generates tailored notifications for defenders and other advocate types.

These changes align well with the PR objectives of implementing notifications for lawyers and legal rights protectors in civil claim cases. The implementation is clean, follows TypeScript best practices, and improves the overall modularity of the notification system.


677-709: Conditional logic added to handle different advocate types

The function now uses conditional statements to format the subject and body of the email based on the advocateType. This allows for more specific and relevant notifications for different types of advocates.

Key changes:

  1. Different subject lines for defenders and other advocate types.
  2. Different body content for defenders and other advocate types.
  3. Utilization of the advocateType parameter in the formatting of the email body.

These changes improve the specificity and relevance of the notifications sent to different types of advocates.

To ensure that all possible AdvocateType values are handled correctly, let's verify the implementation:

#!/bin/bash
# Search for the definition of AdvocateType enum
rg "enum AdvocateType" --type typescript

# Search for usage of AdvocateType in the codebase
rg "AdvocateType\." --type typescript

671-676: Function signature updated to support multiple advocate types

The function has been renamed from formatDefenderAssignedEmailNotification to formatAdvocateAssignedEmailNotification and now includes an advocateType parameter of type AdvocateType. This change allows the function to handle notifications for different types of advocates, improving its flexibility and reusability.

To ensure this change is properly implemented across the codebase, let's verify the usage of this function:

✅ Verification successful

Function signature update verified

The formatAdvocateAssignedEmailNotification function is correctly updated and used in the following locations:

  • apps/judicial-system/backend/src/app/modules/notification/internalNotification.service.ts
  • apps/judicial-system/backend/src/app/formatters/index.ts
  • apps/judicial-system/backend/src/app/formatters/formatters.ts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of the new function name
rg "formatAdvocateAssignedEmailNotification" --type typescript

Length of output: 152


Script:

#!/bin/bash
# Search for usage of the new function name in TypeScript files
rg "formatAdvocateAssignedEmailNotification" --type ts
rg "formatAdvocateAssignedEmailNotification" --type tsx

Length of output: 651


Script:

#!/bin/bash
# Search for usage of the new function name in TypeScript and TSX files
rg "formatAdvocateAssignedEmailNotification" --glob "*.ts" --glob "*.tsx"

Length of output: 586

Copy link
Member

@unakb unakb left a comment

Choose a reason for hiding this comment

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

🙌

@oddsson oddsson added the automerge Merge this PR as soon as all checks pass label Oct 10, 2024
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

🧹 Outside diff range and nitpick comments (1)
apps/judicial-system/web/src/routes/Court/Indictments/Advocates/SelectCivilClaimantAdvocate.tsx (1)

91-92: LGTM: Improved type safety with enum usage

The replacement of string literals with AdvocateType enum values (AdvocateType.LAWYER and AdvocateType.LEGAL_RIGHTS_PROTECTOR) is a good improvement. It enhances type safety and makes the code more maintainable.

Consider using a ternary operator for a more concise expression:

advocateType={civilClaimant.spokespersonIsLawyer ? AdvocateType.LAWYER : AdvocateType.LEGAL_RIGHTS_PROTECTOR}

This change would slightly improve readability while maintaining the same functionality.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9f2f435 and aa96f55.

📒 Files selected for processing (1)
  • apps/judicial-system/web/src/routes/Court/Indictments/Advocates/SelectCivilClaimantAdvocate.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/web/src/routes/Court/Indictments/Advocates/SelectCivilClaimantAdvocate.tsx (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."
🔇 Additional comments (1)
apps/judicial-system/web/src/routes/Court/Indictments/Advocates/SelectCivilClaimantAdvocate.tsx (1)

12-12: LGTM: New import enhances type safety

The addition of the AdvocateType import from @island.is/judicial-system/types is a good practice. It enhances type safety by introducing an enum for advocate types, which aligns well with TypeScript best practices.

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