Skip to content

fix:sonar resolved on resolvers/queries#7217

Open
Buyant0gt0kh wants to merge 1 commit intomainfrom
sonar_resolve_resolvers_queries
Open

fix:sonar resolved on resolvers/queries#7217
Buyant0gt0kh wants to merge 1 commit intomainfrom
sonar_resolve_resolvers_queries

Conversation

@Buyant0gt0kh
Copy link
Collaborator

@Buyant0gt0kh Buyant0gt0kh commented Mar 19, 2026

Summary by Sourcery

Resolve Sonar-reported issues in POS client GraphQL product and bridge resolvers to improve correctness and code quality.

Bug Fixes:

  • Correct category meta filtering logic to properly distinguish numeric and non-numeric meta values in product queries.
  • Fix meta filter construction so non-numeric values are matched directly and numeric values are compared using less-than-or-equal semantics.
  • Ensure regex construction for product code and search filters correctly escapes special characters and handles wildcard replacements.
  • Use array.some instead of .find when checking customFieldsData to correctly express existence checks and improve readability.
  • Remove unreachable return statements from bridge customer resolvers.

Enhancements:

  • Replace chained String.replace calls with replaceAll for clearer and more consistent string transformations in regex generation.

Summary by CodeRabbit

  • Bug Fixes

    • Improved product filtering logic for code wildcards and category metadata matching to handle numeric and non-numeric values more accurately.
  • Chores

    • Optimized internal code patterns in product resolver implementations for improved maintainability.

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 19, 2026

Reviewer's Guide

Refactors several GraphQL product query resolvers to satisfy Sonar suggestions by simplifying numeric vs string meta handling, using safer/more explicit RegExp construction and modern array helpers, and removing unreachable returns in bridge resolvers.

File-Level Changes

Change Details Files
Align wildcard search and regex construction for product/code filters with safer and clearer string replacement semantics.
  • Replace chained String.replace with String.replaceAll for '' and '_' wildcard handling before building code RegExp in both cpProducts and products resolvers.
  • Adjust regex construction for search strings so that literal '.' is escaped via replaceAll with a raw backslash pattern, while '' and '_' are consistently converted to '.'.
backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/cpProducts.ts
backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/products.ts
Correct and simplify logic that branches on numeric vs non-numeric category meta values when building aggregation filters.
  • Invert the Number.isNaN checks so that non-numeric categoryMeta/meta values lead to equality filters on the raw meta field, while numeric values produce $lte comparisons on a converted numeric field.
  • Remove duplicated else branches and keep a single, clearer path for each of the numeric and non-numeric meta cases.
  • Ensure the same meta handling semantics are applied in both generateFilter and generateFilterCat helpers for products and cpProducts.
backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/cpProducts.ts
backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/products.ts
Modernize collection and control-flow usage in custom field filtering and bridge query resolvers.
  • Replace Array.find with Array.some when checking if any customFieldsData entry matches a generated regex filter, making the intent explicit and returning a boolean directly.
  • Remove unreachable return statements at the end of bridgesQueries methods that already return conditionally within the function body.
backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/cpProducts.ts
backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/products.ts
backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/bridges.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai
Copy link

coderabbitai bot commented Mar 19, 2026

📝 Walkthrough

Walkthrough

Three GraphQL query resolver files in the posclient API plugin were updated: removed explicit return statements in bridges.ts; modernized regex wildcard handling with .replaceAll() in cpProducts.ts and products.ts; refined metadata filtering logic with inverted numeric/non-numeric branching; and simplified array existence checks from .find() to .some().

Changes

Cohort / File(s) Summary
Control Flow Cleanup
backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/bridges.ts
Removed explicit return; statements at the end of resolver branches where no matching data is found, relying on implicit undefined fallthrough.
Query Resolver Regex & Metadata Filtering
backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/cpProducts.ts, backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/products.ts
Replaced .replace(..., 'g') chains with .replaceAll() for wildcard-to-dot conversions in regex generation; inverted numeric/non-numeric metadata branching logic (numeric values now use $lte with $convert, non-numeric use direct equality); simplified custom field existence checks from .find() to .some().

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Wildcard whispers dance with dots so fine,
replaceAll flows like morning dew in line,
Metadata spirits flip their logic dance,
As resolvers leap and filters prance,
Return statements fade to nothing's call—
Cleaner code hops through it all! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title references 'sonar resolved' issues in resolver query files, which aligns with the PR's refactoring of regex patterns, loop optimizations, and control flow simplifications across multiple resolver files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sonar_resolve_resolvers_queries
📝 Coding Plan
  • Generate coding plan for human review comments

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@deepsource-io
Copy link

deepsource-io bot commented Mar 19, 2026

DeepSource Code Review

We reviewed changes in 11ffffb...7bedefd on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
JavaScript Mar 19, 2026 9:23a.m. Review ↗
Docker Mar 19, 2026 9:23a.m. Review ↗

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In both generateFilterCat functions you now use if (Number.isNaN(meta)) (without casting) to decide between treating meta as numeric or not; this will mis-handle non-numeric strings (e.g. 'abc' becomes { $lte: NaN }), so consider aligning this check with the categoryMeta logic and using Number.isNaN(Number(meta)) (or a clearer helper) to avoid introducing incorrect filters.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In both `generateFilterCat` functions you now use `if (Number.isNaN(meta))` (without casting) to decide between treating `meta` as numeric or not; this will mis-handle non-numeric strings (e.g. `'abc'` becomes `{ $lte: NaN }`), so consider aligning this check with the `categoryMeta` logic and using `Number.isNaN(Number(meta))` (or a clearer helper) to avoid introducing incorrect filters.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@github-actions
Copy link

🌗 Pull Request Overview

This PR addresses SonarQube code quality issues in GraphQL resolver query files. The changes include removing unnecessary return statements, replacing replace() with replaceAll() for correct multi-occurrence replacements, inverting isNaN conditionals for clarity, and using some() instead of find() for boolean checks.

Reviewed Changes
Kimi performed full review on 3 changed files and found 1 issue.

Show a summary per file
File Description
backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/bridges.ts Removed 2 unnecessary return; statements at end of async functions
backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/cpProducts.ts Changed replace() to replaceAll(), reordered isNaN conditionals, updated regex escaping, changed .find() to .some()
backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/products.ts Same changes as cpProducts.ts - replaceAll(), reordered conditionals, regex escaping, .some() usage

📋 Review Findings

📄 backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/cpProducts.ts

🟡 MEDIUM code-quality: Potential behavioral change with replaceAll() for regex special characters

Line 188

The change from replace(/_/g, '.') to replaceAll('_', '.') is correct (both replace all occurrences). However, there's a logic issue: both * and _ are being replaced with . (match any character). If a user provides a search string with both characters, they both become . which may not be the intended behavior for _ (typically a single character wildcard, not any number).

💡 Suggested fix:

Consider using different regex patterns for * (zero or more) vs _ (single character):

// Current code (both become '.' which matches any single character):
const codeRegex = new RegExp(
  `^${searchValue.replaceAll('*', '.*').replaceAll('_', '.')}$`,
  'igu',
);

📄 backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/products.ts

🟡 MEDIUM code-quality: Same regex pattern issue as cpProducts.ts

Line 165

Same concern as above - the pattern replacement for * and _ both use . which only matches a single character. * typically means "zero or more of preceding" in wildcards.

💡 Suggested fix:

const codeRegex = new RegExp(
  `^${searchValue.replaceAll('*', '.*').replaceAll('_', '.')}$`,
  'igu',
);

📄 backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/bridges.ts

No issues found. The removal of unnecessary return; statements at the end of async functions is correct. These functions return Promise<void> implicitly, and the explicit return; statements were redundant.


📄 backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/cpProducts.ts (continued)

🔵 LOW nitpick: Inconsistent Number.isNaN() check between generateFilter and generateFilterCat

Lines 238, 342

In generateFilter, the check is Number.isNaN(Number(categoryMeta)) (converts to Number first), but in generateFilterCat, it's Number.isNaN(meta) directly. If meta is passed as a string like "123", these behave differently. Ensure consistent validation across both functions.


✅ Overall Assessment

The PR makes legitimate code quality improvements:

  • ✅ Removing unnecessary return statements improves readability
  • ✅ Using replaceAll() fixes potential bugs where only first occurrence was replaced
  • ✅ Using some() instead of find() is semantically clearer for boolean checks
  • ✅ The String.raw usage for regex escaping is cleaner

Recommendation: Address the wildcard regex pattern issue (using .* for * instead of .) to ensure the search behaves as users would expect from standard wildcard patterns.


Powered by Kimi | Model: kimi-k2.5

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
100.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

return;
},

async poscCustomerDetail(
Copy link

Choose a reason for hiding this comment

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

Expected to return a value at the end of async method 'poscCustomerDetail'


Any code paths that do not have explicit returns will return undefined. It is recommended to replace any implicit dead-ends that return undefined with a return null statement.

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/cpProducts.ts`:
- Around line 342-345: The check that tests whether meta is numeric is wrong
because Number.isNaN(meta) receives a string and always returns false; in the
function that builds the filter (the block handling variable meta in
cpProducts.ts, same logic as generateFilterCat in products.ts) change the
condition to Number.isNaN(Number(meta)) so non-numeric meta values go down the
intended branch and numeric strings are converted with Number(meta) for the $lte
filter; update the conditional accordingly wherever that meta check appears.

In
`@backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/products.ts`:
- Around line 319-322: Replace the incorrect Number.isNaN(meta) check with
Number.isNaN(Number(meta)) in the products resolver so the code tests the
numeric conversion of meta; specifically, update the conditional that assigns to
filter.meta (the branch using Number.isNaN(meta) and the else branch that sets
filter.meta = { $lte: Number(meta) }) to use Number.isNaN(Number(meta)) so
string inputs are correctly classified as numeric vs non-numeric.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b36ba7c5-5e4d-4bf5-8b04-e1fff5cb43f5

📥 Commits

Reviewing files that changed from the base of the PR and between 11ffffb and 7bedefd.

📒 Files selected for processing (3)
  • backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/bridges.ts
  • backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/cpProducts.ts
  • backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/products.ts
💤 Files with no reviewable changes (1)
  • backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/bridges.ts

Comment on lines +342 to +345
if (Number.isNaN(meta)) {
filter.meta = meta;
} else {
filter.meta = { $lte: Number(meta) };
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Bug: Same issue as products.ts - Number.isNaN(meta) always returns false for strings.

This has the identical bug as generateFilterCat in products.ts. The condition should be Number.isNaN(Number(meta)) to properly detect non-numeric strings.

🐛 Proposed fix
  if (meta) {
-   if (Number.isNaN(meta)) {
+   if (Number.isNaN(Number(meta))) {
      filter.meta = meta;
    } else {
      filter.meta = { $lte: Number(meta) };
    }
  }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/cpProducts.ts`
around lines 342 - 345, The check that tests whether meta is numeric is wrong
because Number.isNaN(meta) receives a string and always returns false; in the
function that builds the filter (the block handling variable meta in
cpProducts.ts, same logic as generateFilterCat in products.ts) change the
condition to Number.isNaN(Number(meta)) so non-numeric meta values go down the
intended branch and numeric strings are converted with Number(meta) for the $lte
filter; update the conditional accordingly wherever that meta check appears.

Comment on lines +319 to +322
if (Number.isNaN(meta)) {
filter.meta = meta;
} else {
filter.meta = { $lte: Number(meta) };
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Bug: Number.isNaN(meta) will always return false for string input.

Number.isNaN() checks if the value is exactly the NaN value of type Number. Since meta is a string, Number.isNaN(meta) always returns false, causing all values to fall into the else branch with { $lte: Number(meta) }.

This is inconsistent with line 215 which correctly uses Number.isNaN(Number(categoryMeta)).

🐛 Proposed fix
  if (meta) {
-   if (Number.isNaN(meta)) {
+   if (Number.isNaN(Number(meta))) {
      filter.meta = meta;
    } else {
      filter.meta = { $lte: Number(meta) };
    }
  }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@backend/plugins/posclient_api/src/modules/posclient/graphql/resolvers/queries/products.ts`
around lines 319 - 322, Replace the incorrect Number.isNaN(meta) check with
Number.isNaN(Number(meta)) in the products resolver so the code tests the
numeric conversion of meta; specifically, update the conditional that assigns to
filter.meta (the branch using Number.isNaN(meta) and the else branch that sets
filter.meta = { $lte: Number(meta) }) to use Number.isNaN(Number(meta)) so
string inputs are correctly classified as numeric vs non-numeric.

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.

1 participant