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): New endpoint to update signature page number #16163

Merged
merged 3 commits into from
Sep 26, 2024

Conversation

juni-haukur
Copy link
Member

@juni-haukur juni-haukur commented Sep 26, 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 updating signature collection page numbers.
    • Added a mutation method to update the page number of a signature in the collection.
    • Implemented two new API endpoints for updating the page number of written recommendations.
    • Updated the schema to include a new required property for recommendations.
  • Bug Fixes

    • Enhanced error handling for API responses related to page number updates.

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

coderabbitai bot commented Sep 26, 2024

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

📥 Commits

Files that changed from the base of the PR and between c962865 and 7926efd.

📒 Files selected for processing (1)
  • libs/clients/signature-collection/src/lib/signature-collection.service.spec.ts (5 hunks)
______________________________
< Carpe Debug. Seize the bugs. >
------------------------------
 \
  \   (\__/)
      (•ㅅ•)
      /   づ

Walkthrough

A new feature has been implemented to allow the updating of the page number for signatures in the signature collection. This includes the introduction of a new input type class SignatureCollectionSignatureUpdateInput, a mutation method in the resolver, and a corresponding service method. Additionally, two new API endpoints have been created to facilitate this functionality, along with updates to relevant data schemas.

Changes

File Change Summary
libs/api/domains/signature-collection/src/lib/dto/signatureUpdate.input.ts Added a new input type class SignatureCollectionSignatureUpdateInput with a required pageNumber property.
libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts Introduced a mutation method signatureCollectionAdminUpdatePaperSignaturePageNumber to update the signature page number, utilizing the new input type.
libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.service.ts Added a method updateSignaturePageNumber to handle the logic for updating the signature page number based on user input.
libs/clients/signature-collection/src/clientConfig.json Introduced two new PATCH endpoints for updating the page number of recommendations and modified the SvaediDTO schema to include a new required property nr.
libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts Added an asynchronous method updateSignaturePageNumber to call the API for updating the page number of a signature.

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • albinagu

Tip

You can make CodeRabbit's review more strict using the `assertive` profile, if that's what you prefer.

Change the reviews.profile setting in your project's settings in CodeRabbit to assertive to make CodeRabbit's nitpick more issues in your PRs.


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: 1

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

7-9: Field declaration is correct, with a minor suggestion for improvement.

The pageNumber field is properly declared with appropriate decorators for GraphQL schema integration (@Field()) and validation (@IsNumber()). The use of TypeScript's non-null assertion operator ensures type safety. This implementation aligns well with the PR objective of updating the signature page number.

For improved clarity and to avoid potential runtime errors, consider using the @IsInt() decorator instead of @IsNumber() if the page number is expected to be an integer. Additionally, you might want to add a @Min(1) decorator to ensure the page number is positive. Here's a suggested improvement:

import { IsInt, Min } from 'class-validator'

// ...

@Field()
@IsInt()
@Min(1)
pageNumber!: number

This change would provide more precise validation for the pageNumber field.

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

181-190: LGTM: New method added correctly. Consider adding error handling.

The updateSignaturePageNumber method is well-implemented and consistent with the existing code style and patterns. It correctly uses the new input type and delegates to the client service.

Consider adding error handling to catch and properly handle any exceptions that might be thrown by the client service. For example:

async updateSignaturePageNumber(
  user: User,
  input: SignatureCollectionSignatureUpdateInput,
): Promise<SignatureCollectionSuccess> {
  try {
    return await this.signatureCollectionClientService.updateSignaturePageNumber(
      user,
      input.signatureId,
      input.pageNumber,
    );
  } catch (error) {
    // Log the error
    console.error('Error updating signature page number:', error);
    // Rethrow or handle as appropriate for your use case
    throw new Error('Failed to update signature page number');
  }
}

This would improve the robustness of the method and provide better debugging information in case of failures.

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

297-314: LGTM with a suggestion for improved error handling

The new updateSignaturePageNumber method is well-implemented and follows good practices for TypeScript usage and error handling. It adheres to the coding guidelines for files in the libs/**/* path pattern.

To further improve the method, consider enhancing the error case to provide more information about the failure reason. This could help with debugging and provide more context to the caller.

Consider modifying the catch block to include more information:

} catch (error) {
  console.error('Failed to update signature page number:', error);
  return { success: false, reason: 'Failed to update signature page number' };
}
libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts (1)

246-256: LGTM: New mutation method is well-structured and consistent with existing patterns.

The new signatureCollectionAdminUpdatePaperSignaturePageNumber method is correctly implemented as a GraphQL mutation. It follows the existing patterns in the class, uses TypeScript for type definitions, and maintains a clear separation of concerns by delegating the actual work to the service layer.

For consistency with other methods in this class, consider adding the @Scopes() decorator to explicitly define the required scopes for this mutation.

@Mutation(() => SignatureCollectionSuccess)
@Audit()
@Scopes(AdminPortalScope.signatureCollectionProcess) // Add this line
async signatureCollectionAdminUpdatePaperSignaturePageNumber(
  // ... rest of the method
)
libs/clients/signature-collection/src/clientConfig.json (2)

77-114: LGTM! Consider adding English translations for descriptions.

The new admin endpoint for updating the page number is well-structured and follows RESTful principles. The use of PATCH is appropriate for partial updates.

Consider adding English translations alongside the Icelandic descriptions to improve accessibility for non-Icelandic speaking developers who might work on this API in the future.

 "patch": {
   "tags": ["Admin"],
-  "summary": "Uppfærir blaðsíðunúmer skriflegs meðmælis",
-  "description": "Aðeins m0gulegt fyrir skrifleg meðmæli",
+  "summary": "Uppfærir blaðsíðunúmer skriflegs meðmælis (Updates the page number of a written recommendation)",
+  "description": "Aðeins m0gulegt fyrir skrifleg meðmæli (Only possible for written recommendations)",
   ...
 }

1763-1800: LGTM! Maintain consistency with admin endpoint improvements.

The new user endpoint for updating the page number is well-structured and consistent with the admin endpoint. This consistency is good for maintainability and understanding of the API.

For consistency with the suggested improvement for the admin endpoint, consider adding English translations alongside the Icelandic descriptions:

 "patch": {
   "tags": ["Medmaeli"],
-  "summary": "Uppfærir blaðsíðunúmer skriflegs meðmælis",
-  "description": "Aðeins m0gulegt fyrir skrifleg meðmæli",
+  "summary": "Uppfærir blaðsíðunúmer skriflegs meðmælis (Updates the page number of a written recommendation)",
+  "description": "Aðeins m0gulegt fyrir skrifleg meðmæli (Only possible for written recommendations)",
   ...
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5828cef and c962865.

📒 Files selected for processing (5)
  • libs/api/domains/signature-collection/src/lib/dto/signatureUpdate.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/clientConfig.json (3 hunks)
  • libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
libs/api/domains/signature-collection/src/lib/dto/signatureUpdate.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/clientConfig.json (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 (8)
libs/api/domains/signature-collection/src/lib/dto/signatureUpdate.input.ts (3)

1-3: Imports look good and follow guidelines.

The imports are correctly specified and necessary for the functionality of the class. They adhere to the TypeScript usage guidelines mentioned in the coding guidelines for the libs directory.


5-6: Class definition adheres to guidelines and promotes reusability.

The SignatureCollectionSignatureUpdateInput class is well-defined using the @InputType() decorator from NestJS. Extending SignatureCollectionSignatureIdInput promotes code reusability, which aligns with the coding guidelines for the libs directory. The naming convention is clear and descriptive, enhancing maintainability.


1-10: Overall, excellent implementation that meets PR objectives and follows guidelines.

This new input type class for updating signature page numbers is well-implemented. It adheres to NestJS and TypeScript conventions, promotes code reusability, and aligns perfectly with the PR objectives. The code structure and use of decorators ensure proper GraphQL schema integration and basic validation.

The implementation follows the coding guidelines for the libs directory, particularly in terms of reusability and TypeScript usage. It's a valuable addition to the signature collection feature, allowing for the updating of signature page numbers as intended.

Consider the minor suggestion for improving field validation in the previous comment to further enhance the robustness of this input type.

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

24-24: LGTM: New import added correctly.

The new import for SignatureCollectionSignatureUpdateInput is correctly added and follows the existing conventions in the file.


Line range hint 1-190: Overall assessment: Changes are well-implemented and consistent with best practices.

The new code adheres to the coding guidelines for libs/**/*:

  • It maintains reusability across different NextJS apps.
  • TypeScript is used effectively for type definitions.
  • The changes don't negatively impact tree-shaking or bundling practices.

The new method and import are consistent with the existing code style and patterns in the file. The only suggestion for improvement is to consider adding error handling to the new method.

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

37-37: LGTM: Import statement is well-structured and follows TypeScript conventions.

The import statement is correctly using TypeScript for defining types and follows proper naming conventions. It's imported from a local file, which is good for modularity.


37-37: Compliance with coding guidelines for libs/**/* files confirmed.

The changes in this file adhere to the specified coding guidelines:

  1. The new method enhances the reusability of the resolver across different NextJS apps.
  2. TypeScript is correctly used for defining types in both the import statement and the new method.
  3. The local import and class-based structure support effective tree-shaking and bundling.

Also applies to: 246-256

libs/clients/signature-collection/src/clientConfig.json (1)

2281-2286: ⚠️ Potential issue

Breaking change detected. Clarification needed on new 'nr' field.

The SvaediDTO schema has been updated to include a new required property nr of type string. This is a breaking change that might affect existing clients.

  1. As this is a breaking change, ensure that all clients are updated to handle the new required field.
  2. The purpose of the nr field is not immediately clear. Consider adding a description to clarify its meaning and usage.
  3. If nr is intended to be a numeric identifier, consider using type "integer" instead of "string", unless there's a specific reason for using a string (e.g., leading zeros or non-numeric characters).

Please provide more context on the purpose and expected format of the nr field.

To check for potential impacts of this change, let's search for usages of the SvaediDTO schema:

✅ Verification successful

Breaking change detected within signature-collection library.

The SvaediDTO schema has been updated to include a new required property nr of type string. This change affects the libs/clients/signature-collection/src/clientConfig.json and libs/clients/signature-collection/src/lib/types/area.dto.ts.

  1. Ensure all internal components using SvaediDTO are updated to handle the new required nr field.
  2. Consider adding a description for the nr field in the schema to clarify its purpose and usage.
  3. Verify that the change does not inadvertently affect other parts of the application relying on signature-collection.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for files referencing SvaediDTO
echo "Files referencing SvaediDTO:"
rg --type typescript --type javascript "SvaediDTO"

# Search for API calls that might be affected
echo "\nPotential API calls affected:"
rg --type typescript --type javascript "api.*Svaedi"

Length of output: 315


Script:

#!/bin/bash
# Search for files referencing SvaediDTO without specifying file types
echo "Files referencing SvaediDTO:"
rg "SvaediDTO"

# Search for API calls that might be affected without specifying file types
echo "\nPotential API calls affected:"
rg "api.*Svaedi"

Length of output: 1085

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

codecov bot commented Sep 26, 2024

Codecov Report

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

Project coverage is 36.67%. Comparing base (a513759) to head (7926efd).
Report is 2 commits behind head on main.

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

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16163      +/-   ##
==========================================
- Coverage   36.69%   36.67%   -0.02%     
==========================================
  Files        6776     6769       -7     
  Lines      139581   139286     -295     
  Branches    39680    39573     -107     
==========================================
- Hits        51222    51086     -136     
+ Misses      88359    88200     -159     
Flag Coverage Δ
api 3.39% <ø> (ø)
application-system-api 41.63% <0.00%> (-0.01%) ⬇️
application-template-api-modules 23.71% <ø> (+0.01%) ⬆️
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.76% <0.00%> (-0.67%) ⬇️

... and 52 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 4cb5e52...7926efd. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 26, 2024

Datadog Report

All test runs 611cbc2 🔗

4 Total Test Services: 0 Failed, 4 Passed
🔻 Test Sessions change in coverage: 4 decreased, 6 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.95s 1 no change Link
application-system-api 0 0 0 111 2 3m 30.13s 1 decreased (-0.02%) Link
application-template-api-modules 0 0 0 109 0 1m 47.65s 1 decreased (-0.01%) Link
application-ui-shell 0 0 0 74 0 33.88s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (4)

  • clients-signature-collection - jest 0% (-22.9%) - Details
  • api-domains-signature-collection - jest 13.31% (-0.2%) - Details
  • application-system-api - jest 37.1% (-0.02%) - Details
  • application-template-api-modules - jest 25.7% (-0.01%) - Details

@kodiakhq kodiakhq bot merged commit 60a4187 into main Sep 26, 2024
38 checks passed
@kodiakhq kodiakhq bot deleted the feat/update-signature-endpoint branch September 26, 2024 14:43
thoreyjona pushed a commit that referenced this pull request Oct 2, 2024
…ber (#16163)

* New endpoint to update signature page number

* Fix tests after client update

---------

Co-authored-by: albinagu <[email protected]>
Co-authored-by: kksteini <[email protected]>
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.

3 participants