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(signature-collection): Signature lookup for admin #16232

Merged
merged 3 commits into from
Oct 3, 2024

Conversation

juni-haukur
Copy link
Member

@juni-haukur juni-haukur commented Oct 2, 2024

...

Attach a link to issue if relevant

What

Specify what you're trying to achieve

Why

Specify why you need to achieve this

Screenshots / Gifs

Attach Screenshots / Gifs to help reviewers understand the scope of the pull request

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 new input type for signature lookups, enhancing the ability to search for signatures based on collection and national IDs.
    • Added a new query method for users to perform signature lookups.
    • Expanded functionality to retrieve signatures while maintaining user permissions and auditing.
  • Bug Fixes

    • Updated method signatures for improved clarity and consistency.

@juni-haukur juni-haukur requested a review from a team as a code owner October 2, 2024 10:34
Copy link
Contributor

coderabbitai bot commented Oct 2, 2024

Walkthrough

A new input type class named SignatureCollectionSignatureLookupInput has been introduced to facilitate GraphQL operations for signature lookups. This class includes two required string properties: collectionId and nationalId. Additionally, a new query method signatureCollectionSignatureLookup has been added to the SignatureCollectionAdminResolver, which utilizes the new input type. Corresponding methods have also been implemented in the service and client service classes to handle the lookup functionality, ensuring consistent integration across the application.

Changes

File Change Summary
libs/api/domains/signature-collection/src/lib/dto/signatureLookup.input.ts - New input type class: SignatureCollectionSignatureLookupInput
- Properties added: collectionId, nationalId
libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts - Method added: signatureCollectionSignatureLookup for querying signatures using the new input type
libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.service.ts - Method added: signatureLookup for processing signature lookups using the new input type
libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts - Method added: signatureLookup for client-side signature lookups based on collection and national IDs

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • albinagu
  • kksteini

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.

@juni-haukur juni-haukur added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Oct 2, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
libs/api/domains/signature-collection/src/lib/dto/signatureLookup.input.ts (1)

6-11: LGTM: Property definitions are well-structured. Consider adding comments for clarity.

The collectionId and nationalId properties are correctly defined with appropriate decorators:

  • @Field() exposes them in the GraphQL schema.
  • @IsString() ensures proper validation.
  • The use of the definite assignment assertion (!) correctly indicates these fields are required.

This structure adheres to TypeScript best practices and supports effective GraphQL schema generation.

Consider adding brief comments to describe the purpose of each field, which could enhance code readability and maintainability. For example:

@Field()
@IsString()
collectionId!: string; // Unique identifier for the signature collection

@Field()
@IsString()
nationalId!: string; // National ID of the individual whose signature is being looked up
libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.service.ts (1)

201-210: LGTM: New signatureLookup method implemented correctly.

The new signatureLookup method is well-implemented and consistent with the existing code style and patterns in the class. It correctly uses async/await, maintains proper authentication by including the User parameter, and adheres to TypeScript usage for defining props and types.

Consider adding error handling to catch and properly handle any potential errors from the client service call. For example:

async signatureLookup(
  user: User,
  input: SignatureCollectionSignatureLookupInput,
): Promise<SignatureCollectionSignature[]> {
  try {
    return await this.signatureCollectionClientService.signatureLookup(
      user,
      input.collectionId,
      input.nationalId,
    );
  } catch (error) {
    // Log the error or handle it appropriately
    console.error('Error in signatureLookup:', error);
    throw error; // or return an empty array, depending on your error handling strategy
  }
}

This will improve the robustness of the method and make debugging easier in case of errors.

libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts (1)

331-353: Good implementation with room for improvement

The signatureLookup method is well-implemented, adhering to TypeScript usage and promoting code reuse. It effectively utilizes existing methods and APIs, contributing to the overall reusability of the codebase.

However, there are a few areas that could be improved:

  1. Error handling could be more specific. Currently, it catches all errors and returns an empty array, which might hide important issues.

  2. Input parameter validation is missing, which could lead to runtime errors if invalid inputs are provided.

Consider the following improvements:

  1. Implement more specific error handling:
try {
  // ... existing code ...
} catch (error) {
  console.error('Error in signatureLookup:', error);
  if (error instanceof ApiError) {
    // Handle API-specific errors
    return [];
  }
  throw error; // Re-throw unexpected errors
}
  1. Add input parameter validation:
if (!auth || !collectionId || !nationalId) {
  throw new Error('Missing required parameters');
}
if (typeof collectionId !== 'string' || typeof nationalId !== 'string') {
  throw new Error('Invalid parameter types');
}

These changes will improve the robustness and maintainability of the method.

libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts (1)

268-279: LGTM: New query method is well-structured and follows existing patterns.

The signatureCollectionSignatureLookup method is correctly implemented with appropriate decorators and TypeScript usage. It adheres to the coding guidelines for reusability and type safety.

For consistency with other methods in this class, consider adding a comment explaining the purpose of this new query method.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4d38b65 and 548a498.

📒 Files selected for processing (4)
  • libs/api/domains/signature-collection/src/lib/dto/signatureLookup.input.ts (1 hunks)
  • libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts (2 hunks)
  • libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.service.ts (2 hunks)
  • libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
libs/api/domains/signature-collection/src/lib/dto/signatureLookup.input.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.service.ts (1)

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

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

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments (6)
libs/api/domains/signature-collection/src/lib/dto/signatureLookup.input.ts (3)

1-2: LGTM: Import statements are concise and follow best practices.

The import statements are correctly importing only the necessary items from 'class-validator' and '@nestjs/graphql'. This approach supports effective tree-shaking and bundling practices.


4-5: LGTM: Class definition adheres to GraphQL and TypeScript best practices.

The SignatureCollectionSignatureLookupInput class is correctly defined as an exported GraphQL input type. The naming convention and use of the @InputType() decorator are appropriate. This structure supports reusability across different NextJS apps and proper TypeScript usage for GraphQL schemas.


1-12: Overall assessment: Well-structured and adheres to best practices.

This new file, signatureLookup.input.ts, successfully implements a GraphQL input type for signature lookup. It demonstrates:

  1. Proper use of TypeScript and GraphQL decorators.
  2. Adherence to coding guidelines for reusability across NextJS apps.
  3. Effective tree-shaking and bundling practices through specific imports.
  4. Clear and type-safe property definitions.

The implementation is correct, maintainable, and aligns well with the project's coding standards. The minor suggestion to add comments for each property is the only recommended improvement.

libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.service.ts (2)

25-26: LGTM: New imports added correctly.

The new imports for SignatureCollectionNationalIdInput and SignatureCollectionSignatureLookupInput are correctly added and follow the existing import style in the file. These imports suggest that new DTOs have been created for the signature lookup functionality, which is good for type safety and code organization.


Line range hint 1-210: Summary: Changes align well with PR objectives and coding guidelines.

The modifications to SignatureCollectionAdminService successfully enhance the signature lookup functionality for admin use, aligning with the PR objectives. The new signatureLookup method and its associated imports are well-implemented and consistent with the existing code style.

The changes adhere to the coding guidelines for libs/**/*:

  1. The code maintains reusability across different NextJS apps as it's part of a shared library.
  2. TypeScript is effectively used for defining props and types, enhancing type safety.
  3. The new method follows the existing patterns, which likely supports effective tree-shaking and bundling practices.

Overall, this is a well-implemented feature addition that maintains the quality and consistency of the codebase.

libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts (1)

38-38: LGTM: Import statement is correctly placed and follows the existing pattern.

The new import for SignatureCollectionSignatureLookupInput is appropriately added and aligns with the file's import structure.

Copy link

codecov bot commented Oct 2, 2024

Codecov Report

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

Project coverage is 36.88%. Comparing base (9af30c0) to head (3b51eba).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...tion/src/lib/signature-collection-admin.service.ts 0.00% 7 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16232      +/-   ##
==========================================
- Coverage   36.93%   36.88%   -0.05%     
==========================================
  Files        6781     6787       +6     
  Lines      140002   139907      -95     
  Branches    39809    39789      -20     
==========================================
- Hits        51703    51602     -101     
- Misses      88299    88305       +6     
Flag Coverage Δ
api 3.37% <ø> (ø)
application-system-api 41.63% <0.00%> (-0.01%) ⬇️
application-template-api-modules 24.40% <ø> (+0.03%) ⬆️
application-ui-shell 21.29% <ø> (ø)

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

Files with missing lines Coverage Δ
...tion/src/lib/signature-collection-admin.service.ts 13.28% <0.00%> (-0.77%) ⬇️

... and 48 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 37cd47a...3b51eba. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Oct 2, 2024

Datadog Report

All test runs 17e1a5a 🔗

4 Total Test Services: 0 Failed, 4 Passed
🔻 Test Sessions change in coverage: 2 decreased, 9 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 3.86s 1 no change Link
application-system-api 0 0 0 120 2 3m 12.58s 1 no change Link
application-template-api-modules 0 0 0 135 0 2m 1.77s 1 no change Link
application-ui-shell 0 0 0 74 0 35.33s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (2)

  • api-domains-signature-collection - jest 12.48% (-0.18%) - Details
  • clients-signature-collection - jest 22.11% (-0.07%) - Details

@kodiakhq kodiakhq bot removed the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Oct 2, 2024
Copy link
Contributor

kodiakhq bot commented Oct 2, 2024

This PR currently has a merge conflict. Please resolve this and then re-add the automerge label.

@juni-haukur juni-haukur added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Oct 3, 2024
@kodiakhq kodiakhq bot removed the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Oct 3, 2024
Copy link
Contributor

kodiakhq bot commented Oct 3, 2024

This PR currently has a merge conflict. Please resolve this and then re-add the automerge label.

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 548a498 and 782e435.

📒 Files selected for processing (3)
  • libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts (2 hunks)
  • libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.service.ts (2 hunks)
  • libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts
  • libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.service.ts
🧰 Additional context used
📓 Path-based instructions (1)
libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."

@juni-haukur juni-haukur added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants