fix: limit standing gain from medallions for title's max #772

Merged
Sainan merged 2 commits from standing-clamp into main 2025-01-13 08:58:00 -08:00
Owner

Fixes #734

Fixes #734
coderabbitai[bot] commented 2025-01-11 22:56:34 -08:00 (Migrated from github.com)
Author
Owner

Walkthrough

The changes in the syndicateStandingBonusController modify the logic for updating syndicate standings. The new implementation introduces a more robust approach to managing syndicate affiliations. When updating standings, the code now first checks if the syndicate exists in the affiliations list. If not, it initializes the syndicate with a zero standing and adds it to the list. A new getMaxStanding function has been implemented to determine the maximum allowable standing based on the affiliation tag and syndicate title. This function ensures that standing updates do not exceed predefined limits by adjusting the gained standing if necessary.

Assessment against linked issues

Objective Addressed Explanation
Handle excess standing for syndicate medallions [#734]
Prevent standings from exceeding maximum limits

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.
<!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- walkthrough_start --> ## Walkthrough The changes in the `syndicateStandingBonusController` modify the logic for updating syndicate standings. The new implementation introduces a more robust approach to managing syndicate affiliations. When updating standings, the code now first checks if the syndicate exists in the affiliations list. If not, it initializes the syndicate with a zero standing and adds it to the list. A new `getMaxStanding` function has been implemented to determine the maximum allowable standing based on the affiliation tag and syndicate title. This function ensures that standing updates do not exceed predefined limits by adjusting the gained standing if necessary. ## Assessment against linked issues | Objective | Addressed | Explanation | |-----------|-----------|-------------| | Handle excess standing for syndicate medallions [#734] | ✅ | | | Prevent standings from exceeding maximum limits | ✅ | | <!-- walkthrough_end --> <!-- internal state start --> <!-- FAHghAtBAEAqAWBLAztF0CGA7TBXALgPYQDmAplmQE4b5kAm0AxoQLasX4Bc0ADldEIAjAFZkm+RADcyqIQE9mhetQxChifADoMiaFAB8wY+CjGAxOegAFAErQAyrnYYq84wjJ9cAGx/QqMgBHXFl8aEl8HwZoACIAM0QADx4fRFZNaGR8bHpELBJoEl0ceKo2aA56DD9EQixUeMIBSOiAclRWDCTY6AB3DFRkXCEM/DpGBQj4L1xkakcS7EwsRnREFSxJRJip/BnoLGchBYB2U4AmLTgD/nTXRV5cKl5CecF46fQ7NFQiTHo9ECyFQyxQwy8gXi1AoTBig2g5lOAGYACzXTzQFTIJhURC8ST1PjlKQbGL0QiyQ6EcL5Jg+XAqAF5QlYGpYsg5RA+ORkeT1Rj7Lzg0IBMjQwJYOFaYwAMWa0HizyFAnyTSoXVZABppl4nn4xSEwsxlidMEw4SD4eEhYrCH5CH18oUAKq2AAyPAA2vBxrxkFwAPSBkiaeAjLQsViB5C8DBwrD5ESDagyKiBhxxuEAOSTGAcqeogf1PkD5wuAF0ABS+/D+oMhsMRqMxrMUPPzKhpjNt3NYZMFrtFktly4AShlwEMJkgMAojEInwwBGI5EoNAmSnYnB4/EEonEkhkckULBUNHUmh0emnphgCHWoJwy6IpAoqk3UY4Wx4ND6WWcLo3GgKYz1US9tF0fQICMGczGAZAqCYQMWC2co/GoZBAwwXhEBjeRVkQJhaDIBwckIgoACF6jmABhep8HQ6IqC0fAA2AWJOOASxoAAQQASTfdcSMYYYXGAxdmHgbByGQDwDiYaSCipfJdWgAADZACLyYi6DI3JnWoo5kHotD7WY9TFVwKVWWgCglLhNSfEIUMmDtARcF4apJAKLJtKIkisnIvICmQDFbkCUlCDmNBWF4aJvxyWy8kCCQfEUTzvJiW1sgM3zJOWMgkhQHzCi0wjdK8BUMEBeFDjIf9yp0wKnX2NTinyGJcookhwq8Sh/2c1zFUQKhskwcYyDitiIkIEbVjUpqAroNAcFtDB4kSNJaDqBpoDSbJrn4z4cv8yqsUpVAsBpOziuyHVMnyTREBqRAAC8VPCVr4EwIK8sKSSPvKFZGBq+hUEyf51s27kXtZVADu0YxeMBZ76hqdKdQwer/yVGzdp1dTyHwABZbp9J69SdWk3kKFWxjlFwOFBTmlQ6A1Tq1K6YrWGcTAHQGIRoj+nqQJTBc1oODatrh3aIgwQpckWs6SI6CJNGicL0DxiQ5fQYiMJZqTxAAazQE6DgGkWQpIHU+hmZ9aqN20mGeSVwm6m2dSKuEGD+A5ufSPmMcdBgjs+TIKVkHVbQ6yhROC51fgBEQ5k3eMWCoG30pA8Vmi8E4k7B7K5tOirVdQV2qHd63nUnTFCDTDGlDM/x4mc/8adzunWGURAdiNukGSZIV3kU03kG9hpniT/ZaEWxPfMykjQXoGZAlmtSVESeP9vSTQwosKxeJ8dmdvqP5S4OFR6Vcc+9skorXioTcFSeIWiLsrZntkYwYBJzk8BlDMgYDwdSqFxrEzJkkCmNtoAAF5oBVmlrDe+sAFY8GyHiAoMcNZkB4EcVgJwqBjgIccagllVKaSQihBiTFMLYVwvhcuelF4kCMnROh5lqCsWQOpDiXEpwwTgnOBaBUVxCQ/DEL8O4AgYEaoBB4IFTzKHAhoSCN5hF3i3GMAA+hsZAujIqIAagwXRuUX7QVgtogADKcegNiACcAA2AAjDYoQG0mDxHoBcMgjiPEAFZThCAAByoh8RgC4GA0QeORK4jAoTHFCFOFY0As5oChNCacVErihCuIuEk04zibGomRMiNxyILgXECYCGxziyCnHcciIQgTAnOPiDY+gjivC3gyciJJNiyDxMcS09xNimChIwBgYJ7ihD0DafEVE6hwmBLIBtZE8QLiOMYNOdJUAdGaH0eDIxZBSSmPoLo+cVigA= --> <!-- internal state end --> <!-- finishing_touch_checkbox_start --> ## Finishing Touches - [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings (Beta) <!-- finishing_touch_checkbox_end --> <!-- tips_start --> --- 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? <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): - 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 generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR. ([Beta](https://docs.coderabbit.ai/early-access#beta)) - `@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](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 -->
coderabbitai[bot] (Migrated from github.com) reviewed 2025-01-11 22:58:52 -08:00
coderabbitai[bot] (Migrated from github.com) left a comment
Author
Owner

Actionable comments posted: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8ebd7068e2 and 07d09610bafcfd2e90b57b84fda2a340b31a89b7.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • package.json (1 hunks)
  • src/controllers/api/syndicateStandingBonusController.ts (2 hunks)
🧰 Additional context used
🪛 eslint
src/controllers/api/syndicateStandingBonusController.ts

[error] 29-29: Insert ⏎···········

(prettier/prettier)

🪛 GitHub Check: build (22)
src/controllers/api/syndicateStandingBonusController.ts

[failure] 29-29:
Insert ⏎···········

🪛 GitHub Check: build (20)
src/controllers/api/syndicateStandingBonusController.ts

[failure] 29-29:
Insert ⏎···········

🪛 GitHub Check: build (18)
src/controllers/api/syndicateStandingBonusController.ts

[failure] 29-29:
Insert ⏎···········

🪛 GitHub Actions: Build
src/controllers/api/syndicateStandingBonusController.ts

[error] 29-29: Code formatting error: Insert line break and proper indentation

🔇 Additional comments (2)
src/controllers/api/syndicateStandingBonusController.ts (1)

32-38: LGTM! Well-implemented standing limit.

The implementation correctly caps the gained standing to prevent exceeding the maximum limit, with proper null checking for the Title property.

package.json (1)

19-19: Verify the dependency update impact.

The minor version update of warframe-public-export-plus should be verified for any breaking changes.

Let's check the package's release notes:

Verification successful

Patch version update appears safe to proceed

The update from 0.5.21 to 0.5.22 is a patch version that should only contain backwards-compatible bug fixes. The package is used exclusively for importing static data exports and type definitions across the codebase, with no complex interactions that could break from minor data updates.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check release notes and compare versions

# Get changelog or release notes
gh api repos/WFCD/warframe-public-export-plus/releases | jq -r '.[0:2] | .[] | "Version: \(.tag_name)\nChanges:\n\(.body)\n"'

# Compare versions for breaking changes
npm view warframe-public-export-plus@0.5.21 exports
npm view warframe-public-export-plus@0.5.22 exports

Length of output: 318


Script:

#!/bin/bash
# Search for usage of warframe-public-export-plus in the codebase
rg -l "require.*warframe-public-export-plus|from.*warframe-public-export-plus" --type js --type ts

# Check if package-lock.json exists and show the relevant section
if [ -f package-lock.json ]; then
  cat package-lock.json | jq '.packages["node_modules/warframe-public-export-plus"]'
fi

# Try to fetch the package's README directly
curl -s https://raw.githubusercontent.com/WFCD/warframe-public-export-plus/master/README.md || true

Length of output: 1484


Script:

#!/bin/bash
# Check actual usage in one of the files to understand the features being used
ast-grep --pattern 'from "warframe-public-export-plus"' -f src/services/itemDataService.ts
rg "from 'warframe-public-export-plus'" src/services/itemDataService.ts -A 2

Length of output: 355


Script:

#!/bin/bash
# Check imports in one of the key service files
cat src/services/itemDataService.ts | head -n 20

# Search for import patterns across files
rg "from ['\"]warframe-public-export-plus['\"]" -A 1 --type ts

Length of output: 4169

**Actionable comments posted: 2** <details> <summary>📜 Review details</summary> **Configuration used: .coderabbit.yaml** **Review profile: CHILL** **Plan: Pro** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 8ebd7068e2cb44731a70e07783b648e0da5f79bb and 07d09610bafcfd2e90b57b84fda2a340b31a89b7. </details> <details> <summary>⛔ Files ignored due to path filters (1)</summary> * `package-lock.json` is excluded by `!**/package-lock.json` </details> <details> <summary>📒 Files selected for processing (2)</summary> * `package.json` (1 hunks) * `src/controllers/api/syndicateStandingBonusController.ts` (2 hunks) </details> <details> <summary>🧰 Additional context used</summary> <details> <summary>🪛 eslint</summary> <details> <summary>src/controllers/api/syndicateStandingBonusController.ts</summary> [error] 29-29: Insert `⏎···········` (prettier/prettier) </details> </details> <details> <summary>🪛 GitHub Check: build (22)</summary> <details> <summary>src/controllers/api/syndicateStandingBonusController.ts</summary> [failure] 29-29: Insert `⏎···········` </details> </details> <details> <summary>🪛 GitHub Check: build (20)</summary> <details> <summary>src/controllers/api/syndicateStandingBonusController.ts</summary> [failure] 29-29: Insert `⏎···········` </details> </details> <details> <summary>🪛 GitHub Check: build (18)</summary> <details> <summary>src/controllers/api/syndicateStandingBonusController.ts</summary> [failure] 29-29: Insert `⏎···········` </details> </details> <details> <summary>🪛 GitHub Actions: Build</summary> <details> <summary>src/controllers/api/syndicateStandingBonusController.ts</summary> [error] 29-29: Code formatting error: Insert line break and proper indentation </details> </details> </details> <details> <summary>🔇 Additional comments (2)</summary><blockquote> <details> <summary>src/controllers/api/syndicateStandingBonusController.ts (1)</summary> `32-38`: **LGTM! Well-implemented standing limit.** The implementation correctly caps the gained standing to prevent exceeding the maximum limit, with proper null checking for the Title property. </details> <details> <summary>package.json (1)</summary> `19-19`: **Verify the dependency update impact.** The minor version update of warframe-public-export-plus should be verified for any breaking changes. Let's check the package's release notes: <details> <summary>✅ Verification successful</summary> <!-- [monologue] [task verify_dependency_1/1] [observations] 1. The package is used for importing type definitions and data exports: - ExportArcanes, ExportCustoms, ExportGear - ExportEnemies, ExportResources, ExportSyndicates - ExportDojoRecipes, ExportRelics, ExportRewards - ExportFocusUpgrades, ExportMisc, ExportRecipes - Type definitions like TRarity, ISyndicateSacrifice, IRelic 2. These are all static data exports and type definitions 3. The update is a patch version (0.5.21 -> 0.5.22) [analysis] 1. The package is used purely for data exports and type definitions 2. Following semver, a patch version update (0.5.21 -> 0.5.22): - Should only contain backwards-compatible bug fixes - Won't include breaking changes to types or data structure 3. The usage pattern shows we're only importing static data and types - No direct method calls or complex interactions - Changes would only affect if the data structure itself changed [actions] Given that: 1. It's a patch version update 2. We only use static exports and type definitions 3. No complex interactions that could break Generate final response indicating low risk --> **Patch version update appears safe to proceed** The update from 0.5.21 to 0.5.22 is a patch version that should only contain backwards-compatible bug fixes. The package is used exclusively for importing static data exports and type definitions across the codebase, with no complex interactions that could break from minor data updates. </details> <details> <summary>🏁 Scripts executed</summary> The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Description: Check release notes and compare versions # Get changelog or release notes gh api repos/WFCD/warframe-public-export-plus/releases | jq -r '.[0:2] | .[] | "Version: \(.tag_name)\nChanges:\n\(.body)\n"' # Compare versions for breaking changes npm view warframe-public-export-plus@0.5.21 exports npm view warframe-public-export-plus@0.5.22 exports ``` Length of output: 318 --- Script: ```shell #!/bin/bash # Search for usage of warframe-public-export-plus in the codebase rg -l "require.*warframe-public-export-plus|from.*warframe-public-export-plus" --type js --type ts # Check if package-lock.json exists and show the relevant section if [ -f package-lock.json ]; then cat package-lock.json | jq '.packages["node_modules/warframe-public-export-plus"]' fi # Try to fetch the package's README directly curl -s https://raw.githubusercontent.com/WFCD/warframe-public-export-plus/master/README.md || true ``` Length of output: 1484 --- Script: ```shell #!/bin/bash # Check actual usage in one of the files to understand the features being used ast-grep --pattern 'from "warframe-public-export-plus"' -f src/services/itemDataService.ts rg "from 'warframe-public-export-plus'" src/services/itemDataService.ts -A 2 ``` Length of output: 355 --- Script: ```shell #!/bin/bash # Check imports in one of the key service files cat src/services/itemDataService.ts | head -n 20 # Search for import patterns across files rg "from ['\"]warframe-public-export-plus['\"]" -A 1 --type ts ``` Length of output: 4169 </details> </details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
coderabbitai[bot] (Migrated from github.com) commented 2025-01-11 22:58:51 -08:00
Author
Owner

⚠️ Potential issue

Fix formatting and consider simplifying the initialization.

The code needs proper formatting according to the pipeline failures. Additionally, the push-and-index pattern could be simplified.

Apply this diff to fix the formatting and simplify the code:

 let syndicate = inventory.Affiliations.find(x => x.Tag == request.Operation.AffiliationTag);
 if (!syndicate) {
-        syndicate = inventory.Affiliations[inventory.Affiliations.push({ Tag: request.Operation.AffiliationTag, Standing: 0 })];
+     syndicate = { Tag: request.Operation.AffiliationTag, Standing: 0 };
+     inventory.Affiliations.push(syndicate);
 }
📝 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.

    let syndicate = inventory.Affiliations.find(x => x.Tag == request.Operation.AffiliationTag);
    if (!syndicate) {
        syndicate = { Tag: request.Operation.AffiliationTag, Standing: 0 };
        inventory.Affiliations.push(syndicate);
    }
🧰 Tools
🪛 eslint

[error] 29-29: Insert ⏎···········

(prettier/prettier)

🪛 GitHub Check: build (22)

[failure] 29-29:
Insert ⏎···········

🪛 GitHub Check: build (20)

[failure] 29-29:
Insert ⏎···········

🪛 GitHub Check: build (18)

[failure] 29-29:
Insert ⏎···········

🪛 GitHub Actions: Build

[error] 29-29: Code formatting error: Insert line break and proper indentation

_:warning: Potential issue_ **Fix formatting and consider simplifying the initialization.** The code needs proper formatting according to the pipeline failures. Additionally, the push-and-index pattern could be simplified. Apply this diff to fix the formatting and simplify the code: ```diff let syndicate = inventory.Affiliations.find(x => x.Tag == request.Operation.AffiliationTag); if (!syndicate) { - syndicate = inventory.Affiliations[inventory.Affiliations.push({ Tag: request.Operation.AffiliationTag, Standing: 0 })]; + syndicate = { Tag: request.Operation.AffiliationTag, Standing: 0 }; + inventory.Affiliations.push(syndicate); } ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **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. `````suggestion let syndicate = inventory.Affiliations.find(x => x.Tag == request.Operation.AffiliationTag); if (!syndicate) { syndicate = { Tag: request.Operation.AffiliationTag, Standing: 0 }; inventory.Affiliations.push(syndicate); } ````` </details> <!-- suggestion_end --> <details> <summary>🧰 Tools</summary> <details> <summary>🪛 eslint</summary> [error] 29-29: Insert `⏎···········` (prettier/prettier) </details> <details> <summary>🪛 GitHub Check: build (22)</summary> [failure] 29-29: Insert `⏎···········` </details> <details> <summary>🪛 GitHub Check: build (20)</summary> [failure] 29-29: Insert `⏎···········` </details> <details> <summary>🪛 GitHub Check: build (18)</summary> [failure] 29-29: Insert `⏎···········` </details> <details> <summary>🪛 GitHub Actions: Build</summary> [error] 29-29: Code formatting error: Insert line break and proper indentation </details> </details> <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] (Migrated from github.com) commented 2025-01-11 22:58:51 -08:00
Author
Owner

🛠️ Refactor suggestion

Add error handling and improve constants management.

The function could be more robust with proper error handling and constant management:

  1. Non-null assertions (!.) could fail if data is malformed
  2. No error handling for invalid affiliation tags
  3. Magic number 125000 should be a named constant

Consider this safer implementation:

+const LIBRARY_SYNDICATE_MAX_STANDING = 125000;
+
 const getMaxStanding = (affiliationTag: string, title: number): number => {
     const syndicate = ExportSyndicates[affiliationTag];
+    if (!syndicate) {
+        throw new Error(`Invalid syndicate affiliation tag: ${affiliationTag}`);
+    }
     if (!syndicate.titles) {
         // LibrarySyndicate
-        return 125000;
+        return LIBRARY_SYNDICATE_MAX_STANDING;
     }
+    const titleData = syndicate.titles.find(x => x.level == (title == 0 ? 1 : title));
+    if (!titleData) {
+        throw new Error(`Invalid title level ${title} for syndicate ${affiliationTag}`);
+    }
-    if (title == 0) {
-        return syndicate.titles.find(x => x.level == 1)!.minStanding;
-    }
-    return syndicate.titles.find(x => x.level == title)!.maxStanding;
+    return title == 0 ? titleData.minStanding : titleData.maxStanding;
 };
📝 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.

const LIBRARY_SYNDICATE_MAX_STANDING = 125000;

const getMaxStanding = (affiliationTag: string, title: number): number => {
    const syndicate = ExportSyndicates[affiliationTag];
    if (!syndicate) {
        throw new Error(`Invalid syndicate affiliation tag: ${affiliationTag}`);
    }
    if (!syndicate.titles) {
        // LibrarySyndicate
        return LIBRARY_SYNDICATE_MAX_STANDING;
    }
    const titleData = syndicate.titles.find(x => x.level == (title == 0 ? 1 : title));
    if (!titleData) {
        throw new Error(`Invalid title level ${title} for syndicate ${affiliationTag}`);
    }
    return title == 0 ? titleData.minStanding : titleData.maxStanding;
};
_:hammer_and_wrench: Refactor suggestion_ **Add error handling and improve constants management.** The function could be more robust with proper error handling and constant management: 1. Non-null assertions (!.) could fail if data is malformed 2. No error handling for invalid affiliation tags 3. Magic number 125000 should be a named constant Consider this safer implementation: ```diff +const LIBRARY_SYNDICATE_MAX_STANDING = 125000; + const getMaxStanding = (affiliationTag: string, title: number): number => { const syndicate = ExportSyndicates[affiliationTag]; + if (!syndicate) { + throw new Error(`Invalid syndicate affiliation tag: ${affiliationTag}`); + } if (!syndicate.titles) { // LibrarySyndicate - return 125000; + return LIBRARY_SYNDICATE_MAX_STANDING; } + const titleData = syndicate.titles.find(x => x.level == (title == 0 ? 1 : title)); + if (!titleData) { + throw new Error(`Invalid title level ${title} for syndicate ${affiliationTag}`); + } - if (title == 0) { - return syndicate.titles.find(x => x.level == 1)!.minStanding; - } - return syndicate.titles.find(x => x.level == title)!.maxStanding; + return title == 0 ? titleData.minStanding : titleData.maxStanding; }; ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **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. `````suggestion const LIBRARY_SYNDICATE_MAX_STANDING = 125000; const getMaxStanding = (affiliationTag: string, title: number): number => { const syndicate = ExportSyndicates[affiliationTag]; if (!syndicate) { throw new Error(`Invalid syndicate affiliation tag: ${affiliationTag}`); } if (!syndicate.titles) { // LibrarySyndicate return LIBRARY_SYNDICATE_MAX_STANDING; } const titleData = syndicate.titles.find(x => x.level == (title == 0 ? 1 : title)); if (!titleData) { throw new Error(`Invalid title level ${title} for syndicate ${affiliationTag}`); } return title == 0 ? titleData.minStanding : titleData.maxStanding; }; ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] (Migrated from github.com) reviewed 2025-01-11 23:00:00 -08:00
coderabbitai[bot] (Migrated from github.com) left a comment
Author
Owner

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/controllers/api/syndicateStandingBonusController.ts (2)

33-38: Add validation and error handling for standing adjustments.

While the standing limit check is good, the code could be more robust with additional validations.

Consider these improvements:

+    if (gainedStanding < 0) {
+        throw new Error(`Invalid negative standing gain: ${gainedStanding}`);
+    }
     const max = getMaxStanding(request.Operation.AffiliationTag, syndicate.Title ?? 0);
+    if (max < 0) {
+        throw new Error(`Invalid maximum standing: ${max}`);
+    }
     if (syndicate.Standing + gainedStanding > max) {
         gainedStanding = max - syndicate.Standing;
     }

     syndicate.Standing += gainedStanding;

41-41: Consider tracking the TODO as a separate issue.

The TODO comment about subtracting from daily limit bin seems important for feature completeness.

Would you like me to create a GitHub issue to track this TODO item? I can help draft the issue with appropriate context and requirements.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 07d09610bafcfd2e90b57b84fda2a340b31a89b7 and 88741b1289760433613225dd06e7103b556f0d9e.

📒 Files selected for processing (1)
  • src/controllers/api/syndicateStandingBonusController.ts (2 hunks)
🔇 Additional comments (2)
src/controllers/api/syndicateStandingBonusController.ts (2)

27-30: Fix formatting and consider simplifying the initialization.

The code needs proper formatting and the push-and-index pattern could be simplified.

Apply this diff to fix the formatting and simplify the code:

 let syndicate = inventory.Affiliations.find(x => x.Tag == request.Operation.AffiliationTag);
 if (!syndicate) {
-        syndicate =
-            inventory.Affiliations[inventory.Affiliations.push({ Tag: request.Operation.AffiliationTag, Standing: 0 })];
+     syndicate = { Tag: request.Operation.AffiliationTag, Standing: 0 };
+     inventory.Affiliations.push(syndicate);
 }

66-76: Add error handling and improve constants management.

The function needs proper error handling and constant management.

Consider this safer implementation:

+const LIBRARY_SYNDICATE_MAX_STANDING = 125000;
+
 const getMaxStanding = (affiliationTag: string, title: number): number => {
     const syndicate = ExportSyndicates[affiliationTag];
+    if (!syndicate) {
+        throw new Error(`Invalid syndicate affiliation tag: ${affiliationTag}`);
+    }
     if (!syndicate.titles) {
         // LibrarySyndicate
-        return 125000;
+        return LIBRARY_SYNDICATE_MAX_STANDING;
     }
+    const titleData = syndicate.titles.find(x => x.level == (title == 0 ? 1 : title));
+    if (!titleData) {
+        throw new Error(`Invalid title level ${title} for syndicate ${affiliationTag}`);
+    }
-    if (title == 0) {
-        return syndicate.titles.find(x => x.level == 1)!.minStanding;
-    }
-    return syndicate.titles.find(x => x.level == title)!.maxStanding;
+    return title == 0 ? titleData.minStanding : titleData.maxStanding;
 };
**Actionable comments posted: 0** <details> <summary>🧹 Nitpick comments (2)</summary><blockquote> <details> <summary>src/controllers/api/syndicateStandingBonusController.ts (2)</summary><blockquote> `33-38`: **Add validation and error handling for standing adjustments.** While the standing limit check is good, the code could be more robust with additional validations. Consider these improvements: ```diff + if (gainedStanding < 0) { + throw new Error(`Invalid negative standing gain: ${gainedStanding}`); + } const max = getMaxStanding(request.Operation.AffiliationTag, syndicate.Title ?? 0); + if (max < 0) { + throw new Error(`Invalid maximum standing: ${max}`); + } if (syndicate.Standing + gainedStanding > max) { gainedStanding = max - syndicate.Standing; } syndicate.Standing += gainedStanding; ``` --- `41-41`: **Consider tracking the TODO as a separate issue.** The TODO comment about subtracting from daily limit bin seems important for feature completeness. Would you like me to create a GitHub issue to track this TODO item? I can help draft the issue with appropriate context and requirements. </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: .coderabbit.yaml** **Review profile: CHILL** **Plan: Pro** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 07d09610bafcfd2e90b57b84fda2a340b31a89b7 and 88741b1289760433613225dd06e7103b556f0d9e. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `src/controllers/api/syndicateStandingBonusController.ts` (2 hunks) </details> <details> <summary>🔇 Additional comments (2)</summary><blockquote> <details> <summary>src/controllers/api/syndicateStandingBonusController.ts (2)</summary> `27-30`: **Fix formatting and consider simplifying the initialization.** The code needs proper formatting and the push-and-index pattern could be simplified. Apply this diff to fix the formatting and simplify the code: ```diff let syndicate = inventory.Affiliations.find(x => x.Tag == request.Operation.AffiliationTag); if (!syndicate) { - syndicate = - inventory.Affiliations[inventory.Affiliations.push({ Tag: request.Operation.AffiliationTag, Standing: 0 })]; + syndicate = { Tag: request.Operation.AffiliationTag, Standing: 0 }; + inventory.Affiliations.push(syndicate); } ``` --- `66-76`: **Add error handling and improve constants management.** The function needs proper error handling and constant management. Consider this safer implementation: ```diff +const LIBRARY_SYNDICATE_MAX_STANDING = 125000; + const getMaxStanding = (affiliationTag: string, title: number): number => { const syndicate = ExportSyndicates[affiliationTag]; + if (!syndicate) { + throw new Error(`Invalid syndicate affiliation tag: ${affiliationTag}`); + } if (!syndicate.titles) { // LibrarySyndicate - return 125000; + return LIBRARY_SYNDICATE_MAX_STANDING; } + const titleData = syndicate.titles.find(x => x.level == (title == 0 ? 1 : title)); + if (!titleData) { + throw new Error(`Invalid title level ${title} for syndicate ${affiliationTag}`); + } - if (title == 0) { - return syndicate.titles.find(x => x.level == 1)!.minStanding; - } - return syndicate.titles.find(x => x.level == title)!.maxStanding; + return title == 0 ? titleData.minStanding : titleData.maxStanding; }; ``` </details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
coderabbitai[bot] (Migrated from github.com) reviewed 2025-01-13 08:57:13 -08:00
coderabbitai[bot] (Migrated from github.com) left a comment
Author
Owner

Actionable comments posted: 0

🔭 Outside diff range comments (1)
src/controllers/api/syndicateStandingBonusController.ts (1)

Add input validation to prevent standing calculation exploits

The standing calculation needs validation to prevent potential exploits:

  • Validate that item.ItemCount is positive before calculation
  • Verify medallion.standing is a valid positive number
  • Move the negation of ItemCount before the standing calculation
🔗 Analysis chain

Line range hint 11-22: Validate medallion standing calculations.

The medallion standing calculation should validate the input values to prevent potential exploits.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential validation in other files
rg -A 5 "medallion.standing" .
# Check for any existing validation patterns
ast-grep --pattern 'if (medallion) { $$$standing$$$}'

Length of output: 551


Script:

#!/bin/bash
# Find medallion type definitions
ast-grep --pattern 'interface $_ { $$$standing$$$}'
ast-grep --pattern 'type $_ = { $$$standing$$$}'

# Look for ItemCount validations
rg -A 5 "ItemCount" .

# Find ExportSyndicates definition
ast-grep --pattern 'const ExportSyndicates = $$$'
ast-grep --pattern 'export const ExportSyndicates = $$$'

Length of output: 76104

♻️ Duplicate comments (2)
src/controllers/api/syndicateStandingBonusController.ts (2)

27-30: ⚠️ Potential issue

Fix formatting and simplify initialization logic.

The push-and-index pattern is error-prone and harder to read than a direct approach.

The previous review comment suggesting simplification and proper formatting is still applicable.


66-76: ⚠️ Potential issue

Improve error handling and constant management.

The function needs more robust error handling and better constant management.

The previous review comment suggesting error handling improvements and constant management is still applicable.

Additionally, consider adding input validation for the title parameter to prevent potential security issues:

 const getMaxStanding = (affiliationTag: string, title: number): number => {
+    if (typeof title !== 'number' || title < 0) {
+        throw new Error(`Invalid title value: ${title}`);
+    }
     const syndicate = ExportSyndicates[affiliationTag];
🧹 Nitpick comments (2)
src/controllers/api/syndicateStandingBonusController.ts (2)

33-38: Add validation and logging for standing adjustments.

While the standing limit check is good, consider these improvements:

  1. Add validation for negative standing gains
  2. Add logging when standing is capped to help with debugging
 const max = getMaxStanding(request.Operation.AffiliationTag, syndicate.Title ?? 0);
+if (gainedStanding < 0) {
+    throw new Error(`Invalid negative standing gain: ${gainedStanding}`);
+}
 if (syndicate.Standing + gainedStanding > max) {
+    console.log(`Capping standing gain from ${gainedStanding} to ${max - syndicate.Standing} for ${request.Operation.AffiliationTag}`);
     gainedStanding = max - syndicate.Standing;
 }

41-41: Track TODO comment as a GitHub issue.

The TODO comment about subtracting from the daily limit bin should be tracked properly.

Would you like me to create a GitHub issue to track this TODO item?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 88741b1289760433613225dd06e7103b556f0d9e and 3890e3193b.

📒 Files selected for processing (1)
  • src/controllers/api/syndicateStandingBonusController.ts (2 hunks)
**Actionable comments posted: 0** <details> <summary>🔭 Outside diff range comments (1)</summary><blockquote> <details> <summary>src/controllers/api/syndicateStandingBonusController.ts (1)</summary><blockquote> **Add input validation to prevent standing calculation exploits** The standing calculation needs validation to prevent potential exploits: - Validate that `item.ItemCount` is positive before calculation - Verify `medallion.standing` is a valid positive number - Move the negation of `ItemCount` before the standing calculation <details> <summary>🔗 Analysis chain</summary> Line range hint `11-22`: **Validate medallion standing calculations.** The medallion standing calculation should validate the input values to prevent potential exploits. </details> <details> <summary>🏁 Scripts executed</summary> The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Check for potential validation in other files rg -A 5 "medallion.standing" . # Check for any existing validation patterns ast-grep --pattern 'if (medallion) { $$$standing$$$}' ``` Length of output: 551 --- Script: ```shell #!/bin/bash # Find medallion type definitions ast-grep --pattern 'interface $_ { $$$standing$$$}' ast-grep --pattern 'type $_ = { $$$standing$$$}' # Look for ItemCount validations rg -A 5 "ItemCount" . # Find ExportSyndicates definition ast-grep --pattern 'const ExportSyndicates = $$$' ast-grep --pattern 'export const ExportSyndicates = $$$' ``` Length of output: 76104 </details> </blockquote></details> </blockquote></details> <details> <summary>♻️ Duplicate comments (2)</summary><blockquote> <details> <summary>src/controllers/api/syndicateStandingBonusController.ts (2)</summary><blockquote> `27-30`: _:warning: Potential issue_ **Fix formatting and simplify initialization logic.** The push-and-index pattern is error-prone and harder to read than a direct approach. The previous review comment suggesting simplification and proper formatting is still applicable. --- `66-76`: _:warning: Potential issue_ **Improve error handling and constant management.** The function needs more robust error handling and better constant management. The previous review comment suggesting error handling improvements and constant management is still applicable. Additionally, consider adding input validation for the title parameter to prevent potential security issues: ```diff const getMaxStanding = (affiliationTag: string, title: number): number => { + if (typeof title !== 'number' || title < 0) { + throw new Error(`Invalid title value: ${title}`); + } const syndicate = ExportSyndicates[affiliationTag]; ``` </blockquote></details> </blockquote></details> <details> <summary>🧹 Nitpick comments (2)</summary><blockquote> <details> <summary>src/controllers/api/syndicateStandingBonusController.ts (2)</summary><blockquote> `33-38`: **Add validation and logging for standing adjustments.** While the standing limit check is good, consider these improvements: 1. Add validation for negative standing gains 2. Add logging when standing is capped to help with debugging ```diff const max = getMaxStanding(request.Operation.AffiliationTag, syndicate.Title ?? 0); +if (gainedStanding < 0) { + throw new Error(`Invalid negative standing gain: ${gainedStanding}`); +} if (syndicate.Standing + gainedStanding > max) { + console.log(`Capping standing gain from ${gainedStanding} to ${max - syndicate.Standing} for ${request.Operation.AffiliationTag}`); gainedStanding = max - syndicate.Standing; } ``` --- `41-41`: **Track TODO comment as a GitHub issue.** The TODO comment about subtracting from the daily limit bin should be tracked properly. Would you like me to create a GitHub issue to track this TODO item? </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: .coderabbit.yaml** **Review profile: CHILL** **Plan: Pro** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 88741b1289760433613225dd06e7103b556f0d9e and 3890e3193b100c8aa5710bd55f4bb845eaf3f29d. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `src/controllers/api/syndicateStandingBonusController.ts` (2 hunks) </details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Sign in to join this conversation.
No description provided.