feat: subtract standing for syndicate purchases #608

Merged
Sainan merged 1 commits from favours into main 2024-12-22 14:31:30 -08:00
Owner

Closes #566

Closes #566
coderabbitai[bot] commented 2024-12-22 13:59:47 -08:00 (Migrated from github.com)
Author
Owner

Walkthrough

The pull request introduces changes to enhance the handling of syndicate purchases within the application. Modifications are made across three files: package.json, src/services/purchaseService.ts, and src/types/purchaseTypes.ts.

In package.json, the version of the warframe-public-export-plus dependency is updated from ^0.5.9 to ^0.5.10. The purchaseTypes.ts file is modified to include new optional properties in the IPurchaseParams interface: SyndicateTag and UseFreeFavor. Additionally, a new interface, IPurchaseResponse, is defined, which contains a property InventoryChanges and an optional property Standing.

The most significant changes occur in purchaseService.ts, where the return type of the handleStoreItemAcquisition method is changed to IPurchaseResponse. A new case (case 2) is added to the handlePurchase function to manage syndicate-related purchases, incorporating checks for the UseFreeFavor parameter and updating the user's standing based on the favor cost.

Assessment against linked issues

Objective Addressed Explanation
Consume Reputation when Buying from Faction Vendors [#566]
Handle Syndicate Purchase Logic
Track Standing Changes

The changes effectively address the objectives outlined in the linked issue by implementing a mechanism for handling syndicate purchases, which includes updating the user's standing and ensuring reputation is consumed appropriately.


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 pull request introduces changes to enhance the handling of syndicate purchases within the application. Modifications are made across three files: `package.json`, `src/services/purchaseService.ts`, and `src/types/purchaseTypes.ts`. In `package.json`, the version of the `warframe-public-export-plus` dependency is updated from `^0.5.9` to `^0.5.10`. The `purchaseTypes.ts` file is modified to include new optional properties in the `IPurchaseParams` interface: `SyndicateTag` and `UseFreeFavor`. Additionally, a new interface, `IPurchaseResponse`, is defined, which contains a property `InventoryChanges` and an optional property `Standing`. The most significant changes occur in `purchaseService.ts`, where the return type of the `handleStoreItemAcquisition` method is changed to `IPurchaseResponse`. A new case (case 2) is added to the `handlePurchase` function to manage syndicate-related purchases, incorporating checks for the `UseFreeFavor` parameter and updating the user's standing based on the favor cost. ## Assessment against linked issues | Objective | Addressed | Explanation | |-----------------------------------------------------|-----------|-------------| | Consume Reputation when Buying from Faction Vendors [#566] | ✅ | | | Handle Syndicate Purchase Logic | ✅ | | | Track Standing Changes | ✅ | | The changes effectively address the objectives outlined in the linked issue by implementing a mechanism for handling syndicate purchases, which includes updating the user's standing and ensuring reputation is consumed appropriately. <!-- walkthrough_end --> <!-- internal state start --> <!-- FAHghAtBAEAqAWBLAztF0CGA7TBXALgPYQDmAplmQE4b5kAm0AxoQLasX4Bc0ADldEIAjAFZkm+RADcyqIQE9mhetQxChifADoMiaFAB8wY+CjGAxOegAFAErQAyrnYYq84wjJ9cAGx/QqMgBHXFl8aEl8HwZoACIAMzJaHmRcIXwaCWhkfGx6RCwSaHjCAWR5LHymWi9eXComeAxkWVjoAHdm7LTWTTpGBQj4L1wWgQddLGxMSrRURBUsSXjEGMH8YegsZyFqaAA2AAYADi04Tf5EVldFOqpeQhbBeKH0OzmIwjRWXmiOJcwxSS+HqXg2tEwfkI7VQJQEGy8qXSmUkhBwhBeOTyBSK7WGOGuAGscd4Gk0WrCqGxAeVKohqnQzgh0I1sOQPgU6JUYkRoBQmlgmGDNvFcILUVMfJpFIEfDVGLzaVUahEaFhkBgJIg0ah2pokDgEXwqWIJGcAIL0fISjB+eQAGleqHe6ClWEJPK+KFSXm2rF2AgArPt9o6CsrJIUhhDNJgrYFkBSabxxIgVkwlILqOiBIEQmFjWQpNrRj4ZboWowCkNaibxPgAOTzROhVWaj1UM4AMVKxXqCIEKlyiB8yEdRve1Rwu0wTCFiZiEKNJSheqjAFVbAAZHgAbXg+HwvGQXAA9KeSPq0loWKxT8heJqKAURM1qDIqKeHI+hQA5F8YA477UKedR+KeRzHAAugAFAeR4nuel4bNet73j+z5YK+Ywfl+GH/lhgHAZ+YE+BBJwAJRaMYhgmJAMAUIwGJ4EQpAUKo/RKOwnA8PwgiiPW0iyNAgwsCoNDqJoOh6LRpgwMyzYzCx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NFSC0WCnhHxypCD/dEaYRjWmJn4YgYKXrHCQ9WzQi5691vb13qFm2+MVteHQGQkeKgVhJsdLcnpOzbvUEk4FxDgy3AociuM5JiTAuYaQ0LsZb8MXoiu2iG7NS7t85iuk7EhRvvgt4egHHNiMBNf4h0+e0AACimpeHtN9Ty7W6vCWpVcDQRQmV8AXZ5/dk82tPskFSjBY1K6SD0M8WrglarfflTPdQKiVLLmqD8Aco54CY1gkSfqsdkx5jdIkFwjV3y+XPcKSGq18KvCZuDbaaUAQyBylEV8IRVf8w5GPrMONkjc2+XzeTQbXxi3iFLRKVAlMZbDWrdA2tGZOBMwzjASDhAVfotPgFtX72aje4APyic1wwqbDO1v2sOxN1L2siup8S4/VPnnnYz6pPPvzDAhbw9UdlJHpQN96exylbfJ3d+U/3+N1gx2x+cWp+pWF+VcTaCG9OM2i+Qslaw0dOy2Cq+2yyNOW2RGJ+CWoBL8l+Tas+t+z29+/OWG0uqGnuGGAuaKwueqR+O+Cqv+VmqBLQR+jmpGxWWW9qZWOB1+c+vOC+L2tuoeOIb+cG3um+JAAA3I4IIYUKejJlQJIbhruFBDQd/nQcgWQJtkwegcAZgRwWAXlq7LRKAPRAzExC8BgAQCpOxOpDEJpDxDpHpA1hKqJMoKZBoOZDJFZMYVAFxL0PgAAPoLDID+GBDFhLwMD+FYjwFGFyQiTHQADM9Ax0wSgYV0AA7MdJkcdEKDQvEfEYGPQAACzHBCDHAYA0IpGFFkA0JJHBiBiBjxGWRGCxGHCHD0DxHJFCCFFzghjHT7BMAqCFGHBpHxFCAZE1HHQ3TxGFFpFXQlH1EDFCBNE2QwCaSaCBH0DBGhGrDtARGMRNFAA --> <!-- internal state 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 2024-12-22 14:01:36 -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 2175e003cc and b93d9ba5179999ce2335d48b8a2ba54e2d956553.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • package.json (1 hunks)
  • src/services/purchaseService.ts (3 hunks)
  • src/types/purchaseTypes.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • package.json
🔇 Additional comments (4)
src/services/purchaseService.ts (3)

13-13: Good addition of IPurchaseResponse import.
By importing IPurchaseResponse, you align with the new structured return type. This increases clarity and consistency for your purchase logic.


121-121: Adopting the IPurchaseResponse return type is a good improvement.
Switching the return type to IPurchaseResponse clarifies the outcome of store item acquisitions and fosters better type safety.


15-15: Verify that ExportSyndicates is always defined.
Ensure that ExportSyndicates is always available at runtime, especially if it originates from a dynamically generated or external source. Otherwise, you may encounter runtime errors in the new syndicate purchase logic.

Verification successful

Let me verify the import source and its usage by checking the package.json and the actual usage patterns.


ExportSyndicates is properly defined and safely used

The verification shows that:

  1. The package warframe-public-export-plus is properly defined in package.json (version ^0.5.10)
  2. ExportSyndicates is used with appropriate null checks:
    • The syndicate lookup is guarded with if (syndicate)
    • The parent condition checks !purchaseRequest.PurchaseParams.UseFreeFavor!
    • Further operations are nested within these safety checks
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Searching codebase for ExportSyndicates references to verify usage.
# We'll look for references to confirm no undefined references exist.
rg -A 5 "ExportSyndicates"

Length of output: 2435


Script:

#!/bin/bash
# Check package.json for the dependency
cat package.json | jq '.dependencies["warframe-public-export-plus"]'

# Check if ExportSyndicates is used with proper null checks
ast-grep --pattern 'const $_ = ExportSyndicates[$_]'

Length of output: 236


Script:

#!/bin/bash
# Check the usage context of ExportSyndicates to verify null checks
rg -B 2 -A 3 "const syndicate = ExportSyndicates\[syndicateTag\]"

# Check if the package is actually imported in other places
rg "from \"warframe-public-export-plus\"" -B 1 -A 1

Length of output: 3729

src/types/purchaseTypes.ts (1)

22-29: New IPurchaseResponse interface promotes clarity.
Defining a separate IPurchaseResponse type is a great way to unify the structure of purchase operations and account for changes in standing.

**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 2175e003cc91fcdb4237a982040e352d81aef4cd and b93d9ba5179999ce2335d48b8a2ba54e2d956553. </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 (3)</summary> * `package.json` (1 hunks) * `src/services/purchaseService.ts` (3 hunks) * `src/types/purchaseTypes.ts` (1 hunks) </details> <details> <summary>✅ Files skipped from review due to trivial changes (1)</summary> * package.json </details> <details> <summary>🔇 Additional comments (4)</summary> <details> <summary>src/services/purchaseService.ts (3)</summary> `13-13`: **Good addition of IPurchaseResponse import.** By importing IPurchaseResponse, you align with the new structured return type. This increases clarity and consistency for your purchase logic. --- `121-121`: **Adopting the IPurchaseResponse return type is a good improvement.** Switching the return type to IPurchaseResponse clarifies the outcome of store item acquisitions and fosters better type safety. --- `15-15`: **Verify that ExportSyndicates is always defined.** Ensure that ExportSyndicates is always available at runtime, especially if it originates from a dynamically generated or external source. Otherwise, you may encounter runtime errors in the new syndicate purchase logic. <details> <summary>✅ Verification successful</summary> Let me verify the import source and its usage by checking the package.json and the actual usage patterns. --- **ExportSyndicates is properly defined and safely used** The verification shows that: 1. The package `warframe-public-export-plus` is properly defined in package.json (version ^0.5.10) 2. ExportSyndicates is used with appropriate null checks: - The syndicate lookup is guarded with `if (syndicate)` - The parent condition checks `!purchaseRequest.PurchaseParams.UseFreeFavor!` - Further operations are nested within these safety checks </details> <details> <summary>🏁 Scripts executed</summary> The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Description: Searching codebase for ExportSyndicates references to verify usage. # We'll look for references to confirm no undefined references exist. rg -A 5 "ExportSyndicates" ``` Length of output: 2435 --- Script: ```shell #!/bin/bash # Check package.json for the dependency cat package.json | jq '.dependencies["warframe-public-export-plus"]' # Check if ExportSyndicates is used with proper null checks ast-grep --pattern 'const $_ = ExportSyndicates[$_]' ``` Length of output: 236 --- Script: ```shell #!/bin/bash # Check the usage context of ExportSyndicates to verify null checks rg -B 2 -A 3 "const syndicate = ExportSyndicates\[syndicateTag\]" # Check if the package is actually imported in other places rg "from \"warframe-public-export-plus\"" -B 1 -A 1 ``` Length of output: 3729 </details> </details> <details> <summary>src/types/purchaseTypes.ts (1)</summary> `22-29`: **New IPurchaseResponse interface promotes clarity.** Defining a separate IPurchaseResponse type is a great way to unify the structure of purchase operations and account for changes in standing. </details> </details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
@ -14,2 +14,4 @@
UsePremium: boolean;
ExpectedPrice: number;
SyndicateTag?: string; // for Source 2
UseFreeFavor?: boolean; // for Source 2
coderabbitai[bot] (Migrated from github.com) commented 2024-12-22 14:01:35 -08:00
Author
Owner

🛠️ Refactor suggestion

Optional parameter usage caution.
• Marking SyndicateTag and UseFreeFavor as optional is correct if they only apply to specific purchase scenarios.
• However, the service code uses “!” to bypass null checks. Consider safer patterns to avoid runtime crashes when these properties are not passed.

_:hammer_and_wrench: Refactor suggestion_ **Optional parameter usage caution.** • Marking SyndicateTag and UseFreeFavor as optional is correct if they only apply to specific purchase scenarios. • However, the service code uses “!” to bypass null checks. Consider safer patterns to avoid runtime crashes when these properties are not passed. <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] (Migrated from github.com) reviewed 2024-12-22 14:31:08 -08:00
coderabbitai[bot] (Migrated from github.com) left a comment
Author
Owner

Actionable comments posted: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b93d9ba5179999ce2335d48b8a2ba54e2d956553 and 00d39bb4cc.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • package.json (1 hunks)
  • src/services/purchaseService.ts (3 hunks)
  • src/types/purchaseTypes.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • package.json
  • src/types/purchaseTypes.ts
🔇 Additional comments (2)
src/services/purchaseService.ts (2)

14-14: LGTM: Import changes align with new functionality

The addition of IPurchaseResponse to imports correctly supports the new standing-related functionality.


162-162: LGTM: Return type change is appropriate

The return type change to Promise<IPurchaseResponse> correctly supports the new standing-related functionality.

**Actionable comments posted: 1** <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 b93d9ba5179999ce2335d48b8a2ba54e2d956553 and 00d39bb4cc6696cde4073b792d91034718b55cdb. </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 (3)</summary> * `package.json` (1 hunks) * `src/services/purchaseService.ts` (3 hunks) * `src/types/purchaseTypes.ts` (1 hunks) </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (2)</summary> * package.json * src/types/purchaseTypes.ts </details> <details> <summary>🔇 Additional comments (2)</summary> <details> <summary>src/services/purchaseService.ts (2)</summary> `14-14`: **LGTM: Import changes align with new functionality** The addition of `IPurchaseResponse` to imports correctly supports the new standing-related functionality. --- `162-162`: **LGTM: Return type change is appropriate** The return type change to `Promise<IPurchaseResponse>` correctly supports the new standing-related functionality. </details> </details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
coderabbitai[bot] (Migrated from github.com) commented 2024-12-22 14:31:07 -08:00
Author
Owner

🛠️ Refactor suggestion

Improve robustness and readability of syndicate purchase handling

The current implementation has several areas for improvement:

  1. Excessive use of non-null assertions (!) could lead to runtime errors
  2. Deep nesting makes the code harder to maintain
  3. Missing error handling for invalid syndicate/favor
  4. No validation before subtracting standing

Consider refactoring to this more robust implementation:

 case 2: {
-    if (!purchaseRequest.PurchaseParams.UseFreeFavor!) {
-        const syndicateTag = purchaseRequest.PurchaseParams.SyndicateTag!;
-        const syndicate = ExportSyndicates[syndicateTag];
-        if (syndicate) {
-            const favour = syndicate.favours.find(x => x.storeItem == purchaseRequest.PurchaseParams.StoreItem);
-            if (favour) {
-                const inventory = await getInventory(accountId);
-                const affiliation = inventory.Affiliations.find(x => x.Tag == syndicateTag);
-                if (affiliation) {
-                    purchaseResponse.Standing = [
-                        {
-                            Tag: syndicateTag,
-                            Standing: favour.standingCost
-                        }
-                    ];
-                    affiliation.Standing -= favour.standingCost;
-                    await inventory.save();
-                }
-            }
-        }
-    }
-    break;
+    const { UseFreeFavor, SyndicateTag } = purchaseRequest.PurchaseParams;
+    
+    // Skip standing deduction if using free favor
+    if (UseFreeFavor === true) {
+        break;
+    }
+    
+    if (!SyndicateTag) {
+        throw new Error("SyndicateTag is required for syndicate purchases");
+    }
+    
+    const syndicate = ExportSyndicates[SyndicateTag];
+    if (!syndicate) {
+        throw new Error(`Invalid syndicate tag: ${SyndicateTag}`);
+    }
+    
+    const favour = syndicate.favours.find(x => x.storeItem === purchaseRequest.PurchaseParams.StoreItem);
+    if (!favour) {
+        throw new Error(`Favor not found for item: ${purchaseRequest.PurchaseParams.StoreItem}`);
+    }
+    
+    const inventory = await getInventory(accountId);
+    const affiliation = inventory.Affiliations.find(x => x.Tag === SyndicateTag);
+    if (!affiliation) {
+        throw new Error(`User not affiliated with syndicate: ${SyndicateTag}`);
+    }
+    
+    // Validate sufficient standing
+    if (affiliation.Standing < favour.standingCost) {
+        throw new Error(`Insufficient standing for purchase. Required: ${favour.standingCost}, Available: ${affiliation.Standing}`);
+    }
+    
+    purchaseResponse.Standing = [{
+        Tag: SyndicateTag,
+        Standing: favour.standingCost
+    }];
+    
+    affiliation.Standing -= favour.standingCost;
+    await inventory.save();
+    break;
+}

Key improvements:

  1. Proper error handling with descriptive messages
  2. Standing validation before purchase
  3. Early returns reduce nesting
  4. Type-safe comparisons
  5. Destructured parameters improve readability
📝 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.

        case 2: {
            const { UseFreeFavor, SyndicateTag } = purchaseRequest.PurchaseParams;
            
            // Skip standing deduction if using free favor
            if (UseFreeFavor === true) {
                break;
            }
            
            if (!SyndicateTag) {
                throw new Error("SyndicateTag is required for syndicate purchases");
            }
            
            const syndicate = ExportSyndicates[SyndicateTag];
            if (!syndicate) {
                throw new Error(`Invalid syndicate tag: ${SyndicateTag}`);
            }
            
            const favour = syndicate.favours.find(x => x.storeItem === purchaseRequest.PurchaseParams.StoreItem);
            if (!favour) {
                throw new Error(`Favor not found for item: ${purchaseRequest.PurchaseParams.StoreItem}`);
            }
            
            const inventory = await getInventory(accountId);
            const affiliation = inventory.Affiliations.find(x => x.Tag === SyndicateTag);
            if (!affiliation) {
                throw new Error(`User not affiliated with syndicate: ${SyndicateTag}`);
            }
            
            // Validate sufficient standing
            if (affiliation.Standing < favour.standingCost) {
                throw new Error(`Insufficient standing for purchase. Required: ${favour.standingCost}, Available: ${affiliation.Standing}`);
            }
            
            purchaseResponse.Standing = [{
                Tag: SyndicateTag,
                Standing: favour.standingCost
            }];
            
            affiliation.Standing -= favour.standingCost;
            await inventory.save();
            break;
        }
_:hammer_and_wrench: Refactor suggestion_ **Improve robustness and readability of syndicate purchase handling** The current implementation has several areas for improvement: 1. Excessive use of non-null assertions (!) could lead to runtime errors 2. Deep nesting makes the code harder to maintain 3. Missing error handling for invalid syndicate/favor 4. No validation before subtracting standing Consider refactoring to this more robust implementation: ```diff case 2: { - if (!purchaseRequest.PurchaseParams.UseFreeFavor!) { - const syndicateTag = purchaseRequest.PurchaseParams.SyndicateTag!; - const syndicate = ExportSyndicates[syndicateTag]; - if (syndicate) { - const favour = syndicate.favours.find(x => x.storeItem == purchaseRequest.PurchaseParams.StoreItem); - if (favour) { - const inventory = await getInventory(accountId); - const affiliation = inventory.Affiliations.find(x => x.Tag == syndicateTag); - if (affiliation) { - purchaseResponse.Standing = [ - { - Tag: syndicateTag, - Standing: favour.standingCost - } - ]; - affiliation.Standing -= favour.standingCost; - await inventory.save(); - } - } - } - } - break; + const { UseFreeFavor, SyndicateTag } = purchaseRequest.PurchaseParams; + + // Skip standing deduction if using free favor + if (UseFreeFavor === true) { + break; + } + + if (!SyndicateTag) { + throw new Error("SyndicateTag is required for syndicate purchases"); + } + + const syndicate = ExportSyndicates[SyndicateTag]; + if (!syndicate) { + throw new Error(`Invalid syndicate tag: ${SyndicateTag}`); + } + + const favour = syndicate.favours.find(x => x.storeItem === purchaseRequest.PurchaseParams.StoreItem); + if (!favour) { + throw new Error(`Favor not found for item: ${purchaseRequest.PurchaseParams.StoreItem}`); + } + + const inventory = await getInventory(accountId); + const affiliation = inventory.Affiliations.find(x => x.Tag === SyndicateTag); + if (!affiliation) { + throw new Error(`User not affiliated with syndicate: ${SyndicateTag}`); + } + + // Validate sufficient standing + if (affiliation.Standing < favour.standingCost) { + throw new Error(`Insufficient standing for purchase. Required: ${favour.standingCost}, Available: ${affiliation.Standing}`); + } + + purchaseResponse.Standing = [{ + Tag: SyndicateTag, + Standing: favour.standingCost + }]; + + affiliation.Standing -= favour.standingCost; + await inventory.save(); + break; +} ``` Key improvements: 1. Proper error handling with descriptive messages 2. Standing validation before purchase 3. Early returns reduce nesting 4. Type-safe comparisons 5. Destructured parameters improve readability <!-- 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 case 2: { const { UseFreeFavor, SyndicateTag } = purchaseRequest.PurchaseParams; // Skip standing deduction if using free favor if (UseFreeFavor === true) { break; } if (!SyndicateTag) { throw new Error("SyndicateTag is required for syndicate purchases"); } const syndicate = ExportSyndicates[SyndicateTag]; if (!syndicate) { throw new Error(`Invalid syndicate tag: ${SyndicateTag}`); } const favour = syndicate.favours.find(x => x.storeItem === purchaseRequest.PurchaseParams.StoreItem); if (!favour) { throw new Error(`Favor not found for item: ${purchaseRequest.PurchaseParams.StoreItem}`); } const inventory = await getInventory(accountId); const affiliation = inventory.Affiliations.find(x => x.Tag === SyndicateTag); if (!affiliation) { throw new Error(`User not affiliated with syndicate: ${SyndicateTag}`); } // Validate sufficient standing if (affiliation.Standing < favour.standingCost) { throw new Error(`Insufficient standing for purchase. Required: ${favour.standingCost}, Available: ${affiliation.Standing}`); } purchaseResponse.Standing = [{ Tag: SyndicateTag, Standing: favour.standingCost }]; affiliation.Standing -= favour.standingCost; await inventory.save(); break; } ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
Sign in to join this conversation.
No description provided.