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): New Subpoena #16168

Merged
merged 25 commits into from
Sep 30, 2024
Merged

feat(j-s): New Subpoena #16168

merged 25 commits into from
Sep 30, 2024

Conversation

gudjong
Copy link
Member

@gudjong gudjong commented Sep 26, 2024

New Subpoena

Nýtt fyrirkall

What

  • Enables the district court to issue a new subpoena.
  • Displays all issued subpoenas on case overview pages.
  • The UI supports issuing new subpoenas to only a subset of the defendants, but on the backend all defendants will be sent a new subpoena. This is good enough to start as we will only have a single defendant. A separate task will be created to complete the implementation.
  • Communicating with external systems, LÖKE, island.is and digital mailbox, will be handled in a separate task.
  • When issuing a new subpoena, we should consider clearing any court conclusions set, such as postponed indefinately. Otherwise, the status on case lists may not reflect the new arraignment date. A separete ticket is created for this.

Why

  • Necessary when serving a subpoena fails.

Screenshots / Gifs

Screen.Recording.2024-09-27.at.19.34.47.mov

Checklist:

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

Summary by CodeRabbit

  • New Features

    • Introduced a Subpoena model to enhance the representation of subpoenas in the system.
    • Added an optional subpoenas field to the Defendant class for associating multiple subpoenas.
    • Updated getSubpoenaPdf method to support flexible URL patterns and optional query parameters.
    • Added a new SubpoenaController for handling subpoena-related requests.
    • Introduced SubpoenaExistsGuard and SubpoenaExistsOptionalGuard to manage subpoena existence checks.
  • Bug Fixes

    • Streamlined the DefendantController by removing outdated PDF generation functionality.
  • Refactor

    • Enhanced the CaseService to manage subpoena-related messages and streamline case updates.
    • Simplified the DefendantController by removing unnecessary dependencies and methods.
    • Adjusted the Subpoena model to enforce required fields and improve data integrity.
    • Modified component logic to improve rendering and state management related to subpoenas.
  • Chores

    • Updated database migration scripts to accommodate new fields for subpoenas.

Copy link
Contributor

coderabbitai bot commented Sep 26, 2024

Walkthrough

The changes in this pull request introduce a new Subpoena model and enhance the Defendant class by adding a subpoenas property to accommodate multiple subpoenas. The FileController and various services have been updated to handle these changes, including modifications to method signatures and internal logic. Additionally, a migration script is included to update the database schema, reflecting the new fields related to subpoenas. The DefendantController has been simplified by removing PDF generation functionality, and related imports have been adjusted accordingly.

Changes

Files Change Summary
.../defendant/models/defendant.model.ts Added subpoenas property (optional array of Subpoena objects) to Defendant class.
.../defendant/models/subpoena.model.ts Introduced new Subpoena class with multiple fields for GraphQL schema.
.../file/file.controller.ts Updated getSubpoenaPdf method to accept subpoenaId and optional query parameters.
.../migrations/20240926131706-update-subpoena.js Migration script to add arraignment_date and location columns to subpoena table.
.../formatters/subpoenaPdf.ts Modified createSubpoena function to include new optional subpoena parameter.
.../case/case.module.ts Added SubpoenaModule to CaseModule imports.
.../case/case.service.ts Added new method for handling messages related to updated subpoenas; modified existing methods for better handling.
.../case/internalCase.service.ts Changed import statement for Subpoena model to a more general path.
.../case/limitedAccessCase.service.ts Updated Defendant inclusion in queries to include nested Subpoena model.
.../case/pdf.service.ts Updated getSubpoenaPdf method to include subpoena parameter.
.../defendant/defendant.controller.ts Removed getSubpoenaPdf method and associated PDF generation functionality.
.../defendant/defendant.module.ts Removed Subpoena model from Sequelize features and LimitedAccessDefendantController.
.../subpoena/subpoena.controller.ts Introduced SubpoenaController for handling subpoena-related requests and PDF generation.
.../subpoena/guards/subpoenaExists.guard.ts Updated SubpoenaExistsGuard and added SubpoenaExistsOptionalGuard for conditional checks on subpoenas.

Possibly related PRs

Suggested reviewers

  • unakb

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 Sep 26, 2024

Codecov Report

Attention: Patch coverage is 51.94805% with 111 lines in your changes missing coverage. Please review.

Project coverage is 36.78%. Comparing base (2e17b5d) to head (87db72b).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...src/routes/Court/Indictments/Subpoena/Subpoena.tsx 0.00% 34 Missing ⚠️
...src/app/modules/defendant/models/subpoena.model.ts 0.00% 20 Missing ⚠️
...pp/modules/subpoena/guards/subpoenaExists.guard.ts 6.25% 15 Missing ⚠️
...ystem/backend/src/app/modules/case/case.service.ts 77.14% 8 Missing ⚠️
...tes/Court/components/SubpoenaType/SubpoenaType.tsx 0.00% 6 Missing ⚠️
...system/api/src/app/modules/file/file.controller.ts 0.00% 5 Missing ⚠️
...l-system/backend/src/app/formatters/subpoenaPdf.ts 28.57% 5 Missing ⚠️
...rc/app/modules/defendant/models/defendant.model.ts 0.00% 3 Missing ⚠️
...ckend/src/app/modules/subpoena/subpoena.service.ts 50.00% 3 Missing ⚠️
...ndictmentCaseFilesList/IndictmentCaseFilesList.tsx 50.00% 3 Missing ⚠️
... and 5 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16168      +/-   ##
==========================================
+ Coverage   36.70%   36.78%   +0.07%     
==========================================
  Files        6781     6783       +2     
  Lines      139726   139729       +3     
  Branches    39731    39723       -8     
==========================================
+ Hits        51284    51396     +112     
+ Misses      88442    88333     -109     
Flag Coverage Δ
judicial-system-api 18.30% <0.00%> (-0.16%) ⬇️
judicial-system-backend 55.37% <77.02%> (+0.53%) ⬆️
judicial-system-message 66.99% <ø> (ø)
judicial-system-message-handler 47.99% <75.00%> (+0.09%) ⬆️
judicial-system-scheduler 69.12% <ø> (ø)
judicial-system-web 28.11% <5.88%> (-0.05%) ⬇️
web 1.83% <ø> (ø)

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

Files with missing lines Coverage Δ
...ckend/src/app/modules/case/internalCase.service.ts 85.12% <100.00%> (ø)
.../src/app/modules/case/limitedAccessCase.service.ts 72.32% <100.00%> (+0.24%) ⬆️
...system/backend/src/app/modules/case/pdf.service.ts 77.19% <ø> (ø)
.../src/app/modules/defendant/defendant.controller.ts 97.29% <100.00%> (-0.67%) ⬇️
...kend/src/app/modules/defendant/defendant.module.ts 0.00% <ø> (ø)
...-system/backend/src/app/modules/defendant/index.ts 100.00% <100.00%> (ø)
...les/defendant/test/createTestingDefendantModule.ts 100.00% <100.00%> (ø)
...l-system/backend/src/app/modules/subpoena/index.ts 100.00% <100.00%> (ø)
...pp/modules/subpoena/internalSubpoena.controller.ts 85.00% <100.00%> (+85.00%) ⬆️
...dules/subpoena/limitedAccessSubpoena.controller.ts 100.00% <100.00%> (ø)
... and 21 more

... and 22 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 2e17b5d...87db72b. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 26, 2024

Datadog Report

All test runs 79bbab1 🔗

6 Total Test Services: 0 Failed, 6 Passed
🔻 Test Sessions change in coverage: 2 decreased, 3 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.24s 1 decreased (-0.17%) Link
judicial-system-backend 0 0 0 18451 0 0s N/A Link
judicial-system-message 0 0 0 32 0 11.36s 1 no change Link
judicial-system-message-handler 0 0 0 4 0 3.69s 1 no change Link
judicial-system-scheduler 0 0 0 4 0 4.22s 1 no change Link
judicial-system-web 0 0 0 338 0 1m 9.66s 1 decreased (-0.04%) Link

🔻 Code Coverage Decreases vs Default Branch (2)

  • judicial-system-api - jest 19.5% (-0.17%) - Details
  • judicial-system-web - jest 32.35% (-0.04%) - Details

@gudjong gudjong marked this pull request as ready for review September 27, 2024 17:21
@gudjong gudjong requested a review from a team as a code owner September 27, 2024 17:21
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: 24

🧹 Outside diff range and nitpick comments (33)
apps/judicial-system/backend/src/app/modules/subpoena/index.ts (1)

1-2: Good module structure. Consider adding documentation.

The index.ts file follows good practices by exporting the SubpoenaService and Subpoena model separately. This structure promotes modularity and adheres to NextJS backend best practices.

Consider adding a brief comment or JSDoc to describe the purpose of this module and its exports. This can help other developers quickly understand the module's role in the system. For example:

/**
 * Subpoena Module
 * 
 * This module exports the SubpoenaService for handling subpoena-related operations
 * and the Subpoena model for defining the structure of subpoena data.
 */

export { SubpoenaService } from './subpoena.service'
export { Subpoena } from './models/subpoena.model'
apps/judicial-system/backend/src/app/modules/defendant/index.ts (1)

4-5: LGTM! Consider grouping exports by type.

The new exports, DefendantExistsGuard and CurrentDefendant, are good additions that enhance the module's functionality. They align well with NextJS best practices by modularizing specific components for route protection and request handling.

For better code organization, consider grouping the exports by type. For example:

// Models
export { Defendant } from './models/defendant.model'
export { CivilClaimant } from './models/civilClaimant.model'

// Services
export { DefendantService } from './defendant.service'

// Guards and Decorators
export { DefendantExistsGuard } from './guards/defendantExists.guard'
export { CurrentDefendant } from './guards/defendant.decorator'

This grouping improves readability and makes it easier to understand the different types of exports at a glance.

apps/judicial-system/backend/src/app/modules/subpoena/test/subpoenaController/getSubpoenaPdfRolesRules.spec.ts (2)

18-18: LGTM: Metadata retrieval updated correctly. Consider improving type safety.

The metadata retrieval has been properly updated to use SubpoenaController.prototype.getSubpoenaPdf, which is consistent with the changes in the test focus.

Consider improving type safety by replacing any[] with a more specific type for the rules variable. For example:

let rules: Array<(request: any, response: any) => boolean>;

This would provide better type checking and make the code more self-documenting.


Line range hint 1-32: LGTM: Overall test structure is sound. Consider enhancing assertions.

The test file structure and content are well-maintained after the changes. The assertions correctly check for the presence of all expected rules for the getSubpoenaPdf method.

Consider enhancing the test by checking not just the presence of rules, but also their order if it's significant. This could be done by using expect(rules).toEqual([...]) instead of multiple expect(rules).toContain(...) assertions. For example:

expect(rules).toEqual([
  prosecutorRule,
  prosecutorRepresentativeRule,
  publicProsecutorStaffRule,
  districtCourtJudgeRule,
  districtCourtRegistrarRule,
  districtCourtAssistantRule
]);

This would ensure that the rules are not only present but also in the correct order, if that's important for your use case.

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

19-23: Controllers array updated correctly.

The new controllers have been properly added to the @Module decorator's controllers array. This is in line with NestJS best practices for module configuration.

Consider ordering the controllers from most specific to least specific to optimize route matching:

controllers: [
  LimitedAccessSubpoenaController,
  InternalSubpoenaController,
  SubpoenaController,
],
apps/judicial-system/backend/src/app/modules/subpoena/test/limitedAccessSubpoenaController/limitedAccessSubpoenaControllerGuards.spec.ts (2)

9-15: Consider using a more specific type for guards.

The test suite setup looks good overall. However, consider replacing the any[] type for the guards variable with a more specific type to improve type safety. You could use Array<Function | object> or create a custom type that represents the possible guard types.

Example:

type Guard = Function | { new (): any };
let guards: Guard[];

This change would maintain type safety while still allowing for the different guard types you're expecting.


17-29: LGTM: Comprehensive guard configuration test.

The test case thoroughly verifies the guard configuration for the LimitedAccessSubpoenaController. It checks both the number of guards and their specific types, which is crucial for ensuring proper access control.

For improved readability, consider extracting the expected guard types into an array constant at the beginning of the test file. This would make it easier to update if the guard configuration changes and would reduce repetition in the test case.

Example:

const EXPECTED_GUARD_TYPES = [
  JwtAuthGuard,
  RolesGuard,
  CaseExistsGuard,
  CaseTypeGuard,
  CaseReadGuard,
  DefendantExistsGuard,
  SubpoenaExistsOptionalGuard
];

// In the test case
EXPECTED_GUARD_TYPES.forEach((GuardType, index) => {
  if (GuardType === CaseTypeGuard) {
    expect(guards[index]).toEqual({
      allowedCaseTypes: indictmentCases,
    });
  } else {
    expect(new guards[index]()).toBeInstanceOf(GuardType);
  }
});

This refactoring would make the test more maintainable and easier to read.

apps/judicial-system/backend/migrations/20240926131706-update-subpoena.js (1)

1-3: Remove redundant 'use strict' directive

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

Apply this change:

-'use strict'

 module.exports = {
🧰 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)

apps/judicial-system/backend/src/app/modules/subpoena/test/limitedAccessSubpoenaController/getSubpoenaPdf.spec.ts (2)

17-18: LGTM: Test setup updated with subpoena-related data

The test setup has been correctly updated to include subpoena-related data, which aligns with the new focus of the controller. The use of TypeScript for type assertions is a good practice for maintaining type safety.

Consider using a more descriptive mock data for the subpoena object. For example:

const subpoena = { id: subpoenaId, type: 'limited_access', status: 'active' } as Subpoena

This would make the test more robust and potentially catch issues related to specific subpoena properties.

Also applies to: 20-20


39-47: LGTM: Controller method call updated

The method call has been correctly updated to use limitedAccessSubpoenaController.getSubpoenaPdf, which aligns with the new controller name. The addition of subpoenaId and subpoena as parameters is consistent with the new focus on subpoenas.

Consider using an object with named parameters for the method call to improve readability and maintainability. For example:

await limitedAccessSubpoenaController.getSubpoenaPdf({
  caseId,
  defendantId,
  subpoenaId,
  case: theCase,
  defendant,
  subpoena,
  res,
});

This approach would make the function call more self-documenting and easier to modify in the future.

apps/judicial-system/backend/src/app/modules/subpoena/test/subpoenaController/getSubpoenaPdf.spec.ts (1)

16-16: LGTM: Test setup updated appropriately with a minor suggestion

The changes to the describe block and variable declarations accurately reflect the shift to a subpoena-centric approach. The use of TypeScript for type assertions is good practice.

However, to improve type safety, consider using a more complete mock object for the subpoena:

const subpoena = { id: subpoenaId, /* other required properties */ } as Subpoena;

This will ensure that the mock object more closely resembles an actual Subpoena instance.

Also applies to: 18-19, 21-21

apps/judicial-system/api/src/app/modules/defendant/models/defendant.model.ts (2)

81-82: LGTM: New subpoenas field is well-defined.

The subpoenas field is correctly implemented as an optional array of Subpoena objects. The use of @Field decorator and readonly modifier is appropriate.

Consider adding a brief comment explaining the relationship between a defendant and subpoenas for better code documentation. For example:

/**
 * Array of subpoenas associated with this defendant.
 * A defendant can have multiple subpoenas for different purposes or court appearances.
 */
@Field(() => [Subpoena], { nullable: true })
readonly subpoenas?: Subpoena[]

11-11: Consider the broader impact of introducing the Subpoena relationship.

The addition of the Subpoena import and the subpoenas field to the Defendant model is a significant change that introduces a new relationship between these entities. This aligns well with the PR objective of introducing a new subpoena feature.

Please consider the following points:

  1. Ensure that any existing code that works with Defendant objects is updated to handle the new subpoenas field appropriately.
  2. Update any relevant database schemas or ORM configurations to reflect this new relationship.
  3. Review and update GraphQL queries and mutations that involve defendants to include subpoena information where necessary.
  4. Consider adding unit tests to verify the correct behavior of the new relationship between Defendant and Subpoena.

These changes may have implications across the judicial system module, so a thorough review of related components is recommended.

Also applies to: 81-82

apps/judicial-system/web/src/components/PdfButton/PdfButton.tsx (1)

49-51: Approved: Consistent handling of new elementId type

The updated logic for constructing the postfix variable correctly handles both string and string array cases for elementId. This change is consistent with the Props interface update and provides the necessary flexibility.

A minor optimization suggestion:

Consider using a ternary operator for a more concise expression:

const postfix = elementId
  ? `/${Array.isArray(elementId) ? elementId.join('/') : elementId}`
  : ''

This maintains the same functionality while slightly reducing the code complexity.

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

Line range hint 29-53: LGTM: Module setup changes are consistent

The removal of LimitedAccessDefendantController from the controllers array and PdfService from the providers array is consistent with the overall changes to the module. The module setup continues to adhere to NextJS best practices for testing modules and maintains good TypeScript usage for type safety.

For consistency, consider updating the comment above the providers array to reflect the current list of providers:

  controllers: [DefendantController, InternalDefendantController],
+ // List of providers used in the testing module
  providers: [
    SharedAuthModule,
    MessageService,
    UserService,
    CourtService,
    CaseService,
    // ... (rest of the providers)
  ],

This small change would improve code documentation and maintainability.

apps/judicial-system/message-handler/src/app/messageHandler.service.ts (1)

36-42: Approve changes with a minor suggestion for readability

The modifications to handle message.elementId as either a single value or an array improve the flexibility of the URL construction. This change aligns well with RESTful practices and demonstrates good use of TypeScript features.

To further enhance readability, consider extracting the URL segment construction into a separate function:

private constructElementIdSegment(elementId: string | string[] | undefined): string {
  if (!elementId) return '';
  const segments = Array.isArray(elementId) ? elementId.join('/') : elementId;
  return `/${segments}`;
}

// Then in handleMessage:
`${this.config.backendUrl}/api/internal${
  message.caseId ? `/case/${message.caseId}` : ''
}/${messageEndpoint[message.type]}${
  this.constructElementIdSegment(message.elementId)
}`

This refactoring would make the URL construction more modular and easier to understand at a glance.

apps/judicial-system/web/src/routes/Court/Indictments/Subpoena/Subpoena.strings.ts (1)

63-68: LGTM! Consider adding a period to the description.

The new newSubpoenaButtonText message is well-structured and consistent with the existing patterns in the file. It aligns with the PR objectives of introducing a new subpoena feature.

Consider adding a period at the end of the description for consistency with other messages in the file:

 newSubpoenaButtonText: {
   id: 'judicial.system.core:subpoena.new_subpoena_button_text',
   defaultMessage: 'Nýtt fyrirkall',
   description:
-    'Notaður sem texti á takka sem býður notanda að búa til nýtt fyrirkall.',
+    'Notaður sem texti á takka sem býður notanda að búa til nýtt fyrirkall.',
 },
apps/judicial-system/backend/src/app/modules/subpoena/internalSubpoena.controller.ts (2)

Line range hint 72-93: LGTM: Improved method signature and guards

The changes to the deliverSubpoenaToPolice method signature and guards are well-implemented:

  1. Adding subpoenaId as a route parameter improves the RESTful nature of the API.
  2. The @CurrentSubpoena() decorator enhances code reusability and separation of concerns.
  3. The SubpoenaExistsGuard ensures data integrity and prevents potential errors.

These changes align well with TypeScript and NestJS best practices.

Consider updating the debug log message to use template literals consistently:

this.logger.debug(
  `Delivering subpoena ${subpoenaId} to police for defendant ${defendantId} and case ${caseId}`,
)

This change makes the string interpolation more consistent and easier to read.


95-102: LGTM: Simplified subpoena delivery logic

The changes in the deliverSubpoenaToPolice method body are well-implemented:

  1. Direct use of the subpoena object instead of PDF generation simplifies the logic and improves type safety.
  2. This change is consistent with the removal of PdfService and aligns with the PR objective.

For consistency with the method signature, consider updating the deliverSubpoenaToPolice call to use named parameters:

return await this.subpoenaService.deliverSubpoenaToPolice({
  case: theCase,
  defendant,
  subpoena,
  user: deliverDto.user,
})

This change would make the code more readable and less prone to errors if the parameter order changes in the future.

apps/judicial-system/backend/src/app/modules/subpoena/test/createTestingSubpoenaModule.ts (2)

29-76: LGTM: Well-structured testing module setup with a minor suggestion

The testing module setup follows NestJS best practices, providing mock implementations for services and models, which is excellent for isolation in unit tests. The use of ConfigModule.forRoot() for configuration management is correct.

Consider extracting the mock implementations for models (Subpoena and Defendant) into separate constants or functions to improve readability and reusability. For example:

const createMockModel = () => ({
  findOne: jest.fn(),
  findAll: jest.fn(),
  create: jest.fn(),
  update: jest.fn(),
  destroy: jest.fn(),
  findByPk: jest.fn(),
});

// Then use it in the providers array
{
  provide: getModelToken(Subpoena),
  useValue: createMockModel(),
},
{
  provide: getModelToken(Defendant),
  useValue: createMockModel(),
},

This approach would make the code more DRY and easier to maintain.


99-110: LGTM: Proper module closure and return, with a suggestion for improvement

The code correctly closes the module to clean up resources and returns an object with all the retrieved instances, allowing for easy destructuring in tests.

Consider using object property shorthand for a more concise return statement:

return {
  userService,
  pdfService,
  subpoenaModel,
  subpoenaService,
  subpoenaController,
  internalSubpoenaController,
  limitedAccessSubpoenaController,
};

This change would make the code more aligned with modern JavaScript practices and improve readability.

apps/judicial-system/backend/src/app/modules/defendant/defendant.controller.ts (2)

Line range hint 1-32: Imports cleanup looks good, consider further optimization.

The removal of unused imports is a good practice and aligns with the changes made to the controller. This helps in maintaining a clean and efficient codebase.

Consider using named imports for ServiceRequirement and User to potentially benefit from tree-shaking:

import { ServiceRequirement, User } from '@island.is/judicial-system/types'

Line range hint 1-132: Clarification needed: NestJS backend vs NextJS frontend

This file is part of a NestJS backend, not a NextJS frontend. The structure and practices used here are appropriate for NestJS. The coding guidelines mention NextJS best practices, which are not applicable to this backend code.

Consider reviewing and updating the coding guidelines to differentiate between frontend (NextJS) and backend (NestJS) best practices. This will ensure more accurate and relevant code reviews in the future.

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

Line range hint 28-35: LGTM: Function signature updated correctly

The createSubpoena function signature has been updated to include new optional parameters, which provides more flexibility. The use of optional parameters is a good TypeScript practice.

Consider adding JSDoc comments to describe the purpose of each new parameter, especially subpoena, to improve code documentation.


157-163: LGTM: Confirmation footer added conditionally

The addition of a confirmation footer when a subpoena is present is a good improvement. The use of optional chaining (?.) when accessing theCase.judge properties is a good TypeScript practice.

Consider extracting the judge-related properties into a separate variable to improve readability:

const judge = {
  name: theCase.judge?.name || '',
  title: theCase.judge?.title,
  institution: theCase.judge?.institution?.name || '',
};

addConfirmation(doc, {
  ...judge,
  date: subpoena.created,
});
apps/judicial-system/web/src/routes/Court/Indictments/Overview/Overview.tsx (1)

126-129: Good restructuring of data passed to SubpoenaType component.

The changes improve the structure of data passed to the SubpoenaType component and introduce a new behavior based on the arraignment schedule. This follows React best practices for rendering lists.

To further enhance type safety, consider defining an interface for the object passed to subpoenaItems:

interface SubpoenaItem {
  defendant: Defendant; // Replace 'Defendant' with the actual type
  disabled: boolean;
}

Then use it in the map function:

subpoenaItems={workingCase.defendants.map((defendant): SubpoenaItem => ({
  defendant,
  disabled: isArraignmentScheduled,
}))}

This will ensure type consistency and make the code more maintainable.

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

Line range hint 296-300: Consider adding documentation for the new subpoena parameter.

While the changes are well-implemented, it would be beneficial to add a brief comment or JSDoc for the subpoena parameter in the getSubpoenaPdf method. This would help other developers understand the purpose and expected content of this new parameter.

Consider adding a JSDoc comment like this:

/**
 * Generates a PDF for a subpoena.
 * @param theCase - The case associated with the subpoena.
 * @param defendant - The defendant involved in the case.
 * @param subpoena - The subpoena details to be included in the PDF.
 * @param arraignmentDate - Optional. The date of arraignment.
 * @param location - Optional. The location of the court.
 * @param subpoenaType - Optional. The type of subpoena.
 * @returns A Promise that resolves to a Buffer containing the PDF data.
 */
async getSubpoenaPdf(
  theCase: Case,
  defendant: Defendant,
  subpoena: Subpoena,
  arraignmentDate?: Date,
  location?: string,
  subpoenaType?: SubpoenaType,
): Promise<Buffer> {
  // ... existing implementation ...
}

**Incomplete updates to `getSubpoenaPdf` method calls**

Several calls to `getSubpoenaPdf` are missing the new `subpoena` parameter. Please ensure all callers include this parameter to maintain consistency and prevent potential errors.

- `apps/judicial-system/backend/src/app/modules/subpoena/test/subpoenaController/getSubpoenaPdf.spec.ts`
- `apps/judicial-system/api/src/app/modules/file/file.controller.ts`
- `apps/judicial-system/api/src/app/modules/file/limitedAccessFile.controller.ts`

🔗 Analysis chain

Line range hint 296-307: LGTM: Method signature update for getSubpoenaPdf.

The addition of the subpoena parameter to the getSubpoenaPdf method and its usage in the createSubpoena function call are consistent with the new subpoena feature. The changes are well-integrated into the existing code.

To ensure that all callers of this method have been updated accordingly, please run the following script:


🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all calls to getSubpoenaPdf include the new subpoena parameter

# Test: Search for calls to getSubpoenaPdf. Expect: All calls include the subpoena parameter.
rg --type typescript -A 5 'getSubpoenaPdf\s*\('

Length of output: 84


Script:

#!/bin/bash
# Description: Verify all calls to getSubpoenaPdf include the new subpoena parameter

# Test: Search for calls to getSubpoenaPdf in TypeScript files. Expect: All calls include the subpoena parameter.
rg -A 5 'getSubpoenaPdf\s*\(' --glob '*.ts*'

Length of output: 6831

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

53-53: Update @ApiTags to Reflect Controller's Focus

The controller is now centered around subpoenas rather than defendants. Consider updating the @ApiTags('limited access defendants') to @ApiTags('limited access subpoenas') for consistency and to accurately represent the controller's functionality.

apps/judicial-system/web/src/routes/Court/components/SubpoenaType/SubpoenaType.tsx (1)

53-53: Simplify marginBottom calculation for better readability

The ternary condition in marginBottom is complex and may affect readability. Consider simplifying it or extracting it into a helper variable.

Possible refactor:

-            index === subpoenaItems.length - 1 ? 0 : item.children ? 5 : 3
+            const isLastItem = index === subpoenaItems.length - 1
+            const marginBottom = isLastItem ? 0 : item.children ? 5 : 3

Then update the marginBottom prop:

             <Box
               key={item.defendant.id}
-              marginBottom={
-                index === subpoenaItems.length - 1 ? 0 : item.children ? 5 : 3
-              }
+              marginBottom={marginBottom}
             >
apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts (1)

144-147: Address the TODO: Enhance error handling after updating the subpoena.

The TODO comment suggests improving error handling by checking how many rows were affected during the subpoena update and posting an error event if necessary. Implementing this would ensure that the update operation is successful and that any failures are properly logged and handled.

Would you like assistance in implementing the error handling enhancements for this section?

apps/judicial-system/backend/src/app/modules/case/test/caseController/update.spec.ts (1)

878-879: Consider Simplifying Variable Declarations

Lines 878-879 introduce const subpoenaId1 = uuid() and const subpoenaId2 = uuid(). To enhance readability and maintainability, consider using an array to handle multiple subpoena IDs, especially if more IDs might be added in the future.

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

275-290: Consider the performance impact of using separate: true when including subpoenas

Using separate: true for including subpoenas under defendants causes Sequelize to execute separate queries, which can have performance implications if there are many defendants. Verify that this is acceptable for the expected data volume.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between cb65af3 and 9d0bb0f.

📒 Files selected for processing (42)
  • apps/judicial-system/api/src/app/modules/defendant/models/defendant.model.ts (2 hunks)
  • apps/judicial-system/api/src/app/modules/defendant/models/subpoena.model.ts (1 hunks)
  • apps/judicial-system/api/src/app/modules/file/file.controller.ts (1 hunks)
  • apps/judicial-system/backend/migrations/20240926131706-update-subpoena.js (1 hunks)
  • apps/judicial-system/backend/src/app/formatters/subpoenaPdf.ts (4 hunks)
  • apps/judicial-system/backend/src/app/modules/case/case.module.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/case/case.service.ts (8 hunks)
  • apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/case/pdf.service.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/case/test/caseController/update.spec.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/defendant.controller.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/defendant.module.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/index.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/test/createTestingDefendantModule.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/test/defendantController/getSubpoenaPdfGuards.spec.ts (0 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/guards/subpoenaExists.guard.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/index.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/internalSubpoena.controller.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/limitedAccessSubpoena.controller.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/models/subpoena.model.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/subpoena.controller.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 (5 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/test/createTestingSubpoenaModule.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/test/limitedAccessSubpoenaController/getSubpoenaPdf.spec.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/test/limitedAccessSubpoenaController/getSubpoenaPdfRolesRules.spec.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/test/limitedAccessSubpoenaController/limitedAccessSubpoenaControllerGuards.spec.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/test/subpoenaController/getSubpoenaPdf.spec.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/test/subpoenaController/getSubpoenaPdfRolesRules.spec.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/test/subpoenaController/subpoenaControllerGuards.spec.ts (2 hunks)
  • apps/judicial-system/message-handler/src/app/messageHandler.service.ts (1 hunks)
  • apps/judicial-system/web/src/components/FormProvider/case.graphql (1 hunks)
  • apps/judicial-system/web/src/components/FormProvider/limitedAccessCase.graphql (1 hunks)
  • apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.strings.ts (1 hunks)
  • apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx (2 hunks)
  • apps/judicial-system/web/src/components/PdfButton/PdfButton.tsx (2 hunks)
  • apps/judicial-system/web/src/routes/Court/Indictments/Overview/Overview.tsx (2 hunks)
  • apps/judicial-system/web/src/routes/Court/Indictments/Subpoena/Subpoena.strings.ts (1 hunks)
  • apps/judicial-system/web/src/routes/Court/Indictments/Subpoena/Subpoena.tsx (7 hunks)
  • apps/judicial-system/web/src/routes/Court/components/SubpoenaType/SubpoenaType.tsx (3 hunks)
  • libs/judicial-system/message/src/lib/message.ts (1 hunks)
💤 Files not reviewed due to no reviewable changes (1)
  • apps/judicial-system/backend/src/app/modules/defendant/test/defendantController/getSubpoenaPdfGuards.spec.ts
🧰 Additional context used
📓 Path-based instructions (41)
apps/judicial-system/api/src/app/modules/defendant/models/defendant.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/api/src/app/modules/defendant/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/api/src/app/modules/file/file.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/migrations/20240926131706-update-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/backend/src/app/formatters/subpoenaPdf.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/case/case.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/case/case.service.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/case/pdf.service.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/case/test/caseController/update.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/defendant/defendant.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/defendant.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/defendant/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/defendant/test/createTestingDefendantModule.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/backend/src/app/modules/subpoena/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/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."
apps/judicial-system/backend/src/app/modules/subpoena/limitedAccessSubpoena.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/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/modules/subpoena/subpoena.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/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/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/backend/src/app/modules/subpoena/test/createTestingSubpoenaModule.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/test/limitedAccessSubpoenaController/getSubpoenaPdf.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/subpoena/test/limitedAccessSubpoenaController/getSubpoenaPdfRolesRules.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/subpoena/test/limitedAccessSubpoenaController/limitedAccessSubpoenaControllerGuards.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/subpoena/test/subpoenaController/getSubpoenaPdf.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/subpoena/test/subpoenaController/getSubpoenaPdfRolesRules.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/subpoena/test/subpoenaController/subpoenaControllerGuards.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/message-handler/src/app/messageHandler.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/web/src/components/FormProvider/case.graphql (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/web/src/components/FormProvider/limitedAccessCase.graphql (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.strings.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/IndictmentCaseFilesList/IndictmentCaseFilesList.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/components/PdfButton/PdfButton.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/Overview/Overview.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/Subpoena/Subpoena.strings.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/routes/Court/Indictments/Subpoena/Subpoena.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/components/SubpoenaType/SubpoenaType.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/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."
📓 Learnings (1)
apps/judicial-system/backend/src/app/modules/defendant/index.ts (1)
Learnt from: oddsson
PR: island-is/island.is#16059
File: apps/judicial-system/backend/src/app/modules/defendant/defendant.module.ts:28-28
Timestamp: 2024-09-18T14:32:59.502Z
Learning: Services should only be exported when they are needed by other modules.
🪛 Biome
apps/judicial-system/backend/migrations/20240926131706-update-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)

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

[error] 50-52: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

apps/judicial-system/web/src/routes/Court/Indictments/Subpoena/Subpoena.tsx

[error] 157-208: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

🔇 Additional comments (89)
apps/judicial-system/backend/src/app/modules/subpoena/index.ts (1)

2-2: LGTM! Consider verifying the Subpoena model implementation.

The export of the Subpoena model follows TypeScript best practices. This approach allows for clear separation between the data model and the service logic.

To ensure the Subpoena model is properly implemented, you can run the following script:

✅ Verification successful

Subpoena Model Implementation Verified

The Subpoena model is properly implemented with necessary decorators and properties. The export follows TypeScript best practices and supports tree-shaking.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the Subpoena model implementation

# Test: Check if Subpoena model exists and has properties
ast-grep --lang typescript --pattern 'export class Subpoena {
  $$$
}'

# Test: Look for common model decorators or type definitions
rg --type typescript '(@Entity|@Column|type)' ./apps/judicial-system/backend/src/app/modules/subpoena/models/subpoena.model.ts

Length of output: 236


Script:

#!/bin/bash
# Description: Re-verify the Subpoena model implementation with corrected ripgrep command

# Test: Check if Subpoena model exists and has properties
ast-grep --lang typescript --pattern 'export class Subpoena {
  $$$
}'

# Test: Look for common model decorators or type definitions
rg '(@Entity|@Column|type)' ./apps/judicial-system/backend/src/app/modules/subpoena/models/subpoena.model.ts -g "*.ts" -A 2

Length of output: 1520

apps/judicial-system/backend/src/app/modules/subpoena/test/limitedAccessSubpoenaController/getSubpoenaPdfRolesRules.spec.ts (4)

4-4: LGTM! Test suite description updated correctly.

The test suite description has been properly updated to reflect the new controller name, maintaining consistency with the renaming from LimitedAccessDefendantController to LimitedAccessSubpoenaController.


Line range hint 1-19: Overall LGTM! Suggest comprehensive rename impact verification.

The changes in this file consistently reflect the renaming of the controller from LimitedAccessDefendantController to LimitedAccessSubpoenaController. The test structure and content adhere to NextJS best practices, and the modifications maintain the integrity of the test suite.

To ensure the renaming has been consistently applied across the entire codebase, run the following comprehensive verification script:

#!/bin/bash
# Description: Verify the comprehensive impact of the controller renaming across the codebase.

echo "1. Checking for any remaining references to LimitedAccessDefendantController:"
rg "LimitedAccessDefendantController" apps/judicial-system/backend

echo "2. Verifying occurrences of LimitedAccessSubpoenaController:"
rg "LimitedAccessSubpoenaController" apps/judicial-system/backend

echo "3. Checking for any potential partial renames or inconsistencies:"
rg -i "limitedaccess.*(defendant|subpoena)" apps/judicial-system/backend

echo "4. Verifying import statements for the new controller:"
rg "from '.*limitedAccessSubpoena.controller'" apps/judicial-system/backend

echo "5. Checking for any TODO comments related to the rename:"
rg -i "todo.*rename" apps/judicial-system/backend

This script will help ensure that the renaming has been consistently applied throughout the codebase and catch any potential oversights.


2-2: LGTM! Verify file structure for consistency.

The import statement has been correctly updated to reflect the new controller name. This change is consistent with the renaming from LimitedAccessDefendantController to LimitedAccessSubpoenaController.

To ensure the file structure is consistent with this change, run the following script:


11-11: LGTM! Verify method name consistency across the codebase.

The metadata retrieval has been correctly updated to use LimitedAccessSubpoenaController.prototype.getSubpoenaPdf, which is consistent with the controller renaming.

To ensure the method name getSubpoenaPdf is consistently used across the codebase, run the following script:

apps/judicial-system/api/src/app/modules/defendant/models/subpoena.model.ts (3)

1-4: LGTM: Imports and class definition are correct.

The imports from '@nestjs/graphql' and the use of the @ObjectType() decorator are appropriate for defining a GraphQL object type. The file structure also adheres to NextJS best practices for API routes.


5-6: LGTM: 'id' field is correctly defined.

The 'id' field is appropriately defined as a non-nullable ID type and marked as readonly, which ensures data integrity and follows GraphQL best practices for unique identifiers.


1-31: Overall structure adheres to TypeScript and NestJS best practices.

The file demonstrates good use of TypeScript features and follows NestJS conventions for GraphQL object types. The structure is clean and well-organized.

However, there's room for improvement in type safety, as mentioned in previous comments. Implementing these suggestions would further enhance the robustness of the code.

While this file doesn't contain NextJS-specific code (being a backend model), it fits well within a NextJS project structure for API routes.

apps/judicial-system/backend/src/app/modules/subpoena/test/subpoenaController/getSubpoenaPdfRolesRules.spec.ts (3)

9-9: LGTM: Import statement updated correctly.

The import statement has been properly updated to import SubpoenaController instead of DefendantController, which aligns with the changes in the test focus.


11-11: LGTM: Test description updated appropriately.

The test description has been correctly updated to reflect the focus on SubpoenaController instead of DefendantController. This change maintains consistency with the new test purpose.


Line range hint 1-32: Summary: Changes are consistent and align with PR objectives.

The modifications in this file successfully transition the test focus from DefendantController to SubpoenaController, which aligns with the PR objective of introducing a new subpoena feature. The changes are consistent throughout the file, including imports, test descriptions, and metadata retrieval.

Minor suggestions have been made to improve type safety and enhance test assertions, but these are not critical issues. Overall, the changes appear to be well-implemented and maintain the integrity of the test suite.

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

Line range hint 1-28: Summary of SubpoenaModule changes.

The modifications to the SubpoenaModule enhance its functionality by:

  1. Adding new controllers (SubpoenaController and LimitedAccessSubpoenaController).
  2. Exporting the SubpoenaService for use in other modules.

These changes follow NestJS best practices and improve the module's capabilities, likely supporting the new subpoena feature mentioned in the PR objectives. However, please address the inconsistency regarding the DefendantModule import noted in the previous comment.


25-25: SubpoenaService export added.

Exporting SubpoenaService allows for its use in other modules, which can enhance code reuse and modularity. This change aligns with the expanded functionality suggested by the new controllers.

To ensure the exported service is used appropriately and doesn't create circular dependencies, run the following script:

#!/bin/bash
# Check for imports of SubpoenaService in other modules
rg --type typescript "import.*SubpoenaService.*from.*subpoena\.module" apps/judicial-system/backend/src/app/modules

9-10: New controller imports look good.

The addition of LimitedAccessSubpoenaController and SubpoenaController imports is consistent with the module's purpose and follows NestJS naming conventions.

To ensure the new controller files exist, run the following script:

✅ Verification successful

To resolve the issues from the previous script, please execute the following corrected shell script to verify the existence of the new controller files:


New controller imports verified successfully.

The LimitedAccessSubpoenaController and SubpoenaController files exist in the specified directory.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the existence of new controller files
fd -e ts -p "limitedAccessSubpoena.controller.ts|subpoena.controller.ts" apps/judicial-system/backend/src/app/modules/subpoena

Length of output: 225


Script:

#!/bin/bash
# Verify the existence of new controller files
fd -e ts 'limitedAccessSubpoena\.controller\.ts|subpoena\.controller\.ts' apps/judicial-system/backend/src/app/modules/subpoena

Length of output: 296

apps/judicial-system/backend/src/app/modules/defendant/defendant.module.ts (2)

Line range hint 1-32: LGTM: Module structure and TypeScript usage

The overall structure of the DefendantModule remains intact and follows NestJS best practices. The use of TypeScript for type safety is appropriate and effective.


24-27: Confirm the removal of LimitedAccessDefendantController

The LimitedAccessDefendantController has been removed from the list of controllers. This could potentially impact the limited access functionality for defendants.

Please ensure this removal is intentional and doesn't break any existing features. Run the following script to check for any remaining references to the LimitedAccessDefendantController:

✅ Verification successful

Removal of LimitedAccessDefendantController Verified

The LimitedAccessDefendantController has been successfully removed without any remaining references in the codebase. No issues detected.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for remaining references to the LimitedAccessDefendantController
# Expected result: No occurrences of LimitedAccessDefendantController in other files

rg --type typescript "import.*LimitedAccessDefendantController.*from" apps/judicial-system
rg --type typescript "LimitedAccessDefendantController" apps/judicial-system

Length of output: 239


Script:

#!/bin/bash
# Description: Check for remaining references to the LimitedAccessDefendantController
# Expected result: No occurrences of LimitedAccessDefendantController in other files

rg "import.*LimitedAccessDefendantController.*from" apps/judicial-system
rg "LimitedAccessDefendantController" apps/judicial-system

Length of output: 133

apps/judicial-system/backend/src/app/modules/subpoena/test/subpoenaController/subpoenaControllerGuards.spec.ts (4)

9-9: LGTM! Test suite title updated correctly.

The describe block title has been appropriately updated to reflect the change from LimitedAccessDefendantController to SubpoenaController.


14-14: LGTM! Metadata retrieval updated correctly.

The metadata retrieval has been correctly updated to use SubpoenaController, which is consistent with the refactoring of the test suite.


5-6: LGTM! Verify import paths across the project.

The new imports look good and align with the refactoring from LimitedAccessDefendantController to SubpoenaController.

To ensure consistency, please run the following script to verify the import paths:

✅ Verification successful

Import paths verified and consistent across the project.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the import paths for DefendantExistsGuard and SubpoenaExistsOptionalGuard

# Test: Search for DefendantExistsGuard imports
echo "DefendantExistsGuard imports:"
rg --type typescript "import.*DefendantExistsGuard.*from"

# Test: Search for SubpoenaExistsOptionalGuard imports
echo "SubpoenaExistsOptionalGuard imports:"
rg --type typescript "import.*SubpoenaExistsOptionalGuard.*from"

Length of output: 348


Script:

#!/bin/bash
# Description: Verify the import paths for DefendantExistsGuard and SubpoenaExistsOptionalGuard

# Test: Search for DefendantExistsGuard imports
echo "DefendantExistsGuard imports:"
rg "import.*DefendantExistsGuard.*from" -g "*.ts"

# Test: Search for SubpoenaExistsOptionalGuard imports
echo "SubpoenaExistsOptionalGuard imports:"
rg "import.*SubpoenaExistsOptionalGuard.*from" -g "*.ts"

Length of output: 2926


Line range hint 18-28: LGTM! Guard assertions updated correctly.

The guard assertions have been properly updated to include the new SubpoenaExistsOptionalGuard while maintaining the existing guard checks. The increase in the number of expected guards from 6 to 7 is correct.

To ensure the guard order is consistent across the application, please run the following script:

apps/judicial-system/backend/src/app/modules/subpoena/test/limitedAccessSubpoenaController/limitedAccessSubpoenaControllerGuards.spec.ts (2)

1-7: LGTM: Imports are well-organized and relevant.

The imports are logically structured, starting with external modules followed by internal modules. All imported entities are used in the test file, and they cover the necessary guards and components for testing the LimitedAccessSubpoenaController.


1-30: Overall: Well-structured and effective test file for guard configuration.

This test file for the LimitedAccessSubpoenaController guards is well-implemented and aligns with NextJS best practices for backend testing. It effectively verifies the guard configuration, which is crucial for ensuring proper access control in the new subpoena feature.

The file structure, import organization, and test case implementation are all commendable. The suggested minor improvements (more specific typing for guards and refactoring the test case for better readability) would further enhance the quality of this already solid test file.

Great job on prioritizing security and access control testing for this new feature!

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

72-74: LGTM: arraignmentDate property addition

The addition of the arraignmentDate property is well-implemented. It's correctly defined as non-nullable in both TypeScript and the database schema, and the @ApiProperty decorator is appropriately used for API documentation.


76-78: LGTM: location property addition

The addition of the location property is well-implemented. It's correctly defined as non-nullable in both TypeScript and the database schema, and the @ApiProperty decorator is appropriately used for API documentation.


Line range hint 1-78: Verify impact on related components

The changes to the Subpoena model look good overall. However, please ensure that all components interacting with the Subpoena model (e.g., controllers, services, and frontend components) are updated to handle the new required properties (caseId, arraignmentDate, and location).

To help verify this, you can run the following script to find potential areas that might need updates:

Please review the output of this script and make necessary adjustments to ensure all parts of the application are consistent with the updated Subpoena model.

apps/judicial-system/backend/migrations/20240926131706-update-subpoena.js (3)

42-60: Approve down function implementation

The down function correctly reverses the changes made in the up function. It removes the newly added columns and reverts the case_id column to its previous state. The use of a transaction ensures the atomicity of the rollback operation.


1-61: Approve overall implementation with testing reminder

The migration file is well-structured and correctly implements the required changes for the new subpoena feature. It follows Sequelize migration best practices and provides a proper rollback mechanism.

As per the PR checklist, please ensure that you've added tests to verify the effectiveness of these changes, particularly focusing on the new arraignment_date and location fields in the subpoena model and any related functionality.

🧰 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)


4-40: Approve changes with a suggestion for arraignment_date

The up function correctly implements the required changes to the subpoena table. However, consider if using CURRENT_TIMESTAMP as the default value for arraignment_date is appropriate for all cases. It might be better to require this value to be explicitly set when creating a new subpoena.

If you decide to keep the current implementation, please run the following script to verify that arraignment_date is being set correctly in the application code:

apps/judicial-system/backend/src/app/modules/subpoena/test/limitedAccessSubpoenaController/getSubpoenaPdf.spec.ts (5)

4-4: LGTM: Import statements updated correctly

The import statements have been appropriately updated to reflect the shift from a defendant-centric approach to a subpoena-centric approach. The use of TypeScript for importing the Subpoena type is a good practice for maintaining type safety.

Also applies to: 7-7


15-15: LGTM: Test suite description updated

The test suite description has been correctly updated to reflect the new focus on the LimitedAccessSubpoenaController. This change maintains clarity and accurately represents the purpose of the test suite.


28-29: LGTM: Module creation updated

The change from createTestingDefendantModule to createTestingSubpoenaModule is consistent with the overall refactoring to a subpoena-centric approach. The destructuring of pdfService and limitedAccessSubpoenaController from the module creation is a good practice for clarity and maintainability.


65-65: LGTM: Test expectation updated

The test expectation has been correctly updated to include the subpoena in the arguments passed to mockPdfService.getSubpoenaPdf. This change ensures that the test accurately verifies the new behavior of passing the subpoena to the PDF service.


Line range hint 1-72: Overall: Well-structured refactoring to subpoena-centric approach

The file has been successfully refactored from a defendant-centric to a subpoena-centric approach, aligning well with the PR objectives. The changes are consistent throughout the file, and the use of TypeScript for type safety is commendable. The test structure follows good practices for unit testing in a NextJS environment.

Key points:

  1. Imports and module creation have been updated correctly.
  2. The test setup and expectations have been adjusted to focus on subpoenas.
  3. TypeScript is used effectively for type assertions and importing types.

The changes adhere to the coding guidelines, particularly in terms of NextJS best practices and TypeScript usage. While this file doesn't directly involve state management or server-side rendering, the structure supports efficient testing of these aspects in the actual implementation.

apps/judicial-system/backend/src/app/modules/subpoena/test/subpoenaController/getSubpoenaPdf.spec.ts (5)

4-4: LGTM: Import statements updated correctly

The new import statements for createTestingSubpoenaModule and Subpoena model align well with the shift towards a subpoena-centric approach in this test file. This change demonstrates good module organization and maintains clear dependencies.

Also applies to: 8-8


29-30: LGTM: Test setup correctly updated

The changes in the beforeEach block, including the use of createTestingSubpoenaModule and the destructuring of subpoenaController, align well with the shift to a subpoena-centric approach. This demonstrates good separation of concerns in the test setup and maintains consistency with the new focus of the controller.


66-66: LGTM: Expectation updated correctly

The addition of the subpoena parameter in the mockPdfService.getSubpoenaPdf expectation accurately reflects the changes made to the controller method. This ensures that the mock service is called with the correct parameters, maintaining the integrity of the test.


Line range hint 1-73: Overall assessment: Well-structured and consistent changes

The modifications to this test file successfully transition it from a defendant-centric to a subpoena-centric approach. The changes are consistent throughout the file, maintaining good TypeScript practices and test structure. The updated imports, variable declarations, test setup, and expectations all align well with the new focus on subpoenas.

A few minor suggestions were made to further improve type safety and ensure consistency with the controller implementation. Overall, the changes effectively represent the new subpoena functionality and maintain the integrity of the test suite.


40-43: LGTM: Controller method call updated correctly

The changes to the controller method call, including the use of subpoenaController and the addition of subpoenaId and subpoena parameters, accurately reflect the updated controller structure and focus.

To ensure consistency, please verify that the getSubpoenaPdf method signature in the SubpoenaController matches these changes. Run the following script to check the method signature:

Also applies to: 46-46

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

18-18: LGTM: SubpoenaModule import added correctly

The addition of SubpoenaModule to the imports list is consistent with the module's structure and follows the existing import pattern. This change aligns with the PR objective of introducing a new subpoena feature.

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

11-11: LGTM: New import statement is correctly placed.

The import of the Subpoena model is appropriately added and follows good practices for modular code organization.

To ensure the Subpoena model is correctly defined, please run the following script:

✅ Verification successful

Verification Successful: Subpoena class is present.

The subpoena.model.ts file exists and correctly exports the Subpoena class as expected. The import statement in defendant.model.ts is valid and follows best practices.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and content of the subpoena.model.ts file

# Test: Check if the file exists and contains a Subpoena class
rg --type typescript -e "export class Subpoena" apps/judicial-system/api/src/app/modules/defendant/models/subpoena.model.ts

Length of output: 160


Script:

#!/bin/bash
# Description: Verify the existence and content of the subpoena.model.ts file

# Test: Check if the file exists and contains a Subpoena class
rg -g '*.ts' -e 'export class Subpoena' apps/judicial-system/api/src/app/modules/defendant/models/subpoena.model.ts

Length of output: 141

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

25-25: Approved: Enhanced flexibility with union type for elementId

The change from string to string | string[] for the elementId property is a good improvement. It allows the component to handle both single and multiple identifiers, increasing its flexibility and reusability. This is a non-breaking change and follows TypeScript best practices for type definitions.


Line range hint 1-101: Approved: Well-structured component adhering to NextJS and TypeScript best practices

The PdfButton component is well-implemented, adhering to NextJS and React best practices:

  1. It uses functional component syntax with TypeScript for better type safety.
  2. Props are properly typed using an interface, enhancing maintainability.
  3. React hooks (useContext) are used correctly.
  4. The component is modular and reusable, promoting code efficiency.
  5. The file structure follows NextJS conventions.

The recent changes have improved the component's flexibility without compromising its adherence to best practices.

apps/judicial-system/backend/src/app/modules/defendant/test/createTestingDefendantModule.ts (2)

13-19: LGTM: Import changes align with module updates

The changes in imports, including the removal of PdfService and the addition of CaseService, CourtService, and UserService, are consistent with the evolving requirements of the testing module. These modifications align well with the changes described in the AI-generated summary.


Line range hint 80-89: LGTM: Return object updates are consistent

The changes in the return object of the createTestingDefendantModule function, specifically the removal of pdfService and limitedAccessDefendantController, are consistent with the earlier modifications in imports and module setup. The return object continues to provide all necessary services and controllers for testing while maintaining good TypeScript usage for type safety.

To ensure that these changes don't have unintended consequences, please verify that all tests using this module have been updated accordingly. Run the following script to check for any remaining references to the removed services:

If this script returns any results, those test files may need to be updated to reflect the changes made in this module.

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

Line range hint 23-33: LGTM: Import changes align with new subpoena feature

The new imports (CurrentSubpoena, SubpoenaExistsGuard, Subpoena) and the removal of PdfService are consistent with the PR's objective of introducing a new subpoena feature. These changes suggest a shift from PDF handling to direct subpoena object management, which is a good practice for better type safety and modularity.


Line range hint 38-41: LGTM: Constructor simplified

The removal of the pdfService parameter from the constructor is consistent with the earlier changes. This simplification keeps the controller focused on its core responsibilities and adheres to the principle of dependency injection. Good job on maintaining a clean and focused controller.

apps/judicial-system/backend/src/app/modules/subpoena/test/createTestingSubpoenaModule.ts (3)

1-27: LGTM: Imports and mocks are well-structured

The imports and mocks are appropriately set up for a testing module. The use of Jest for mocking services is a good practice for unit testing, ensuring isolation of the subpoena module from its dependencies.


78-97: LGTM: Efficient retrieval of service and controller instances

The code efficiently retrieves instances of services and controllers from the compiled module. The use of TypeScript generics ensures type safety, which aligns with the requirement for optimal use of TypeScript in the coding guidelines.


1-110: Great implementation of the Subpoena testing module

This file successfully implements a comprehensive testing module for the new Subpoena feature, aligning well with the PR objectives. The code demonstrates adherence to NextJS and NestJS best practices, including proper file structure and efficient use of the testing framework. The implementation makes optimal use of TypeScript for type safety, as required by the coding guidelines.

The testing module provides a solid foundation for unit testing the Subpoena feature, with proper mocking of dependencies and isolation of the module under test. This approach will facilitate thorough testing of the new feature, contributing to the overall quality and reliability of the judicial system application.

apps/judicial-system/backend/src/app/modules/defendant/defendant.controller.ts (2)

Line range hint 1-132: TypeScript usage is appropriate and effective.

The file demonstrates good use of TypeScript features:

  • Types are well-defined for method parameters and return values.
  • Decorators are used effectively, which is typical in NestJS applications.
  • The overall structure leverages TypeScript's capabilities to enhance code quality and maintainability.

Line range hint 44-47: PDF functionality removed, consider updating documentation.

The removal of the pdfService dependency and the getSubpoenaPdf method indicates that PDF generation functionality has been moved or removed from this controller. This change simplifies the controller's responsibilities.

To ensure consistency across the codebase:

Also, please ensure that any related documentation or API specifications are updated to reflect this change in functionality.

✅ Verification successful

PDF functionality successfully removed. No remaining PDF-related references found in the DefendantController.
Please ensure that all related documentation is updated to reflect these changes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any remaining references to PDF functionality in this file or related files
rg -i 'pdf|subpoena' apps/judicial-system/backend/src/app/modules/defendant

Length of output: 1524


Script:

#!/bin/bash
# Trace all implementations and usages of 'Subpoena' within the defendant module
rg -C 3 'Subpoena' apps/judicial-system/backend/src/app/modules/defendant

Length of output: 3991

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

69-69: Approved: Enhanced flexibility for elementId. Consider adding documentation.

The change to allow elementId to be either a string or an array of strings enhances the flexibility of the Message type, which is good for reusability across different NextJS apps.

Consider adding a comment to explain the usage of elementId, for example:

/**
 * The ID(s) of the element(s) associated with this message.
 * Can be a single string for one element or an array of strings for multiple elements.
 */
elementId?: string | string[]

It's important to verify that this change doesn't break existing code. Please run the following script to check for potential issues:

If the script returns results, those locations may need to be updated to handle both string and array cases.

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

10-10: LGTM: New imports added correctly

The new imports for SubpoenaType and Subpoena are correctly added and follow TypeScript best practices by explicitly importing types.

Also applies to: 16-16


54-56: LGTM: Conditional formatting added

The addition of empty lines when a subpoena is present is a minor formatting change that doesn't affect core functionality.


60-63: LGTM: Improved date handling

The date formatting now correctly uses the subpoena.created property when available, falling back to nowFactory(). The use of the nullish coalescing operator (??) is a good TypeScript practice.


66-68: LGTM: Flexible value assignment

The code now correctly uses the subpoena object properties if available, falling back to the function parameters. This change allows for more flexibility in setting these values, and the use of the nullish coalescing operator (??) is consistent with TypeScript best practices.


Line range hint 1-173: Overall: Well-implemented changes improving subpoena creation flexibility

The modifications to the createSubpoena function significantly improve its flexibility by introducing an optional Subpoena object. The changes are consistent with the AI-generated summary and follow TypeScript best practices. The code now handles various scenarios more gracefully, whether a Subpoena object is provided or not.

Key improvements:

  1. Addition of new optional parameters to the function signature.
  2. Flexible assignment of arraignment date, location, and subpoena type.
  3. Conditional addition of a confirmation footer.
  4. Improved date handling using the subpoena.created property when available.

These changes enhance the reusability and maintainability of the code while adhering to NextJS and TypeScript best practices.

apps/judicial-system/api/src/app/modules/file/file.controller.ts (3)

180-191: Improved flexibility with optional parameters

The changes to the getSubpoenaPdf method signature and URL patterns enhance the API's flexibility. The method now supports both subpoena/:defendantId and subpoena/:defendantId/:subpoenaId routes, allowing for optional subpoenaId. Additionally, making arraignmentDate, location, and subpoenaType optional query parameters improves the versatility of the API.

These changes align well with TypeScript best practices by utilizing optional parameters. The method signature is now more expressive and type-safe.


197-206: Enhanced dynamic URL construction

The new logic for constructing the file service request URL is more robust and handles optional parameters effectively. The use of template literals and conditional injections (subpoenaIdInjection and queryInjection) creates a clean and readable solution.

This approach ensures that the URL is correctly formed regardless of whether subpoenaId or query parameters are provided, improving the method's flexibility and maintainability.


180-206: Overall improvement in subpoena handling

The changes to the getSubpoenaPdf method significantly enhance its flexibility and usability. By supporting an optional subpoenaId and making query parameters optional, the API can now handle a wider range of subpoena-related requests. The updated URL construction logic ensures that these new options are handled correctly.

These modifications align well with NextJS best practices for API routes and make effective use of TypeScript's type system. The changes are focused and don't introduce any apparent issues to the existing codebase.

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

29-32: LGTM! Consider updating related TypeScript types.

The addition of the subpoenas field to the defendants object is well-structured and aligns with the PR objectives. The field follows GraphQL best practices with clear naming and appropriate use of scalar types.

As a follow-up action, please ensure that any related TypeScript interfaces or types (e.g., for Case or Defendant) are updated to include this new field. Run the following script to identify potential files that may need updates:

Review the output and update the relevant TypeScript definitions to include the new subpoenas field.

apps/judicial-system/web/src/routes/Court/Indictments/Overview/Overview.tsx (2)

41-41: Good addition of a descriptive boolean constant.

The introduction of isArraignmentScheduled improves code readability and follows TypeScript best practices. The use of Boolean() ensures a true boolean value, which is a good practice.


Line range hint 1-172: Excellent adherence to NextJS and TypeScript best practices.

The changes maintain the file structure and coding practices consistent with NextJS conventions. The use of TypeScript throughout the file, including the recent changes, ensures type safety and improves code maintainability. The component efficiently manages state using React hooks and follows NextJS routing practices.

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

36-36: LGTM: Import statement for Subpoena type.

The import statement for the Subpoena type is correctly placed and necessary for the changes in the getSubpoenaPdf method.

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

Line range hint 1042-1073: LGTM! Comprehensive indictment case retrieval.

The getIndictmentCase function is well-implemented. It efficiently retrieves an indictment case along with its related data, including defendants, subpoenas, court, prosecutor's office, judge, prosecutor, and date logs. The error handling for a non-existent case is appropriate.


Line range hint 1075-1084: LGTM! Efficient indictment counting.

The countIndictmentsWaitingForConfirmation function is well-implemented. It efficiently counts indictments in the 'WAITING_FOR_CONFIRMATION' state for a specific prosecutor's office. The query is correctly structured with appropriate filters.


Line range hint 1-1084: Overall assessment: Code changes look good.

The modifications in this file, particularly the import change for the Subpoena model and the implementation of getIndictmentCase and countIndictmentsWaitingForConfirmation functions, are well-executed. These changes seem to be part of a larger feature addition or refactoring related to subpoenas. The code maintains good practices in terms of error handling, query structuring, and function naming.


61-61: LGTM! Verify import change impact.

The import statement for the Subpoena model has been simplified. This change looks good, but ensure that it doesn't affect how the Subpoena model is used throughout this file.

✅ Verification successful

Import change verified and appears safe.

The simplified import statement for the Subpoena model is correctly referencing the model, and its usages within the file remain unaffected.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any usage of Subpoena in this file that might be affected by the import change.
rg --type typescript "Subpoena" apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts

Length of output: 140


Script:

#!/bin/bash
# Description: Retry checking for any usage of Subpoena in TypeScript files with corrected file type.
rg --type ts "Subpoena" apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts

Length of output: 167

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

37-39: Avoid exposing sensitive information in error messages

The error message includes defendant.id, which may contain sensitive information. To prevent potential PII leakage, consider omitting defendant.id from the error message.

[security]

Apply this diff to modify the error message:

throw new BadRequestException(
-  `Subpoena ${subpoenaId} of defendant ${defendant.id} does not exist`,
+  `Subpoena ${subpoenaId} does not exist for the specified defendant`,
)
apps/judicial-system/backend/src/app/modules/subpoena/limitedAccessSubpoena.controller.ts (2)

79-81: Confirm Logging Message Handles Undefined subpoenaId Correctly

The logging statement uses subpoenaId ?? 'draft', which substitutes 'draft' when subpoenaId is undefined. Please confirm that this meets the requirements for logging and that it provides sufficient information for debugging purposes.


50-50: Verify the Usage of SubpoenaExistsOptionalGuard

Please verify that the inclusion of SubpoenaExistsOptionalGuard in the @UseGuards array aligns with the intended behavior of the controller. Ensure that this guard appropriately handles scenarios when a subpoena may not exist and that downstream logic accounts for this possibility.

Run the following script to check for consistent usage of SubpoenaExistsOptionalGuard across the codebase:

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

1-110: ⚠️ Potential issue

Inconsistency between coding guidelines and project structure

The coding guidelines specify NextJS best practices for files matching the pattern apps/**/*. However, this file is part of a NestJS backend application. Please ensure that the appropriate coding guidelines for NestJS are applied to this code segment to maintain consistency and adhere to best practices for the framework in use.

⛔ Skipped due to learnings
Learnt from: unakb
PR: island-is/island.is#16132
File: apps/judicial-system/digital-mailbox-api/src/app/modules/cases/models/subpoena.response.ts:79-80
Timestamp: 2024-09-24T11:31:03.418Z
Learning: Subpoenas are already ordered by date in the backend.
apps/judicial-system/web/src/routes/Court/components/SubpoenaType/SubpoenaType.tsx (3)

20-24: Good implementation of extended subpoenaItems type

The updated subpoenaItems type adds flexibility by allowing additional properties (disabled and children) per item. This enhances the component's capability to handle more complex scenarios.


Line range hint 1-107: Adherence to NextJS and TypeScript best practices

The component follows React and TypeScript best practices, utilizing functional components and proper typing. Ensure that it integrates smoothly within the NextJS framework, especially with regards to server-side rendering and static generation if applicable.


42-106: Verify state updates with the new subpoenaItems structure

Ensure that the updateDefendantState function and any related state management accommodate the changes to subpoenaItems and properly update the state based on the new data structure.

Run the following script to check for usages of updateDefendantState:

✅ Verification successful

State updates correctly handle the new subpoenaItems structure

The updateDefendantState function is properly implemented across all relevant files and accommodates the changes to subpoenaItems, ensuring that state updates function as expected.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all calls to updateDefendantState handle the new structure.

# Search for all usages of updateDefendantState in TypeScript files.
rg --type ts 'updateDefendantState' -A 5 -B 5

Length of output: 42564


Script:

#!/bin/bash
# Description: Find the definition of updateDefendantState to verify its implementation.

# Search for the definition of updateDefendantState in TypeScript files.
rg --type ts 'const updateDefendantState\s*='

Length of output: 419


Script:

#!/bin/bash
# Description: Extract the definitions of updateDefendantState from identified TypeScript files.

files=(
  "apps/judicial-system/web/src/routes/Prosecutor/RestrictionCase/Defendant/Defendant.tsx"
  "apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Defendant/Defendant.tsx"
  "apps/judicial-system/web/src/utils/hooks/useDefendants/index.ts"
)

for file in "${files[@]}"; do
  echo "=== Extracting updateDefendantState from $file ==="
  rg --type ts 'const updateDefendantState\s*=' "$file" -C 10
  echo ""
done

Length of output: 3553

apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx (1)

76-78: LGTM

The implementation correctly checks if any defendant has subpoenas associated with them. The use of optional chaining and the some method ensures safe and efficient evaluation.

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

33-33: State management enhancement approved

The addition of the newSubpoenas state variable using useState<string[]>([]) appropriately handles the tracking of new subpoenas.

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

41-41: Approved: Importing Subpoena model

The Subpoena model is correctly imported and ready for use.


174-189: Verify ordering behavior when using separate: true

When separate: true is used in includes, the order clause within the include may not be applied as expected. This can lead to the included models not being ordered correctly. Verify that the defendants and subpoenas are ordered as intended in the fetched data.

apps/judicial-system/backend/src/app/modules/case/test/caseController/update.spec.ts (2)

884-887: Verify the Structure of 'defendants' with 'subpoenas'

The updatedCase object now includes a defendants array with each defendant having a subpoenas array. Ensure that this structure aligns with the expected data model and that all related functionality correctly handles this nested data.


910-921: Validate Message Queue Parameters

In the test assertion, elementId is set as an array [defendantId1, subpoenaId1] and [defendantId2, subpoenaId2]. Confirm that the sendMessagesToQueue function expects elementId to be an array in this format and that this change is consistent with the updated messaging logic.

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

65-65: Importing Subpoena and SubpoenaService is appropriate

The new feature requires the use of Subpoena and SubpoenaService, and importing them here is necessary.


430-430: Injecting SubpoenaService is appropriate

The subpoenaService is needed for handling subpoenas, and injecting it here follows good dependency injection practices.


1176-1199: New method addMessagesForNewSubpoenasToQueue is implemented correctly

The method appropriately identifies defendants with new subpoenas and sends messages accordingly. The use of optional chaining prevents errors due to undefined values.


1376-1379: Adding the call to addMessagesForNewSubpoenasToQueue is appropriate

Including this call ensures that messages are sent when new subpoenas are created due to scheduling a new arraignment date.


1658-1669: New condition variables are defined correctly

The variables completingIndictmentCaseWithoutRuling and schedulingNewArraignmentDateForIndictmentCase are correctly defined to capture the required conditions.


1686-1701: Properly handling the result of the update operation

The code correctly checks the number of affected rows after the update operation and handles unexpected cases appropriately by logging or throwing an exception.


1727-1738: Correctly deleting ruling files when completing indictment case without ruling

The code appropriately deletes ruling files when an indictment case is completed without a ruling, ensuring no incorrect files remain associated with the case.


1740-1754: Creating new subpoenas when scheduling a new arraignment date

The code correctly creates new subpoenas for each defendant when a new arraignment date is scheduled for an indictment case.

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/modules/subpoena/models/subpoena.model.ts (1)

Line range hint 1-78: Overall, excellent improvements to the Subpoena model.

The changes to this file enhance the Subpoena model with additional necessary fields (arraignmentDate and location) and improve type correctness (acknowledged as boolean). All modifications adhere to NextJS best practices and make good use of TypeScript for type safety.

As these changes modify the Subpoena model structure, ensure that:

  1. Any components or services interacting with Subpoena instances are updated to handle the new properties.
  2. API endpoints that create or update Subpoena instances validate the new required fields.
  3. The frontend is updated to display and handle the new information (arraignment date and location).
  4. Any existing unit or integration tests are updated to include the new properties.

Consider running a search for usages of the Subpoena model throughout the codebase to identify areas that might need updates:

#!/bin/bash
# Search for Subpoena usages in TypeScript files
rg --type typescript 'Subpoena'

This will help ensure that the changes are consistently applied across the application.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9d0bb0f and 331ea57.

📒 Files selected for processing (3)
  • apps/judicial-system/api/src/app/modules/defendant/models/subpoena.model.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/case/case.service.ts (8 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/models/subpoena.model.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/judicial-system/api/src/app/modules/defendant/models/subpoena.model.ts
  • apps/judicial-system/backend/src/app/modules/case/case.service.ts
🧰 Additional context used
📓 Path-based instructions (1)
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."
📓 Learnings (1)
apps/judicial-system/backend/src/app/modules/subpoena/models/subpoena.model.ts (1)
Learnt from: gudjong
PR: island-is/island.is#16168
File: apps/judicial-system/api/src/app/modules/defendant/models/subpoena.model.ts:14-30
Timestamp: 2024-09-30T08:07:12.456Z
Learning: In the Subpoena model, fields other than `acknowledged` are intended to be of type `string`.
🔇 Additional comments (4)
apps/judicial-system/backend/src/app/modules/subpoena/models/subpoena.model.ts (4)

52-54: LGTM! Implemented past suggestion correctly.

The changes to the caseId property are well-implemented. You've correctly added allowNull: false to the @Column decorator and marked the property as non-nullable in TypeScript. This ensures consistency between the TypeScript type and the database schema, addressing the concern raised in the previous review.


72-74: LGTM! Well-defined new property.

The addition of the arraignmentDate property is well-implemented. It's correctly defined as a non-nullable Date type in both TypeScript and the database schema. The use of @ApiProperty for API documentation is appropriate for this required field.


76-78: LGTM! Well-defined new property.

The addition of the location property is well-implemented. It's correctly defined as a non-nullable string type in both TypeScript and the database schema. The use of @ApiProperty for API documentation is appropriate for this required field. This implementation aligns with the learning note about fields other than 'acknowledged' being of type string.


62-62: LGTM! Consider updating the learning note.

The change of the acknowledged property from string to boolean is a good improvement. It's more appropriate for representing an acknowledgment status. This change aligns with the learning note that states fields other than 'acknowledged' should be of type string.

To ensure consistency, let's verify if there are any other occurrences of acknowledged as a string type:

Also, consider updating the learning note to reflect this change explicitly.

✅ Verification successful

Verification passed!

No other instances of the acknowledged property use the string type. The change to boolean is consistently applied across the codebase. Please proceed with updating the learning note.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for 'acknowledged' property declarations
rg --type typescript 'acknowledged.*:.*string' -g '!**/subpoena.model.ts'

Length of output: 110


Script:

#!/bin/bash
# Search for 'acknowledged' property declarations with type 'string' excluding subpoena.model.ts
rg 'acknowledged\s*:\s*string' -g '*.ts' -g '!**/subpoena.model.ts'

Length of output: 69

Copy link
Member

@oddsson oddsson left a comment

Choose a reason for hiding this comment

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

Nice! Just had a couple of comments

@oddsson oddsson added the automerge Merge this PR as soon as all checks pass label Sep 30, 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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 331ea57 and 22d975f.

📒 Files selected for processing (4)
  • apps/judicial-system/backend/src/app/modules/subpoena/internalSubpoena.controller.ts (3 hunks)
  • apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx (3 hunks)
  • apps/judicial-system/web/src/routes/Court/Indictments/Subpoena/Subpoena.tsx (7 hunks)
  • apps/judicial-system/web/src/routes/Court/components/SubpoenaType/SubpoenaType.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • apps/judicial-system/backend/src/app/modules/subpoena/internalSubpoena.controller.ts
  • apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx
  • apps/judicial-system/web/src/routes/Court/components/SubpoenaType/SubpoenaType.tsx
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/web/src/routes/Court/Indictments/Subpoena/Subpoena.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."
🪛 Biome
apps/judicial-system/web/src/routes/Court/Indictments/Subpoena/Subpoena.tsx

[error] 158-203: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

🔇 Additional comments (1)
apps/judicial-system/web/src/routes/Court/Indictments/Subpoena/Subpoena.tsx (1)

Line range hint 1-213: Overall code changes are well-implemented

The code changes align with the PR objectives and adhere to the project's coding guidelines. The use of React hooks for state management is appropriate, and TypeScript types are utilized effectively for component and utility type safety.

🧰 Tools
🪛 Biome

[error] 158-203: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

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 (3)
apps/judicial-system/backend/src/app/modules/subpoena/test/subpoenaController/getSubpoenaPdf.spec.ts (3)

16-16: LGTM: Test setup updated correctly with a minor suggestion

The test description and variable declarations have been appropriately updated to reflect the focus on SubpoenaController and Subpoena model.

However, consider using type guards or constructors instead of type assertions (e.g., as Subpoena) for better type safety. For example:

const subpoena: Subpoena = { id: subpoenaId };
const defendant: Defendant = { id: defendantId, subpoenas: [subpoena] };

This approach provides better type checking at compile-time.

Also applies to: 18-19, 21-21


40-43: LGTM: Controller method call updated correctly with a suggestion for improvement

The method call has been correctly updated to use subpoenaController.getSubpoenaPdf with the new required parameters.

However, consider using an object with named parameters for better readability and maintainability, especially given the high number of parameters. For example:

await subpoenaController.getSubpoenaPdf({
  caseId,
  defendantId,
  subpoenaId,
  case: theCase,
  defendant,
  res,
  subpoena,
});

This approach would make the function call more self-documenting and easier to modify in the future.

Also applies to: 47-47


66-66: LGTM: Expect statement correctly updated

The expect statement has been appropriately updated to include the subpoena parameter in the call to mockPdfService.getSubpoenaPdf.

Consider adding a comment or using more descriptive variable names for the undefined parameters to improve clarity. For example:

expect(mockPdfService.getSubpoenaPdf).toHaveBeenCalledWith(
  theCase,
  defendant,
  subpoena,
  undefined, // optionalParam1
  undefined, // optionalParam2
  undefined, // optionalParam3
);

This would make the purpose of these parameters more clear to other developers.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 20bf0f1 and 49b739c.

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

4-4: LGTM: Import statements updated correctly

The import statements have been appropriately updated to reflect the shift from LimitedAccessDefendant to Subpoena. The specific imports for createTestingSubpoenaModule and the Subpoena model align well with TypeScript best practices.

Also applies to: 7-8


29-30: LGTM: Test setup correctly updated

The beforeEach setup has been appropriately updated to use createTestingSubpoenaModule and destructure subpoenaController. This change aligns well with the shift in focus to the Subpoena model and maintains good TypeScript practices.

@oddsson oddsson added automerge Merge this PR as soon as all checks pass and removed automerge Merge this PR as soon as all checks pass labels Sep 30, 2024
@kodiakhq kodiakhq bot merged commit 2197961 into main Sep 30, 2024
36 checks passed
@kodiakhq kodiakhq bot deleted the j-s/indictment-case-new-subpoena branch September 30, 2024 21:58
thoreyjona pushed a commit that referenced this pull request Oct 2, 2024
* Locks subpoena fields when arraignment date has been set

* Move arraignment date message handling to the server side

* Updates tests and fixes date comparison

* Schedules new subpoenas

* Enforces operation ordering

* Only sends query parameters with new subpoena requests

* Supports multiple subpoenas per defendant

* Updates unit tests

* Updates unit test

* Fixes some typs and null reference guards

* Improved type declaration

* Improved date formatting

* Improves indexing

* Fixes spelling

* Fixes indexing

* Fixes optional arguments

* Removes redundant constructor

* Fix tests

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Ívar Oddsson <ivaroddsson@gmail.com>
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