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(endorsement-system): Export pdf template look #16184

Merged
merged 17 commits into from
Oct 9, 2024

Conversation

rafnarnason
Copy link
Member

@rafnarnason rafnarnason commented Sep 27, 2024

Improved layout for backend rendered pdf file
Screenshot 2024-10-08 at 13 36 59

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

    • Added instructions for setting AWS environment variables for local S3 testing in the Endorsements API README.
    • Introduced bulk endorsement creation functionality, allowing for the insertion of 50,000 records at once.
    • Enhanced PDF generation capabilities, including custom fonts, dynamic pagination, and improved layout for endorsement lists.
  • Bug Fixes

    • Streamlined the PDF generation process by removing outdated code.
  • Documentation

    • Updated README with clearer setup instructions for developers.

Copy link
Contributor

coderabbitai bot commented Sep 27, 2024

Walkthrough

This pull request introduces several modifications to the Endorsements API. Key changes include updates to the README.md file to clarify environment variable setup for local S3 testing. Additionally, the EndorsementService class now supports bulk creation of endorsements, allowing for the insertion of 50,000 records at once, while retaining existing functionality. The EndorsementListService class has also been updated to enhance PDF document generation, including custom fonts and dynamic content handling.

Changes

File Change Summary
apps/services/endorsements/api/README.md Added instructions for setting AWS environment variables for local S3 testing.
apps/services/endorsements/api/src/app/modules/endorsement/endorsement.service.ts Updated createEndorsementOnList to support bulk creation of 50,000 endorsements.
apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts Enhanced createDocumentBuffer to register custom fonts and handle dynamic PDF content.

Possibly related PRs

  • feat(endorsement-system): Endorsement count column index logic #15880: This PR involves changes to the endorsementList.service.ts file, which is also modified in the main PR. Both PRs deal with the endorsement system, indicating a potential relationship in terms of functionality and service logic.
  • feat(passport-application): Updated readme #16296: This PR updates the README.md file for the passport application, similar to the changes made in the README.md for the Endorsements API in the main PR. Both PRs enhance documentation related to environment setup, making them relevant to each other.

Suggested labels

automerge, deploy-feature

Suggested reviewers

  • kksteini
  • Tryggvig

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 27, 2024

Codecov Report

Attention: Patch coverage is 1.51515% with 65 lines in your changes missing coverage. Please review.

Project coverage is 36.66%. Comparing base (8e6c0e3) to head (4734314).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...modules/endorsementList/endorsementList.service.ts 1.51% 65 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16184      +/-   ##
==========================================
- Coverage   36.86%   36.66%   -0.21%     
==========================================
  Files        6803     6784      -19     
  Lines      140646   140479     -167     
  Branches    39995    40000       +5     
==========================================
- Hits        51852    51507     -345     
- Misses      88794    88972     +178     
Flag Coverage Δ
api 3.37% <ø> (ø)
application-system-api 41.66% <ø> (ø)
application-template-api-modules 24.27% <ø> (-0.02%) ⬇️
services-endorsements-api 54.27% <1.51%> (-0.77%) ⬇️
testing-e2e ?

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

Files with missing lines Coverage Δ
...modules/endorsementList/endorsementList.service.ts 30.34% <1.51%> (-6.21%) ⬇️

... and 206 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 68290a6...4734314. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 27, 2024

Datadog Report

All test runs bc4e12f 🔗

4 Total Test Services: 0 Failed, 4 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.73%), 5 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.78s 1 no change Link
application-system-api 0 0 0 120 2 3m 25.91s 1 no change Link
application-template-api-modules 0 0 0 134 0 1m 54.21s 1 no change Link
services-endorsements-api 0 0 0 42 0 51.82s 1 decreased (-0.73%) Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • services-endorsements-api - jest 52.14% (-0.73%) - Details

@rafnarnason rafnarnason changed the title Endorsement system/export pdf template look feat(endorsement-system): Export pdf template look Oct 8, 2024
@rafnarnason rafnarnason marked this pull request as ready for review October 8, 2024 14:23
@rafnarnason rafnarnason requested a review from a team as a code owner October 8, 2024 14:23
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: 8

🧹 Outside diff range and nitpick comments (2)
apps/services/endorsements/api/README.md (1)

46-49: Enhance AWS environment variable setup instructions

Great addition of AWS environment variable setup instructions. This will help developers with local S3 testing. However, I have a few suggestions to improve these instructions:

  1. Remove the example values to prevent accidental use of placeholder credentials. Instead, use a format like:

    export AWS_ACCESS_KEY_ID=your_access_key_id_here
    export AWS_SECRET_ACCESS_KEY=your_secret_access_key_here
    export AWS_SESSION_TOKEN=your_session_token_here
    
  2. Add guidance on how to obtain these values, e.g., "You can find these values in your AWS account settings or obtain them from your system administrator."

  3. Include a security note, such as: "IMPORTANT: Keep these values secret and never commit them to version control."

  4. Consider adding a link to AWS documentation for more information, e.g., "For more details on AWS credentials, see: https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html"

apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts (1)

608-609: Remove unnecessary empty lines for code clarity

There are multiple empty lines that might not be necessary and could be removed to enhance code readability.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3a56c8c and c257919.

⛔ Files ignored due to path filters (4)
  • apps/services/endorsements/api/src/assets/ibm-plex-sans-v7-latin-600.ttf is excluded by !**/*.ttf
  • apps/services/endorsements/api/src/assets/ibm-plex-sans-v7-latin-regular.ttf is excluded by !**/*.ttf
  • apps/services/endorsements/api/src/assets/island.png is excluded by !**/*.png
  • apps/services/endorsements/api/src/assets/thjodskra.png is excluded by !**/*.png
📒 Files selected for processing (3)
  • apps/services/endorsements/api/README.md (1 hunks)
  • apps/services/endorsements/api/src/app/modules/endorsement/endorsement.service.ts (1 hunks)
  • apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
apps/services/endorsements/api/README.md (2)

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

  • NestJS architecture, including modules, services, and controllers.
  • Dependency injection patterns and service encapsulation.
  • Integration and unit testing coverage and practices."

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/services/endorsements/api/src/app/modules/endorsement/endorsement.service.ts (2)

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

  • NestJS architecture, including modules, services, and controllers.
  • Dependency injection patterns and service encapsulation.
  • Integration and unit testing coverage and practices."

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/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts (2)

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

  • NestJS architecture, including modules, services, and controllers.
  • Dependency injection patterns and service encapsulation.
  • Integration and unit testing coverage and practices."

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 (4)
apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts (4)

31-31: Approved: Importing the 'path' module

The import of the path module is appropriate for constructing file paths in the PDF generation function.


680-685: Adjust Y-position after adding a new page

When adding a new page due to content overflow, currentYPosition is reset to 60. Ensure that this aligns with the initial content positioning and that any necessary headers (like table headers) are redrawn correctly.

Confirm that resetting currentYPosition and redrawing headers maintains consistent formatting across pages.


514-514: Ensure all usages of 'createDocumentBuffer' handle the updated return type

The method createDocumentBuffer now explicitly returns a Promise<Buffer>. Ensure that all callers of this method handle the promise correctly by using await or proper promise handling to prevent any unexpected behavior.


658-660: Define constants for repeated coordinate values

Defining constants for the column positions (dateX, nameX, localityX) enhances readability and makes future adjustments easier. This practice is good and consistent with maintainable code standards.

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

🧹 Outside diff range and nitpick comments (1)
apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts (1)

348-348: Review hardcoded values in PDF generation

There are several hardcoded values used for positioning and sizing elements in the PDF. Consider extracting these into named constants or configuration objects to improve readability and make future adjustments easier.

For example:

const HEADER_IMAGE_HEIGHT = 40;
const PAGE_MARGIN = 60;
const COLUMN_X = {
  date: 60,
  name: 160,
  locality: 360
};

Also applies to: 351-351, 446-448

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c257919 and 6442b57.

📒 Files selected for processing (1)
  • apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts (2)

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

  • NestJS architecture, including modules, services, and controllers.
  • Dependency injection patterns and service encapsulation.
  • Integration and unit testing coverage and practices."

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/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts (2)

31-31: LGTM: Import of 'path' module

The addition of the 'path' module import is appropriate for handling file paths, which is likely used for asset management in the PDF generation process.


312-315: LGTM: Improved method signature

The addition of the Promise return type enhances type safety and clarity of the method's purpose.

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

🧹 Outside diff range and nitpick comments (3)
apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts (3)

312-315: Approve method signature with a suggestion

The updated method signature with the explicit return type Promise<Buffer> improves type safety and readability. However, consider replacing the any type for endorsementList with a more specific type, such as EndorsementList, to enhance type checking and code clarity.


344-507: Approve PDF content generation with suggestions

The PDF content generation is well-structured and comprehensive, including proper pagination handling and good use of font styles. However, consider the following improvements:

  1. Add null checks or use optional chaining for properties that might be undefined, such as endorsementList.title, endorsementList.description, etc.
  2. Consider extracting repeated patterns (like setting font and fontSize) into helper functions to reduce code duplication.
  3. The endorsementList.endorsements.forEach loop might benefit from using for...of for better performance with large datasets.

Example of null checking:

.text(endorsementList.title ?? 'Untitled', 60, currentYPosition, {
  align: 'left',
})

505-511: Approve PDF finalization with error handling suggestion

The addition of the footer image and the document finalization are implemented correctly. However, consider adding error handling to catch and properly manage any issues that might occur during PDF generation or buffer creation.

Example:

try {
  doc.end()
  return await getStream.buffer(doc)
} catch (error) {
  this.logger.error('Error generating PDF buffer', { error, listId: endorsementList.id })
  throw new Error('Failed to generate PDF buffer')
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6442b57 and 9be2aa0.

📒 Files selected for processing (1)
  • apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts (2)

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

  • NestJS architecture, including modules, services, and controllers.
  • Dependency injection patterns and service encapsulation.
  • Integration and unit testing coverage and practices."

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/services/endorsements/api/src/app/modules/endorsementList/endorsementList.service.ts (2)

31-31: LGTM: Import of 'path' module

The addition of the 'path' module import is appropriate for handling file paths, which will be useful for working with assets in the PDF generation process.


316-325: LGTM: PDF document initialization and event handling

The initialization of the PDF document with a consistent margin and the setup of event listeners for 'data' and 'end' events are well-implemented. The success message logging in the 'end' event is a good practice for monitoring and debugging.

@rafnarnason rafnarnason added the automerge Merge this PR as soon as all checks pass label Oct 9, 2024
@kodiakhq kodiakhq bot merged commit 46c4a1a into main Oct 9, 2024
51 checks passed
@kodiakhq kodiakhq bot deleted the endorsement-system/export-pdf-template-look branch October 9, 2024 11:47
busla pushed a commit that referenced this pull request Oct 10, 2024
* new look setup

* s3 setup

* updated readme

* chore: nx format:write update dirty files

* finalized layout

* chore: nx format:write update dirty files

* cleanup

* cleanup

* cleanup

* cleanup

* chore: nx format:write update dirty files

* trigger

---------

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

3 participants