You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 '.'.
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.
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.
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!
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.
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
fix(posclient): merge #6433: Modifies the same posclient_api resolver code paths in bridges.ts and cpProducts.ts.
🐰 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! ✨
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.
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.
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 ✨
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.
🟡 MEDIUMcode-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):constcodeRegex=newRegExp(`^${searchValue.replaceAll('*','.*').replaceAll('_','.')}$`,'igu',);
🟡 MEDIUMcode-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.
✅ 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.
🔵 LOWnitpick: 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:
✅ 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.
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.
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.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Resolve Sonar-reported issues in POS client GraphQL product and bridge resolvers to improve correctness and code quality.
Bug Fixes:
Enhancements:
Summary by CodeRabbit
Bug Fixes
Chores