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

fix(signature-collection): Fix admin paper signature upload #16500

Merged
merged 3 commits into from
Oct 22, 2024

Conversation

juni-haukur
Copy link
Member

@juni-haukur juni-haukur commented Oct 22, 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 method to upload paper signatures within the admin interface.
    • Enhanced error handling in the Paper Signees component to provide feedback based on upload success or failure.
  • Bug Fixes

    • Updated mutation name for clarity, ensuring consistent naming conventions.

@juni-haukur juni-haukur requested a review from a team as a code owner October 22, 2024 09:17
Copy link
Contributor

coderabbitai bot commented Oct 22, 2024

Walkthrough

The pull request introduces a new mutation method signatureCollectionAdminUploadPaperSignature to the SignatureCollectionAdminResolver, enabling the upload of paper signatures. Corresponding changes are made in the SignatureCollectionAdminService to include a new method uploadPaperSignature, which processes the upload request. Additionally, updates are made to the client service and GraphQL schema to reflect these changes. The error handling in the client component is also enhanced to provide feedback based on the mutation's success. Overall, the modifications focus on adding functionality for managing paper signature uploads.

Changes

File Change Summary
libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts - Added method signatureCollectionAdminUploadPaperSignature for uploading paper signatures.
- Imported SignatureCollectionUploadPaperSignatureInput.
libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.service.ts - Added method uploadPaperSignature for handling paper signature uploads.
- Updated logic in getCanSignInfo method for determining signing eligibility.
libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts - Added method uploadPaperSignature for client-side handling of paper signature uploads.
- Updated imports for error handling.
libs/clients/signature-collection/src/lib/types/bulkUpload.dto.ts - Added function getReasonKeyForPaperSignatureUpload for retrieving reason keys based on upload response.
- Imported ReasonKey.
libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/index.tsx - Modified onCompleted callback to include conditional success/error handling for the upload mutation.
libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/uploadPaperSignee.graphql - Renamed mutation from signatureCollectionUploadPaperSignature to signatureCollectionAdminUploadPaperSignature.

Possibly related PRs

Suggested reviewers

  • 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.

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 (6)
libs/clients/signature-collection/src/lib/types/bulkUpload.dto.ts (1)

53-76: LGTM: Well-implemented function with good type safety and reusability.

The getReasonKeyForPaperSignatureUpload function is well-structured, type-safe, and potentially reusable across different NextJS apps dealing with signature collection. It effectively maps the bulk response to reason keys.

Minor suggestion for improved type safety:

Consider using a type assertion for listMapping to ensure all keys are accounted for:

const listMapping: { [K in keyof MedmaeliBulkResponseDTO]?: ReasonKey } = {
  // ... (rest of the mapping)
} as const;

This change would make the type system catch any missing or extra keys in the mapping.

libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/index.tsx (1)

72-77: Improved error handling, consider destructuring for clarity.

The changes enhance error handling by providing specific feedback based on the mutation's success status. This improvement aligns well with best practices for user experience.

Consider destructuring the response for improved readability:

onCompleted: ({ signatureCollectionAdminUploadPaperSignature }) => {
  if (signatureCollectionAdminUploadPaperSignature?.success) {
    toast.success(formatMessage(m.paperSigneeSuccess))
  } else {
    toast.error(formatMessage(m.paperSigneeError))
  }
  // ... rest of the code
},

This change would make the code slightly more concise and easier to read.

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

70-77: LGTM: Improved logic for determining signing eligibility.

The changes enhance the clarity and specificity of the getCanSignInfo method. The introduction of the inArea variable and its incorporation into the success and reasons properties provide more accurate feedback.

Consider adding a comment explaining the logic behind the canSign condition, as it's quite complex:

// A user can sign if they meet the general criteria or if their only restriction
// is a previous signature (which doesn't prevent paper signatures)
const canSign =
  signatureSignee.canSign ||
  (signatureSignee.canSignInfo?.length === 1 &&
    (signatureSignee.canSignInfo[0] === ReasonKey.AlreadySigned ||
      signatureSignee.canSignInfo[0] === ReasonKey.noInvalidSignature))

255-263: LGTM: New method for uploading paper signatures.

The uploadPaperSignature method is a well-structured addition to the service, consistent with the existing patterns and purpose of the class.

For consistency with other methods in the class, consider reordering the parameters to have user first:

async uploadPaperSignature(
  user: User,
  input: SignatureCollectionUploadPaperSignatureInput
): Promise<SignatureCollectionSuccess> {
  return await this.signatureCollectionClientService.uploadPaperSignature(
    user,
    input
  )
}
libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts (1)

292-299: LGTM: New mutation method is well-implemented.

The signatureCollectionAdminUploadPaperSignature method is correctly implemented and follows the existing patterns in the class. It's properly decorated and uses dependency injection as expected.

For consistency with other methods in this class, consider adding the @Scopes() decorator to specify which admin scopes are allowed to use this mutation.

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

407-448: LGTM: New method uploadPaperSignature is well-implemented.

The method follows the established patterns in the class, uses proper authentication, and handles errors appropriately. It adheres to TypeScript usage for defining props and returns a well-structured Success object.

Consider enhancing the error handling by logging the error or providing more specific error information:

-    } catch {
+    } catch (error) {
+      console.error('Error uploading paper signature:', error);
       return {
         success: false,
-        reasons: [ReasonKey.DeniedByService],
+        reasons: [ReasonKey.DeniedByService, error.message],
       }
     }

This change would provide more context for debugging while maintaining the existing error response structure.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 11b480a and 6bd0273.

📒 Files selected for processing (6)
  • libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts (2 hunks)
  • libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.service.ts (3 hunks)
  • libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts (2 hunks)
  • libs/clients/signature-collection/src/lib/types/bulkUpload.dto.ts (2 hunks)
  • libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/index.tsx (1 hunks)
  • libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/uploadPaperSignee.graphql (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
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."
libs/clients/signature-collection/src/lib/types/bulkUpload.dto.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/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/index.tsx (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/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/uploadPaperSignee.graphql (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 (8)
libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/uploadPaperSignee.graphql (1)

4-4: Approved: Mutation name change improves consistency

The change from signatureCollectionUploadPaperSignature to signatureCollectionAdminUploadPaperSignature aligns with the new method introduced in the SignatureCollectionAdminResolver class. This improves consistency across the codebase and clearly indicates that this mutation is for admin use.

The mutation structure remains reusable and compatible with TypeScript type generation, adhering to the coding guidelines for files in the libs directory.

libs/clients/signature-collection/src/lib/types/bulkUpload.dto.ts (1)

2-2: LGTM: Import statement is correct and necessary.

The import of ReasonKey is appropriate for the new function and follows TypeScript best practices.

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

28-31: LGTM: Import changes are appropriate.

The addition of SignatureCollectionUploadPaperSignatureInput to the existing import statement is consistent with the new uploadPaperSignature method and follows the established import structure.


Line range hint 1-263: Overall: Well-implemented changes for paper signature upload functionality.

The modifications to this file effectively introduce the capability to upload paper signatures while maintaining consistency with the existing codebase. The changes adhere to the coding guidelines for libs/**/* files:

  1. The new functionality is reusable across different NextJS apps.
  2. TypeScript is used appropriately for defining props and exporting types.
  3. The changes maintain the existing structure, promoting effective tree-shaking and bundling practices.

The enhancements to the getCanSignInfo method and the addition of the uploadPaperSignature method improve the overall functionality of the signature collection admin service.

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

39-39: LGTM: Import statement is correctly added.

The new import statement for SignatureCollectionUploadPaperSignatureInput is properly placed and follows TypeScript naming conventions. It's necessary for the new mutation method.


39-39: Overall, the changes look good and add new functionality.

The addition of the SignatureCollectionUploadPaperSignatureInput import and the signatureCollectionAdminUploadPaperSignature mutation method effectively implements the new functionality for uploading paper signatures. The changes are minimal, focused, and consistent with the existing code patterns and structure.

These modifications enhance the signature collection process by allowing admin users to upload paper signatures, which aligns with the PR objectives of fixing the admin paper signature upload.

Also applies to: 292-299

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

19-23: LGTM: Import changes are appropriate.

The addition of getReasonKeyForPaperSignatureUpload from ./types/bulkUpload.dto is relevant to the new functionality and follows good practices by importing only what's needed.


Line range hint 1-448: Overall, the changes are well-implemented and adhere to coding guidelines.

The additions to this file enhance the functionality of the SignatureCollectionAdminClientService while maintaining consistency with the existing code structure. The new uploadPaperSignature method is implemented in a way that ensures reusability across different NextJS apps. The use of TypeScript for defining props and the overall structure of the service class contribute to effective tree-shaking and bundling practices.

@juni-haukur juni-haukur added the automerge Merge this PR as soon as all checks pass label Oct 22, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts (1)

431-472: LGTM: The uploadPaperSignature method is well-implemented.

The new method follows the existing coding style, uses proper error handling, and is consistent with the class's purpose. Great job!

A minor suggestion for improved type safety:

Consider using a type alias for the input object to make the method signature more readable and maintainable:

type UploadPaperSignatureInput = {
  listId: string;
  nationalId: string;
  pageNumber: number;
};

async uploadPaperSignature(
  auth: Auth,
  { listId, nationalId, pageNumber }: UploadPaperSignatureInput
): Promise<Success> {
  // ... existing implementation
}

This change would make it easier to reuse the input type if needed elsewhere and improve code readability.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6bd0273 and 80cfb07.

📒 Files selected for processing (3)
  • libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts (2 hunks)
  • libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/index.tsx (2 hunks)
  • libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/uploadPaperSignee.graphql (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/index.tsx
  • libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/uploadPaperSignee.graphql
🧰 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."
🔇 Additional comments (2)
libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts (2)

19-23: LGTM: New imports are consistent with the added functionality.

The new imports from './types/bulkUpload.dto' are appropriate for the new uploadPaperSignature method and follow the existing import style in the file.


Line range hint 1-472: Overall, the changes in this file are well-implemented and enhance the functionality.

The new uploadPaperSignature method is a valuable addition to the SignatureCollectionAdminClientService class. It follows the existing coding patterns, uses proper error handling, and is consistent with the file's purpose. The changes adhere to the coding guidelines for reusability and TypeScript usage.

To ensure the new method is properly integrated, please run the following verification script:

This script will help identify any places where the new method might need to be integrated or where it's already being used.

✅ Verification successful

uploadPaperSignature method is properly integrated and utilized across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of the new uploadPaperSignature method

# Test: Check if the new method is exported and used in other parts of the codebase
rg -p "uploadPaperSignature" --type ts

Length of output: 1285

Copy link

codecov bot commented Oct 22, 2024

Codecov Report

Attention: Patch coverage is 13.63636% with 19 lines in your changes missing coverage. Please review.

Project coverage is 36.77%. Comparing base (9c1d3f1) to head (80cfb07).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...tion/src/lib/signature-collection-admin.service.ts 7.69% 12 Missing ⚠️
...gnature-collection/src/lib/types/bulkUpload.dto.ts 22.22% 7 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16500      +/-   ##
==========================================
- Coverage   36.77%   36.77%   -0.01%     
==========================================
  Files        6847     6847              
  Lines      141850   141871      +21     
  Branches    40417    40422       +5     
==========================================
+ Hits        52165    52167       +2     
- Misses      89685    89704      +19     
Flag Coverage Δ
api 3.37% <ø> (ø)
application-system-api 41.34% <13.63%> (-0.02%) ⬇️
application-template-api-modules 27.81% <ø> (+0.01%) ⬆️
application-ui-shell 21.36% <ø> (ø)

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

Files with missing lines Coverage Δ
...gnature-collection/src/lib/types/bulkUpload.dto.ts 11.11% <22.22%> (+5.55%) ⬆️
...tion/src/lib/signature-collection-admin.service.ts 11.11% <7.69%> (-0.95%) ⬇️

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 11b480a...80cfb07. Read the comment docs.

@datadog-island-is
Copy link

Datadog Report

All test runs e90007a 🔗

4 Total Test Services: 0 Failed, 4 Passed
🔻 Test Sessions change in coverage: 2 decreased, 1 increased (+0.01%), 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 2.61s 1 no change Link
application-system-api 0 0 0 120 2 3m 58.61s 1 no change Link
application-template-api-modules 0 0 0 123 0 2m 12.3s 1 increased (+0.01%) Link
application-ui-shell 0 0 0 74 0 30.04s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (2)

  • clients-signature-collection - jest 21.68% (-0.15%) - Details
  • api-domains-signature-collection - jest 12.15% (-0.1%) - Details

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