Skip to content

Format report name in report service and controller : BE #1295

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

eieimon
Copy link
Contributor

@eieimon eieimon commented May 5, 2025

Describe your changes

  • Add report name format function in reporting service
  • Add conditions for
    • if request body includes report name, return the report name as user requested
    • If not, return as {type}{YYYYMMDD}{HHMMSS}

Write your issue number after "Fixes "

Fixes #1283

Please ensure all items are checked off before requesting a review:

  • I deployed the code locally.
  • I have performed a self-review of my code.
  • I have included the issue # in the PR.
  • I have labelled the PR correctly.
  • The issue I am working on is assigned to me.
  • I didn't use any hardcoded values (otherwise it will not scale, and will make it difficult to maintain consistency across the application).
  • I made sure font sizes, color choices etc are all referenced from the theme.
  • My PR is granular and targeted to one specific feature.
  • I took a screenshot or a video and attached to this PR if there is a UI change.
Screen.Recording.2025-05-05.at.1.02.15.PM.mov
image

Summary by CodeRabbit

  • Refactor

    • Improved report file naming logic for generated reports, ensuring consistent and formatted report names.
    • Streamlined internal handling of report name formatting for better maintainability.
  • Style

    • Updated markdown report formatting with lowercase titles and section headers, and cleaner key-value style for report details.

@eieimon eieimon self-assigned this May 5, 2025
Copy link
Contributor

coderabbitai bot commented May 5, 2025

Walkthrough

The changes refactor the logic for generating report file names in the report generation controller. The file name is now determined by a new service function, getFormattedReportName, which formats the name based on the report type and current date/time. Additional minor formatting changes are made to the markdown report output.

Changes

File(s) Change Summary
Servers/controllers/reporting.ctrl.ts Replaced in-controller report file name logic with a call to getFormattedReportName. Updated imports.
Servers/services/reportService.ts Added getFormattedReportName function. Adjusted markdown report formatting and updated imports.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Controller as reporting.ctrl.ts
    participant Service as reportService.ts

    Client->>Controller: POST /generateReports (reportName, reportType)
    Controller->>Service: getFormattedReportName(reportName, reportType)
    Service-->>Controller: Returns formatted file name
    Controller->>Service: getProjectRiskMarkdown(...)
    Service-->>Controller: Returns markdown report
    Controller->>Service: convertMarkdownToDocx(...)
    Service-->>Controller: Returns docx buffer
    Controller->>Service: uploadFile(...)
    Service-->>Controller: Returns file URL
    Controller-->>Client: Responds with file URL
Loading

Assessment against linked issues

Objective Addressed Explanation
Report file name should be report_{type}{YYYYMMDD}{HHMMSS} (#1283)

Poem

A hop and a leap, a filename anew,
With type and the date, now formatted true.
No more confusion, no more the same,
Each report is unique, in timestamp and name.
🐇✨
Reports now sparkle, with order and glee—
Just as a rabbit likes things to be!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b90396 and c0a1034.

📒 Files selected for processing (1)
  • Servers/services/reportService.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Servers/services/reportService.ts
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

🧹 Nitpick comments (1)
Servers/services/reportService.ts (1)

14-14: Consider adding type safety for the report type parameter

The type parameter could benefit from being typed more specifically to ensure only valid report types are passed.

- export function getFormattedReportName(name: string, type: string) {
+ export function getFormattedReportName(name: string, type: keyof typeof ReportType | string) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 263fe05 and 1d0a1cc.

📒 Files selected for processing (2)
  • Servers/controllers/reporting.ctrl.ts (2 hunks)
  • Servers/services/reportService.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
Servers/services/reportService.ts (1)
Servers/models/reporting.model.ts (2)
  • ReportType (9-15)
  • DefaultReportName (1-7)
Servers/controllers/reporting.ctrl.ts (1)
Servers/services/reportService.ts (1)
  • getFormattedReportName (14-48)
🔇 Additional comments (3)
Servers/services/reportService.ts (1)

107-107: LGTM: Improved formatting in report text

The formatting changes in the report template improve readability and consistency by adjusting capitalization and spacing.

Also applies to: 112-114, 116-116

Servers/controllers/reporting.ctrl.ts (2)

4-4: LGTM: Good service function import

The import statement correctly includes the new getFormattedReportName function from the report service.


33-33: LGTM: Good refactoring to service layer

Moving the report name formatting logic to a dedicated service function improves separation of concerns and code maintainability.

Comment on lines 14 to 47
export function getFormattedReportName(name: string, type: string) {
let reportType;
switch(type) {
case ReportType.PROJECTRISK_REPORT:
reportType = DefaultReportName.PROJECTRISK_REPORT;
break;
case ReportType.VENDOR_REPORT:
reportType = DefaultReportName.VENDOR_REPORT;
break;
case ReportType.ASSESSMENT_REPORT:
reportType = DefaultReportName.ASSESSMENT_REPORT;
break;
case ReportType.COMPLIANCE_REPORT:
reportType = DefaultReportName.COMPLIANCE_REPORT;
break;
default:
reportType = DefaultReportName.ALL_REPORT;
}

const date = new Date();

const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');

const hour = String(date.getHours()).padStart(2, '0');
const minute = String(date.getMinutes()).padStart(2, '0');
const second = String(date.getSeconds()).padStart(2, '0');

if(name.length === 0 ) {
return `${type}_${year}${month}${day}_${hour}${minute}${second}`;
} else {
return `${name}`;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Bug in default report name generation

The function correctly handles the case when a user provides a report name, but there's an issue when generating the default name. The function currently uses ${type} as the prefix (the full report type string like "Project risks report"), but it should be using the reportType variable (like "risk-report") that was set in the switch statement.

Fix the default report name generation:

  if(name.length === 0 ) {
-    return `${type}_${year}${month}${day}_${hour}${minute}${second}`;
+    return `${reportType}_${year}${month}${day}_${hour}${minute}${second}`;
  } else {
-    return `${name}`;
+    return name;
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function getFormattedReportName(name: string, type: string) {
let reportType;
switch(type) {
case ReportType.PROJECTRISK_REPORT:
reportType = DefaultReportName.PROJECTRISK_REPORT;
break;
case ReportType.VENDOR_REPORT:
reportType = DefaultReportName.VENDOR_REPORT;
break;
case ReportType.ASSESSMENT_REPORT:
reportType = DefaultReportName.ASSESSMENT_REPORT;
break;
case ReportType.COMPLIANCE_REPORT:
reportType = DefaultReportName.COMPLIANCE_REPORT;
break;
default:
reportType = DefaultReportName.ALL_REPORT;
}
const date = new Date();
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hour = String(date.getHours()).padStart(2, '0');
const minute = String(date.getMinutes()).padStart(2, '0');
const second = String(date.getSeconds()).padStart(2, '0');
if(name.length === 0 ) {
return `${type}_${year}${month}${day}_${hour}${minute}${second}`;
} else {
return `${name}`;
}
if (name.length === 0) {
return `${reportType}_${year}${month}${day}_${hour}${minute}${second}`;
} else {
return name;
}

@eieimon eieimon marked this pull request as draft May 5, 2025 19:26
@eieimon eieimon marked this pull request as ready for review May 5, 2025 19:33
@MuhammadKhalilzadeh
Copy link
Collaborator

@eieimon thank you
You have build error that are not passing checks.
Just simply run npm run build for find what are your errors

@gorkem-bwl
Copy link
Contributor

File formating/naming wise look good to me.

@eieimon eieimon force-pushed the eem-may-05-report-name-changes branch from 6b90396 to 1d0a1cc Compare May 5, 2025 20:57
Copy link
Collaborator

@MuhammadKhalilzadeh MuhammadKhalilzadeh left a comment

Choose a reason for hiding this comment

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

@eieimon Thank you for applying changes.
There's a problem however.
I'm not able to generate reports on your branch, while your able to do so as shown in the video attached.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Report file name should be report_{type}_{YYYYMMDD}_{HHMMSS}
3 participants