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): Subpoena delivery and endpoint for updates #15918

Merged
merged 41 commits into from
Sep 16, 2024
Merged

Conversation

unakb
Copy link
Member

@unakb unakb commented Sep 9, 2024

Asana
Asana

What

  • Send subpoena to police
  • Endpoint for updates on subpoena status

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 Subpoena module for managing subpoenas within the judicial system.
    • Added functionality for creating, updating, and delivering subpoenas to the police.
    • New API endpoints for retrieving and updating subpoenas.
  • Enhancements

    • Improved notification system to ensure defendants receive specific notifications regarding police subpoenas.
    • Enhanced error handling when retrieving subpoenas and validating associated entities.
  • Documentation

    • Updated API documentation to reflect new endpoints and data transfer objects for subpoenas.

Copy link
Contributor

coderabbitai bot commented Sep 9, 2024

Walkthrough

This pull request introduces enhancements to the judicial system's backend, focusing on managing subpoenas. It includes the creation of a new subpoena database table, updates to services and controllers for handling subpoena-related operations, and the introduction of a new model and notification types. Additionally, it implements guards for validation and logging, ensuring robust functionality throughout the system.

Changes

File Path Change Summary
apps/judicial-system/backend/migrations/.../create-subpoena.js Created a new subpoena table with fields for ID, timestamps, defendant ID, case ID, acknowledgment status, and comments.
apps/judicial-system/backend/src/app/modules/notification/notification.service.ts Enhanced notification handling for cases by adding messages for defendants regarding police subpoenas.
apps/judicial-system/backend/src/app/modules/subpoena/internalSubpoena.controller.ts Introduced InternalSubpoenaController for managing subpoena-related API endpoints, including methods for retrieving, updating, and delivering subpoenas.
apps/judicial-system/backend/src/app/modules/subpoena/models/subpoena.model.ts Defined Subpoena Sequelize model for database interactions, including relationships with Defendant and Case.
apps/judicial-system/backend/src/app/modules/subpoena/dto/updateSubpoena.dto.ts Created UpdateSubpoenaDto for updating subpoena information with validation rules.
apps/judicial-system/xrd-api/src/app/dto/subpoena.dto.ts Created UpdateSubpoenaDto for updating subpoena information with validation rules.

Possibly related PRs

  • feat(j-s): Confirmed court records #15921: The changes in this PR involve enhancements to PDF generation for court records, which may relate to the management of subpoenas as both involve legal documentation processes within the judicial system.

Suggested labels

automerge


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 generate interesting stats about this repository and render them as a table.
    -- @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 Sep 9, 2024

Codecov Report

Attention: Patch coverage is 2.12766% with 184 lines in your changes missing coverage. Please review.

Project coverage is 36.76%. Comparing base (43a6c6d) to head (d6180f0).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ckend/src/app/modules/subpoena/subpoena.service.ts 0.00% 48 Missing ⚠️
...pp/modules/subpoena/internalSubpoena.controller.ts 0.00% 42 Missing ⚠️
...m/backend/src/app/modules/police/police.service.ts 0.00% 22 Missing ⚠️
.../src/app/modules/subpoena/models/subpoena.model.ts 0.00% 20 Missing ⚠️
...ackend/src/app/modules/subpoena/subpoena.module.ts 0.00% 13 Missing ⚠️
...src/app/modules/subpoena/dto/updateSubpoena.dto.ts 0.00% 12 Missing ⚠️
...pp/modules/subpoena/guards/subpoenaExists.guard.ts 0.00% 11 Missing ⚠️
...ackend/src/app/modules/subpoena/dto/deliver.dto.ts 0.00% 4 Missing ⚠️
...p/modules/police/models/createSubpoena.response.ts 0.00% 3 Missing ⚠️
.../app/modules/subpoena/guards/subpoena.decorator.ts 0.00% 3 Missing ⚠️
... and 4 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #15918      +/-   ##
==========================================
- Coverage   36.81%   36.76%   -0.05%     
==========================================
  Files        6721     6731      +10     
  Lines      137887   138052     +165     
  Branches    39209    39231      +22     
==========================================
- Hits        50763    50757       -6     
- Misses      87124    87295     +171     
Flag Coverage Δ
judicial-system-api 19.35% <ø> (ø)
judicial-system-backend 55.17% <2.12%> (-0.55%) ⬇️
judicial-system-formatters 79.83% <ø> (ø)
judicial-system-message 66.86% <100.00%> (+0.06%) ⬆️
judicial-system-message-handler 47.71% <100.00%> (+0.09%) ⬆️
judicial-system-scheduler 69.01% <100.00%> (+0.02%) ⬆️
judicial-system-web 28.71% <ø> (ø)

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

Files with missing lines Coverage Δ
apps/judicial-system/backend/src/app/app.module.ts 0.00% <ø> (ø)
...ystem/backend/src/app/modules/case/case.service.ts 90.64% <100.00%> (ø)
...s/judicial-system/formatters/src/lib/formatters.ts 80.54% <ø> (ø)
libs/judicial-system/message/src/lib/message.ts 100.00% <100.00%> (ø)
.../modules/defendant/internalDefendant.controller.ts 90.00% <50.00%> (ø)
...s/judicial-system/backend/src/app/modules/index.ts 0.00% <0.00%> (ø)
...c/app/modules/notification/notification.service.ts 92.10% <50.00%> (-2.34%) ⬇️
...p/modules/police/models/createSubpoena.response.ts 0.00% <0.00%> (ø)
.../app/modules/subpoena/guards/subpoena.decorator.ts 0.00% <0.00%> (ø)
...rc/app/modules/subpoena/models/deliver.response.ts 0.00% <0.00%> (ø)
... and 8 more

... and 7 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 43a6c6d...d6180f0. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 9, 2024

Datadog Report

All test runs ad594c4 🔗

9 Total Test Services: 0 Failed, 9 Passed
🔻 Test Sessions change in coverage: 3 decreased, 5 increased, 4 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 57 0 6.62s 1 increased (+0.03%) Link
judicial-system-backend 0 0 0 21268 0 19m 41.94s 1 decreased (-0.69%) Link
judicial-system-formatters 0 0 0 36 0 6.06s 1 increased (+0.02%) Link
judicial-system-message 0 0 0 32 0 12.05s 1 increased (+0.07%) Link
judicial-system-message-handler 0 0 0 4 0 4.06s 1 increased (+0.09%) Link
judicial-system-scheduler 0 0 0 4 0 4.76s 1 increased (+0.05%) Link
judicial-system-types 0 0 0 23 0 8.32s 1 decreased (-0.1%) Link
judicial-system-web 0 0 0 338 0 1m 15.44s 1 no change Link
judicial-system-xrd-api 0 0 0 6 0 5.73s 1 decreased (-1.74%) Link

🔻 Code Coverage Decreases vs Default Branch (3)

  • judicial-system-xrd-api - jest 74.09% (-1.74%) - Details
  • judicial-system-backend - jest 58.72% (-0.69%) - Details
  • judicial-system-types - jest 52.08% (-0.1%) - Details

@unakb unakb marked this pull request as ready for review September 16, 2024 09:24
@unakb unakb requested a review from a team as a code owner September 16, 2024 09:24
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 (1)
apps/judicial-system/backend/src/app/modules/police/police.service.ts (1)

511-578: LGTM! The createSubpoena method is well-implemented.

The method correctly extracts the necessary information from the workingCase and defendant objects to construct the API request payload. It handles the API response appropriately, returning the subpoenaId on success and logging errors on failure.

A few minor suggestions for improvement:

  • Consider adding type annotations for the subpoenaId variable to improve code readability and type safety.
  • Consider extracting the error handling logic (logging and posting error events) into a separate method to promote code reuse and maintainability.
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between eb982d4 and 7822377.

Files selected for processing (24)
  • apps/judicial-system/backend/migrations/20240827132504-create-subpoena.js (1 hunks)
  • apps/judicial-system/backend/src/app/app.module.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/case/case.service.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/defendant.service.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/internalDefendant.controller.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/index.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/notification.service.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/police/models/createSubpoena.response.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/police/police.service.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/dto/deliver.dto.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/dto/updateSubpoena.dto.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/guards/subpoena.decorator.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/guards/subpoenaExists.guard.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/internalSubpoena.controller.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/models/deliver.response.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/models/subpoena.model.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/subpoena.module.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts (1 hunks)
  • apps/judicial-system/xrd-api/src/app/app.controller.ts (3 hunks)
  • apps/judicial-system/xrd-api/src/app/app.service.ts (3 hunks)
  • apps/judicial-system/xrd-api/src/app/dto/subpoena.dto.ts (1 hunks)
  • apps/judicial-system/xrd-api/src/app/models/subpoena.response.ts (1 hunks)
  • libs/judicial-system/formatters/src/lib/formatters.ts (1 hunks)
  • libs/judicial-system/message/src/lib/message.ts (2 hunks)
Files skipped from review due to trivial changes (2)
  • apps/judicial-system/backend/src/app/modules/case/case.service.ts
  • libs/judicial-system/formatters/src/lib/formatters.ts
Additional context used
Path-based instructions (22)
apps/judicial-system/backend/src/app/modules/subpoena/models/deliver.response.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/police/models/createSubpoena.response.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/subpoena/guards/subpoena.decorator.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/subpoena/dto/deliver.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/xrd-api/src/app/models/subpoena.response.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/subpoena/guards/subpoenaExists.guard.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/xrd-api/src/app/dto/subpoena.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/backend/src/app/modules/subpoena/subpoena.module.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/subpoena/dto/updateSubpoena.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/backend/src/app/modules/index.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/subpoena/models/subpoena.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/backend/src/app/app.module.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/migrations/20240827132504-create-subpoena.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/xrd-api/src/app/app.controller.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/defendant/internalDefendant.controller.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/subpoena/internalSubpoena.controller.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/judicial-system/message/src/lib/message.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."
apps/judicial-system/backend/src/app/modules/subpoena/subpoena.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/xrd-api/src/app/app.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/defendant/defendant.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/police/police.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."
Biome
apps/judicial-system/backend/migrations/20240827132504-create-subpoena.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 not posted (34)
apps/judicial-system/backend/src/app/modules/subpoena/models/deliver.response.ts (1)

3-6: LGTM!

The DeliverResponse class is well-structured and follows best practices:

  • The class name clearly conveys its purpose.
  • The @ApiProperty decorator is used correctly to specify the type of the delivered property for API documentation.
  • The non-null assertion operator ! is used appropriately to indicate that the delivered property is always expected to be present.
apps/judicial-system/backend/src/app/modules/police/models/createSubpoena.response.ts (1)

3-6: LGTM!

The CreateSubpoenaResponse class follows the best practices for defining a response DTO:

  • The class name is clear and follows the naming convention.
  • The @ApiProperty decorator is used correctly to specify the type of subpoenaId for API documentation.
  • The subpoenaId property is marked as non-nullable using the ! operator.

The structure and syntax are correct.

apps/judicial-system/backend/src/app/modules/subpoena/guards/subpoena.decorator.ts (1)

1-7: LGTM!

The custom CurrentSubpoena decorator is implemented correctly and follows NestJS best practices. It effectively extracts the current Subpoena object from the request context, making it accessible in the route handler. The use of createParamDecorator and TypeScript ensures type safety and adherence to the framework's guidelines.

The decorator enhances the management and utilization of subpoena-related data within the application, streamlining the process of accessing this information across the codebase.

apps/judicial-system/backend/src/app/modules/subpoena/dto/deliver.dto.ts (2)

7-12: LGTM!

The DeliverDto class is well-structured and follows the appropriate naming convention for a DTO class. It serves a clear purpose of delivering user-related data and ensures type safety by importing the User type from the appropriate module.


8-11: LGTM!

The user property in the DeliverDto class is well-defined with appropriate validation decorators (@IsNotEmpty() and @IsObject()) to ensure data integrity. The @ApiProperty() decorator enhances API documentation by specifying the type of the property. The readonly modifier and non-null assertion operator ! provide additional type safety and prevent unintended reassignment of the property.

apps/judicial-system/xrd-api/src/app/models/subpoena.response.ts (2)

7-13: LGTM!

The SubpoenaResponse class is well-defined and serves its purpose as a DTO for subpoena responses. The properties are appropriately typed and decorated for API documentation.


15-22: LGTM!

The DefenderInfo class is well-structured and effectively encapsulates the relevant information about the defender. The use of the @IsEnum decorator ensures data integrity for the defenderChoice property, and the @ApiProperty decorators provide necessary metadata for API documentation.

apps/judicial-system/backend/src/app/modules/subpoena/guards/subpoenaExists.guard.ts (1)

1-27: LGTM!

The SubpoenaExistsGuard class follows NestJS best practices and provides a robust way to validate the existence of a subpoena based on the subpoenaId parameter in the request URL. The class correctly handles the case when the subpoenaId is missing by throwing a BadRequestException. Retrieving the subpoena using the SubpoenaService and attaching it to the request object is a good approach to make the subpoena available to subsequent handlers.

The code is well-structured, and the logic is clear and concise. Great job!

apps/judicial-system/xrd-api/src/app/dto/subpoena.dto.ts (1)

7-27: LGTM!

The UpdateSubpoenaDto class is well-structured and follows best practices:

  • The properties are correctly typed and marked as optional.
  • Appropriate validation decorators are used to ensure data integrity.
  • @ApiProperty decorators are used for seamless Swagger integration.
  • The DefenderChoice enum is correctly imported and used.

The class provides a clean and validated way to update subpoena information.

apps/judicial-system/backend/src/app/modules/subpoena/subpoena.module.ts (1)

1-22: LGTM! The SubpoenaModule follows NestJS best practices and effectively encapsulates subpoena-related functionality.

The module structure and design are well-organized and adhere to NestJS conventions. Key observations:

  • The use of forwardRef is appropriate to handle circular dependencies between modules.
  • The module properly integrates with other relevant modules such as CaseModule, DefendantModule, and PoliceModule.
  • The module leverages Sequelize for ORM capabilities, defining the necessary models (Subpoena and Defendant).
  • The module registers the InternalSubpoenaController and SubpoenaService, promoting a clean separation of concerns.

Overall, the SubpoenaModule effectively encapsulates subpoena-related functionality and sets up the necessary infrastructure for managing subpoenas within the judicial system.

apps/judicial-system/backend/src/app/modules/subpoena/dto/updateSubpoena.dto.ts (1)

7-42: LGTM! The UpdateSubpoenaDto class is well-structured and effectively uses decorators for validation and API documentation.

The class demonstrates several positive aspects:

  1. Each property is declared on a separate line, enhancing readability.
  2. The use of @IsOptional decorator for all properties allows flexibility in updating subpoena information.
  3. The validation decorators such as @IsBoolean, @IsString, and @IsEnum ensure type safety and data integrity.
  4. The @ApiPropertyOptional annotations improve API documentation by specifying the expected type and optionality of each property.
  5. The defenderChoice property uses the DefenderChoice enum, promoting consistency and type safety.

Overall, the class provides a clear and validated structure for updating subpoena information, which enhances the robustness and maintainability of the codebase. The effective use of decorators for validation and API documentation improves the developer experience and reduces the likelihood of errors.

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

21-21: LGTM!

The export statement for the SubpoenaModule follows the established pattern in the file and makes the module available for use in other parts of the application. This change aligns with the PR objective of implementing subpoena-related functionality in the judicial system's backend.

apps/judicial-system/backend/src/app/modules/subpoena/models/subpoena.model.ts (4)

1-15: Imports look good!

The file correctly imports the necessary dependencies from sequelize-typescript, @nestjs/swagger, and other application models. The imports are well-structured and follow the best practices.


17-20: @Table decorator configuration looks good!

The @Table decorator correctly defines the tableName as 'subpoena' and enables timestamps by setting timestamps to true. This configuration aligns with the best practices for defining Sequelize models.


21-66: Model properties are well-defined!

The Subpoena model extends the Sequelize Model class and defines several properties with appropriate data types, validation decorators, and relationships:

  • The id property is correctly defined as the primary key with UUID data type and default value.
  • The created and modified properties use the @CreatedAt and @UpdatedAt decorators for automatic timestamp management.
  • The subpoenaId, acknowledged, and comment properties are optional and use appropriate data types.
  • The defendantId and caseId properties are correctly defined as foreign keys using the @ForeignKey decorator.
  • The @BelongsTo decorator is used to define the relationships with the Defendant and Case models.
  • The @ApiProperty and @ApiPropertyOptional decorators are used for Swagger documentation.

The property definitions align with the best practices for defining Sequelize models and follow the NestJS conventions for API documentation.


1-67: Overall structure and adherence to best practices are excellent!

The subpoena.model.ts file is well-structured and follows the NestJS conventions and best practices for defining Sequelize models:

  • The file is organized into logical sections: imports, model definition, and property definitions.
  • The model class is decorated with appropriate Sequelize and NestJS decorators for database mapping and API documentation.
  • The property definitions use TypeScript types for type safety and follow the best practices for defining Sequelize models.
  • The file exports the model class for use in other parts of the application, promoting modularity and reusability.

The code adheres to the following:

  • NestJS best practices for defining Sequelize models and integrating with the NestJS framework.
  • Efficient use of Sequelize decorators and configurations for database mapping and relationships.
  • Optimal use of TypeScript for model property type safety and API documentation.

Great job on structuring the Subpoena model and ensuring adherence to best practices!

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

33-33: LGTM!

The SubpoenaModule is imported and added to the AppModule following the existing patterns and best practices. This change expands the system's capabilities to handle subpoenas without introducing any apparent issues.

Also applies to: 54-54

apps/judicial-system/backend/migrations/20240827132504-create-subpoena.js (1)

3-68: LGTM!

The migration script follows best practices and correctly defines the structure of the subpoena table. The use of transactions ensures data integrity during the migration process.

apps/judicial-system/xrd-api/src/app/app.controller.ts (1)

67-77: LGTM!

The new endpoint for updating subpoenas looks good:

  • The endpoint URL and HTTP method follow REST conventions.
  • The use of ParseUUIDPipe ensures that the subpoenaId parameter is a valid UUID.
  • The UpdateSubpoenaDto and SubpoenaResponse provide a clear contract for the request and response.
  • The @ApiResponse decorator improves the API documentation.

One minor suggestion:

  • Review the debug log statement to ensure it does not log any sensitive information about the subpoena or the update request.
apps/judicial-system/backend/src/app/modules/defendant/internalDefendant.controller.ts (2)

68-68: LGTM!

The updated API documentation accurately reflects the new functionality of the updateDefendant method to update defendant information by case and national ID.


76-76: LGTM!

The updated logging statement accurately reflects the new functionality of the updateDefendant method and provides useful debugging information by including the case ID.

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

72-79: LGTM!

The code segment correctly generates a notification message of type MessageType.DELIVERY_TO_POLICE_SUBPOENA for each defendant associated with the case. This ensures that the police are notified about the subpoena delivery for each defendant, enhancing the comprehensiveness of the notification system.

The message includes the necessary information such as the user, case ID, and defendant ID, making it suitable for its intended purpose.

apps/judicial-system/backend/src/app/modules/subpoena/internalSubpoena.controller.ts (3)

53-62: LGTM!

The getSubpoena method is well-implemented. It uses the SubpoenaExistsGuard to ensure the subpoena exists and the @CurrentSubpoena() decorator to retrieve it. Logging the action is a good practice for debugging.


64-74: LGTM!

The updateSubpoena method is well-implemented. It uses the SubpoenaExistsGuard to validate the subpoena's existence and delegates the update operation to the subpoenaService. Logging the action is a good practice for debugging.


76-114: LGTM!

The deliverSubpoenaToPolice method is well-implemented. It uses multiple guards to ensure the validity of the case, defendant, and case type. Generating the PDF and encoding it in Base64 before sending it to the subpoenaService is a good practice for data transfer. Error handling and logging are implemented for the PDF generation process, which is crucial for debugging.

libs/judicial-system/message/src/lib/message.ts (2)

25-25: LGTM!

The new message type DELIVERY_TO_POLICE_SUBPOENA is added correctly to the MessageType enum. The naming convention is consistent, and the placement is appropriate.


58-58: Verify the deliverSubpoenaToPolice function.

The new entry in the messageEndpoint object is added correctly, mapping the DELIVERY_TO_POLICE_SUBPOENA message type to the deliverSubpoenaToPolice function. The mapping is consistent with the pattern used for other message types.

Ensure that the deliverSubpoenaToPolice function is defined in the codebase and has the expected signature. Run the following script to verify:

apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts (4)

34-39: LGTM!

The createSubpoena method correctly creates a new subpoena record linked to the provided defendant.


41-89: Looks good!

The update method correctly updates the subpoena and defendant records within a transaction. The error handling and logging for unexpected row counts is a nice touch.


91-106: Nicely done!

The findBySubpoenaId method correctly fetches a subpoena record by its ID, with proper error handling for missing or invalid input.


108-139: Great work!

The deliverSubpoenaToPolice method handles the complex process of creating and delivering a subpoena to the police in a clear and error-safe manner. The logging and error handling ensure that any issues are properly tracked and communicated.

apps/judicial-system/xrd-api/src/app/app.service.ts (2)

83-93: LGTM!

The method is correctly using the audit trail service to audit the subpoena update action and delegating the actual update logic to the private method updateSubpoenaInfo.


95-168: Excellent work on implementing the subpoena update functionality!

The method is correctly handling the following:

  • Validation of the defender's choice and national ID.
  • Fetching of lawyer details using the LawyersService if a national ID is provided.
  • Making a PATCH request to update the subpoena with the updated details.
  • Handling successful and error responses from the backend API.

The code is well-structured, readable, and follows best practices.

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

206-220: LGTM!

The added code segment enhances the error handling and robustness of the updateByNationalId method by ensuring that a valid defendant exists before attempting an update. It queries the defendantModel using both the formatted and original national IDs, providing flexibility in the lookup. If no defendant is found, it throws an InternalServerErrorException with a clear error message indicating the absence of the defendant for the specified case.

This addition improves the overall reliability and maintainability of the service.

@unakb unakb changed the title feat(j-s): Subpoena delivery feat(j-s): Subpoena delivery and endpoint for updates Sep 16, 2024
Copy link
Member

@gudjong gudjong left a comment

Choose a reason for hiding this comment

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

No showstoppers, but some suggestions.

@unakb unakb added the automerge Merge this PR as soon as all checks pass label Sep 16, 2024
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