feat: implement socketing of ayatan sculptures #542

Merged
Sainan merged 2 commits from ayatan into main 2024-10-12 14:51:45 -07:00
Owner

closes #541

closes #541
coderabbitai[bot] commented 2024-10-11 16:37:04 -07:00 (Migrated from github.com)
Author
Owner

Walkthrough

The changes in this pull request include updates to various files within the wf-emulator project. The package.json file has been modified to increment the version of the warframe-public-export-plus dependency from ^0.5.1 to ^0.5.2. A new controller, fusionTreasuresController.ts, has been introduced to handle requests related to fusion treasures in an Express application. This controller includes an interface for incoming requests and a function to process these requests, managing the user's inventory and updating it based on the treasures involved. The getItemListsController.ts file has been updated to modify how the uniqueName property is assigned for items, changing the categorization logic. Additionally, a new route has been added in api.ts for the fusionTreasures.php endpoint, linking it to the new controller. Lastly, the addFusionTreasures function in inventoryService.ts has been corrected to improve the accuracy of item index retrieval in the FusionTreasures array.

Assessment against linked issues

Objective Addressed Explanation
Implement POST endpoint for /api/fusionTreasures.php (541)
Ensure functionality for installing Ayatan Stars (541) The issue description does not confirm if the installation functionality is fully addressed.
  • #517: This PR updates the warframe-public-export-plus dependency version from ^0.4.4 to ^0.5.0, which is directly related to the main PR's update from ^0.5.1 to ^0.5.2.
  • #537: This PR updates the warframe-public-export-plus dependency version from ^0.5.0 to ^0.5.1, which is also directly related to the main PR's update from ^0.5.1 to ^0.5.2.

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 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 this pull request include updates to various files within the `wf-emulator` project. The `package.json` file has been modified to increment the version of the `warframe-public-export-plus` dependency from `^0.5.1` to `^0.5.2`. A new controller, `fusionTreasuresController.ts`, has been introduced to handle requests related to fusion treasures in an Express application. This controller includes an interface for incoming requests and a function to process these requests, managing the user's inventory and updating it based on the treasures involved. The `getItemListsController.ts` file has been updated to modify how the `uniqueName` property is assigned for items, changing the categorization logic. Additionally, a new route has been added in `api.ts` for the `fusionTreasures.php` endpoint, linking it to the new controller. Lastly, the `addFusionTreasures` function in `inventoryService.ts` has been corrected to improve the accuracy of item index retrieval in the `FusionTreasures` array. ## Assessment against linked issues | Objective | Addressed | Explanation | |------------------------------------------------------------|-----------|-------------------------------------| | Implement POST endpoint for `/api/fusionTreasures.php` (541) | ✅ | | | Ensure functionality for installing Ayatan Stars (541) | ❌ | The issue description does not confirm if the installation functionality is fully addressed. | ## Possibly related PRs - #517: This PR updates the `warframe-public-export-plus` dependency version from `^0.4.4` to `^0.5.0`, which is directly related to the main PR's update from `^0.5.1` to `^0.5.2`. - #537: This PR updates the `warframe-public-export-plus` dependency version from `^0.5.0` to `^0.5.1`, which is also directly related to the main PR's update from `^0.5.1` to `^0.5.2`. <!-- walkthrough_end --><!-- This is an auto-generated comment: raw summary by coderabbit.ai --> <!-- ``` # Consolidated Changesets ## package.json ### Summary of Changes The `package.json` file for the `wf-emulator` project has been updated with a modification to the version of the `warframe-public-export-plus` dependency. The version has been incremented from `^0.5.1` to `^0.5.2`. No other changes to dependencies, scripts, or other configurations are present in this diff. ### Alterations to the Declarations of Exported or Public Entities - Dependency version updated: `"warframe-public-export-plus": "^0.5.1"` → `"warframe-public-export-plus": "^0.5.2"` in `package.json` --- ## src/controllers/api/fusionTreasuresController.ts ### Summary of Changes The new file `fusionTreasuresController.ts` introduces a controller for handling fusion treasure requests in an Express application. It imports necessary modules and types, including `RequestHandler` from Express and various services for managing inventory. The controller defines an interface `IFusionTreasureRequest` to structure incoming requests, which include the names of old and new treasures. A helper function `parseFusionTreasure` is implemented to convert a treasure name and count into an `IFusionTreasure` object, extracting the item type and socket information from the name. The main controller function, `fusionTreasuresController`, is defined as an asynchronous request handler. It retrieves the account ID from the request, fetches the user's inventory, and parses the request body to obtain the old and new treasure names. The controller then creates `IFusionTreasure` objects for both the old and new treasures. It adds these treasures to the inventory using the `addFusionTreasures` function. Additionally, it calculates the changes in miscellaneous items based on the filled sockets of the new treasure compared to the old one. For each filled socket, it prepares a change to the corresponding miscellaneous item, which is then added to the inventory using `addMiscItems`. Finally, the inventory is saved, and the response is sent back to the client. This controller encapsulates the logic for swapping treasures and managing associated inventory changes. ### Alterations to the Declarations of Exported or Public Entities - New interface added: `interface IFusionTreasureRequest` in `src/controllers/api/fusionTreasuresController.ts` - New method added: `export const fusionTreasuresController: RequestHandler` in `src/controllers/api/fusionTreasuresController.ts` --- ## src/controllers/custom/getItemListsController.ts ### Summary of Changes The diff introduces modifications to the `getItemListsController` function within the `src/controllers/custom/getItemListsController.ts` file. The primary change involves the construction of the `miscitems` array, specifically in how the `uniqueName` property is assigned for items derived from `ExportResources`. The previous implementation concatenated the string "MiscItems:" with the `uniqueName`, while the updated version prefixes the `uniqueName` with the `item.productCategory`. This change alters the categorization of resources in the response structure. Additionally, the overall structure of the response object remains intact, which includes arrays for `warframes`, `weapons`, `miscitems`, `mods`, and `badItems`, along with the inclusion of `archonCrystalUpgrades`. The logic for populating the `weapons`, `mods`, and `badItems` remains unchanged, ensuring that the core functionality of the controller is preserved while modifying how resource items are categorized. ### Alterations to the Declarations of Exported or Public Entities - No alterations to the declarations of exported or public entities were made in this diff. --- ## src/routes/api.ts ### Summary of Changes The diff introduces a new route handler for the `fusionTreasures.php` endpoint, linking it to the `fusionTreasuresController` for POST requests. This addition is reflected in the import statements at the top of the file, where `fusionTreasuresController` is imported from the appropriate module. The new route is defined in the `apiRouter` under the POST method, allowing clients to interact with the fusion treasures functionality. Additionally, the existing structure of the API routes remains unchanged, with no modifications to other endpoints or their associated controllers. ### Alterations to the Declarations of Exported or Public Entities - Method added: `apiRouter.post("/fusionTreasures.php", fusionTreasuresController);` in `src/routes/api.ts` - Import added: `import { fusionTreasuresController } from "@/src/controllers/api/fusionTreasuresController";` in `src/routes/api.ts` --- ## src/services/inventoryService.ts ### Summary of Changes The diff introduces a modification to the `addFusionTreasures` function within the `src/services/inventoryService.ts` file. The change updates the logic for finding an index in the `FusionTreasures` array. The previous implementation used a separate line for each condition in the `findIndex` method, which was incorrect as it did not properly combine the conditions. The new implementation correctly combines the conditions using a logical AND operator, ensuring that both the `ItemType` and `Sockets` properties are checked simultaneously. This change enhances the accuracy of the index retrieval for items in the `FusionTreasures` array, which is crucial for correctly updating the item count. ### Alterations to the Declarations of Exported or Public Entities - No alterations to the declarations of exported or public entities were made in this diff. ``` --> <!-- end of auto-generated comment: raw summary by coderabbit.ai --><!-- This is an auto-generated comment: pr objectives by coderabbit.ai --> <!-- ## PR Summary The pull request titled "feat: implement socketing of ayatan sculptures" was submitted by the user Sainan and is identified as PR number 542. The primary purpose of this PR is to address an issue related to the installation of Ayatan Stars in Ayatan Treasures, as indicated by its closure of issue #541. The description of the PR does not provide additional details beyond this closure. The PR can be accessed through the provided URL: [PR 542](https://github.com/spaceninjaserver/SpaceNinjaServer/pull/542). ## Objectives from Linked Issues The linked issue #541, titled "Cannot install Ayatan Stars in Ayatan Treasures," outlines a specific problem encountered when attempting to install Ayatan Stars. The issue description includes an error log indicating a failure to connect to the endpoint for the fusion of treasures, specifically a POST request to `/api/fusionTreasures.php`, which returned a 404 error. The log details the data that was provided to the endpoint, including the old and new treasure names, but highlights that the endpoint is unknown, leading to the failure of the operation. The objective of the linked issue is to resolve this installation problem, which is directly addressed by the changes proposed in PR 542. --> <!-- end of auto-generated comment: pr objectives by coderabbit.ai --><!-- commit_ids_reviewed_start --> <!-- 5f7e1bc764d13733f9732dcb8e2f594710266269 --> <!-- commit_ids_reviewed_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 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://coderabbit.ai/docs) 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-10-11 16:42:50 -07:00
coderabbitai[bot] (Migrated from github.com) left a comment
Author
Owner

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (3)
src/services/inventoryService.ts (2)

Line range hint 657-670: Improved item matching logic for FusionTreasures

The change in the addFusionTreasures function enhances the accuracy of item matching. By including both ItemType and Sockets in the comparison, it ensures that items with the same type but different socket configurations are treated as distinct. This prevents incorrect merging of items and maintains the integrity of the inventory.

Consider adding a type guard or default value for the Sockets property to handle potential undefined values more explicitly:

-const itemIndex = FusionTreasures.findIndex(i => i.ItemType == ItemType && (i.Sockets || 0) == (Sockets || 0));
+const itemIndex = FusionTreasures.findIndex(i => i.ItemType === ItemType && (i.Sockets ?? 0) === (Sockets ?? 0));

This change uses the nullish coalescing operator (??) for clearer intent and strict equality (===) for consistency with TypeScript best practices.


Line range hint 1-670: General code quality improvements

While reviewing the file, I noticed some areas where we could improve overall code quality and consistency:

  1. Error handling: Consider implementing a more consistent error handling strategy across functions. For example, the upgradeMod function uses try-catch, while others don't.

  2. Type safety: Enhance type safety by using more specific types instead of any or undefined. For instance, in the updateGeneric function, consider creating a specific type for the data parameter.

  3. Async/await consistency: Ensure all async functions are properly handled with try/catch blocks or returned promises are caught at the caller level.

  4. Code duplication: There are several similar functions for adding different types of items (e.g., addMiscItems, addConsumables, addRecipes). Consider creating a generic function to reduce duplication.

  5. Comments and documentation: Add JSDoc comments to functions, especially for complex operations or those with multiple parameters.

Would you like me to provide specific examples for any of these improvements?

src/controllers/api/fusionTreasuresController.ts (1)

39-39: Remove commented-out debugging code.

The commented-out console.log statement can be removed to keep the codebase clean and maintainable.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between de6c1da55d and 5f7e1bc764.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • package.json (1 hunks)
  • src/controllers/api/fusionTreasuresController.ts (1 hunks)
  • src/controllers/custom/getItemListsController.ts (1 hunks)
  • src/routes/api.ts (2 hunks)
  • src/services/inventoryService.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • package.json
🧰 Additional context used
🔇 Additional comments (4)
src/controllers/custom/getItemListsController.ts (1)

39-39: Verify client compatibility with the new uniqueName structure for resources.

The change from "MiscItems:" + uniqueName to item.productCategory + ":" + uniqueName introduces a more specific categorization for resource items. While this improves item organization, it may impact client-side code that expects the previous "MiscItems:" prefix.

Consider the following:

  1. Ensure that all client implementations are updated to handle the new uniqueName structure.
  2. Add a comment explaining the rationale behind this change for future reference.
  3. If backward compatibility is a concern, consider implementing a version check or providing a migration path for clients.

To verify the impact of this change, run the following script:

This script will help identify any code that might be affected by the change in the uniqueName structure.

src/routes/api.ts (3)

14-14: LGTM: Import statement for fusionTreasuresController

The import statement for fusionTreasuresController is correctly added and follows the existing pattern in the file. The naming convention is consistent with other controller imports.


14-14: Changes align well with PR objectives

The addition of the fusionTreasuresController import and the new route for "/fusionTreasures.php" are well-integrated into the existing codebase. These changes directly address the PR objective of implementing socketing of Ayatan sculptures and appear to resolve the issue described in #541 regarding the installation of Ayatan Stars in Ayatan Treasures.

The modifications follow the established patterns in the file and should not negatively impact other parts of the application. Overall, these changes seem appropriate and focused on solving the specific problem at hand.

Also applies to: 113-113


113-113: LGTM: New route for fusionTreasures.php

The new POST route for "/fusionTreasures.php" is correctly added and handled by the fusionTreasuresController. This addition aligns with the PR objectives to implement socketing of Ayatan sculptures. The route naming and placement are consistent with the existing pattern in the file.

To ensure consistency, let's verify that no duplicate routes exist:

Verification successful

LGTM: New route for fusionTreasures.php

The new POST route for "/fusionTreasures.php" is correctly added and handled by the fusionTreasuresController. This addition aligns with the PR objectives to implement socketing of Ayatan sculptures. The route naming and placement are consistent with the existing pattern in the file.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for duplicate routes in api.ts

# Test: Search for duplicate routes
duplicates=$(grep -n 'apiRouter\.(get|post)' src/routes/api.ts | sort | uniq -d -f2)

if [ -n "$duplicates" ]; then
    echo "Duplicate routes found:"
    echo "$duplicates"
else
    echo "No duplicate routes found."
fi

Length of output: 168

**Actionable comments posted: 2** <details> <summary>🧹 Outside diff range and nitpick comments (3)</summary><blockquote> <details> <summary>src/services/inventoryService.ts (2)</summary><blockquote> Line range hint `657-670`: **Improved item matching logic for FusionTreasures** The change in the `addFusionTreasures` function enhances the accuracy of item matching. By including both `ItemType` and `Sockets` in the comparison, it ensures that items with the same type but different socket configurations are treated as distinct. This prevents incorrect merging of items and maintains the integrity of the inventory. Consider adding a type guard or default value for the `Sockets` property to handle potential undefined values more explicitly: ```diff -const itemIndex = FusionTreasures.findIndex(i => i.ItemType == ItemType && (i.Sockets || 0) == (Sockets || 0)); +const itemIndex = FusionTreasures.findIndex(i => i.ItemType === ItemType && (i.Sockets ?? 0) === (Sockets ?? 0)); ``` This change uses the nullish coalescing operator (`??`) for clearer intent and strict equality (`===`) for consistency with TypeScript best practices. --- Line range hint `1-670`: **General code quality improvements** While reviewing the file, I noticed some areas where we could improve overall code quality and consistency: 1. Error handling: Consider implementing a more consistent error handling strategy across functions. For example, the `upgradeMod` function uses try-catch, while others don't. 2. Type safety: Enhance type safety by using more specific types instead of `any` or `undefined`. For instance, in the `updateGeneric` function, consider creating a specific type for the `data` parameter. 3. Async/await consistency: Ensure all async functions are properly handled with try/catch blocks or returned promises are caught at the caller level. 4. Code duplication: There are several similar functions for adding different types of items (e.g., `addMiscItems`, `addConsumables`, `addRecipes`). Consider creating a generic function to reduce duplication. 5. Comments and documentation: Add JSDoc comments to functions, especially for complex operations or those with multiple parameters. Would you like me to provide specific examples for any of these improvements? </blockquote></details> <details> <summary>src/controllers/api/fusionTreasuresController.ts (1)</summary><blockquote> `39-39`: **Remove commented-out debugging code.** The commented-out `console.log` statement can be removed to keep the codebase clean and maintainable. </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: .coderabbit.yaml** **Review profile: CHILL** <details> <summary>📥 Commits</summary> Files that changed from the base of the PR and between de6c1da55d9679014473fc95c5a020f5df1c7315 and 5f7e1bc764d13733f9732dcb8e2f594710266269. </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 (5)</summary> * package.json (1 hunks) * src/controllers/api/fusionTreasuresController.ts (1 hunks) * src/controllers/custom/getItemListsController.ts (1 hunks) * src/routes/api.ts (2 hunks) * src/services/inventoryService.ts (1 hunks) </details> <details> <summary>✅ Files skipped from review due to trivial changes (1)</summary> * package.json </details> <details> <summary>🧰 Additional context used</summary> </details> <details> <summary>🔇 Additional comments (4)</summary><blockquote> <details> <summary>src/controllers/custom/getItemListsController.ts (1)</summary><blockquote> `39-39`: **Verify client compatibility with the new `uniqueName` structure for resources.** The change from `"MiscItems:" + uniqueName` to `item.productCategory + ":" + uniqueName` introduces a more specific categorization for resource items. While this improves item organization, it may impact client-side code that expects the previous "MiscItems:" prefix. Consider the following: 1. Ensure that all client implementations are updated to handle the new `uniqueName` structure. 2. Add a comment explaining the rationale behind this change for future reference. 3. If backward compatibility is a concern, consider implementing a version check or providing a migration path for clients. To verify the impact of this change, run the following script: This script will help identify any code that might be affected by the change in the `uniqueName` structure. </blockquote></details> <details> <summary>src/routes/api.ts (3)</summary><blockquote> `14-14`: **LGTM: Import statement for fusionTreasuresController** The import statement for `fusionTreasuresController` is correctly added and follows the existing pattern in the file. The naming convention is consistent with other controller imports. --- `14-14`: **Changes align well with PR objectives** The addition of the `fusionTreasuresController` import and the new route for "/fusionTreasures.php" are well-integrated into the existing codebase. These changes directly address the PR objective of implementing socketing of Ayatan sculptures and appear to resolve the issue described in #541 regarding the installation of Ayatan Stars in Ayatan Treasures. The modifications follow the established patterns in the file and should not negatively impact other parts of the application. Overall, these changes seem appropriate and focused on solving the specific problem at hand. Also applies to: 113-113 --- `113-113`: **LGTM: New route for fusionTreasures.php** The new POST route for "/fusionTreasures.php" is correctly added and handled by the `fusionTreasuresController`. This addition aligns with the PR objectives to implement socketing of Ayatan sculptures. The route naming and placement are consistent with the existing pattern in the file. To ensure consistency, let's verify that no duplicate routes exist: <details> <summary>✅ Verification successful</summary> <!-- [monologue] [task finalize_verification_1/1] [observations] - The shell script to check for duplicate routes was executed. - The output confirmed that there are no duplicate routes in `api.ts`. [analysis] - With no duplicate routes found, the new route addition does not introduce any conflicts. - The initial approval can be confidently finalized. [actions] - Generate the final approval response. - Update the review comment status to . --> **LGTM: New route for fusionTreasures.php** The new POST route for "/fusionTreasures.php" is correctly added and handled by the `fusionTreasuresController`. This addition aligns with the PR objectives to implement socketing of Ayatan sculptures. The route naming and placement are consistent with the existing pattern in the file. </details> <details> <summary>🏁 Scripts executed</summary> The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Description: Check for duplicate routes in api.ts # Test: Search for duplicate routes duplicates=$(grep -n 'apiRouter\.(get|post)' src/routes/api.ts | sort | uniq -d -f2) if [ -n "$duplicates" ]; then echo "Duplicate routes found:" echo "$duplicates" else echo "No duplicate routes found." fi ``` Length of output: 168 </details> </blockquote></details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
@ -0,0 +22,4 @@
export const fusionTreasuresController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
const request = JSON.parse(req.body.toString() as string) as IFusionTreasureRequest;
coderabbitai[bot] (Migrated from github.com) commented 2024-10-11 16:42:49 -07:00
Author
Owner

🛠️ Refactor suggestion

⚠️ Potential issue

Consider using req.body directly and add input validation.

If body-parsing middleware is used in Express, req.body is already a parsed object. Parsing it again with JSON.parse may be unnecessary and could lead to errors.

Recommended change:

-const request = JSON.parse(req.body.toString() as string) as IFusionTreasureRequest;
+const request = req.body as IFusionTreasureRequest;

Additionally, it's important to validate the request data to ensure that oldTreasureName and newTreasureName are present and are valid strings. Consider adding validation and appropriate error handling to prevent potential runtime exceptions.

Committable suggestion was skipped due to low confidence.

_:hammer_and_wrench: Refactor suggestion_ _:warning: Potential issue_ **Consider using `req.body` directly and add input validation.** If body-parsing middleware is used in Express, `req.body` is already a parsed object. Parsing it again with `JSON.parse` may be unnecessary and could lead to errors. Recommended change: ```diff -const request = JSON.parse(req.body.toString() as string) as IFusionTreasureRequest; +const request = req.body as IFusionTreasureRequest; ``` Additionally, it's important to validate the request data to ensure that `oldTreasureName` and `newTreasureName` are present and are valid strings. Consider adding validation and appropriate error handling to prevent potential runtime exceptions. > Committable suggestion was skipped due to low confidence. <!-- This is an auto-generated reply by CodeRabbit -->
@ -0,0 +35,4 @@
const miscItemChanges: IMiscItem[] = [];
const filledSockets = newTreasure.Sockets & ~oldTreasure.Sockets;
for (let i = 0; filledSockets >> i; ++i) {
if ((filledSockets >> i) & 1) {
coderabbitai[bot] (Migrated from github.com) commented 2024-10-11 16:42:49 -07:00
Author
Owner

⚠️ Potential issue

Fix the loop condition to prevent incorrect termination.

The loop condition for (let i = 0; filledSockets >> i; ++i) may not function as intended. If filledSockets becomes zero after right-shifting, the loop could terminate prematurely or lead to incorrect behavior.

Consider modifying the loop condition to ensure it iterates over all bits:

-for (let i = 0; filledSockets >> i; ++i) {
+for (let i = 0; (filledSockets >> i) > 0; ++i) {

Alternatively, if the number of sockets is known (e.g., 32 bits), you could use:

for (let i = 0; i < 32; ++i) {
    if ((filledSockets >> i) & 1) {
        // ...
    }
}

This ensures the loop checks each bit position consistently.

_:warning: Potential issue_ **Fix the loop condition to prevent incorrect termination.** The loop condition `for (let i = 0; filledSockets >> i; ++i)` may not function as intended. If `filledSockets` becomes zero after right-shifting, the loop could terminate prematurely or lead to incorrect behavior. Consider modifying the loop condition to ensure it iterates over all bits: ```diff -for (let i = 0; filledSockets >> i; ++i) { +for (let i = 0; (filledSockets >> i) > 0; ++i) { ``` Alternatively, if the number of sockets is known (e.g., 32 bits), you could use: ```javascript for (let i = 0; i < 32; ++i) { if ((filledSockets >> i) & 1) { // ... } } ``` This ensures the loop checks each bit position consistently. <!-- This is an auto-generated reply by CodeRabbit -->
Sainan reviewed 2024-10-11 16:45:18 -07:00
@ -0,0 +35,4 @@
const miscItemChanges: IMiscItem[] = [];
const filledSockets = newTreasure.Sockets & ~oldTreasure.Sockets;
for (let i = 0; filledSockets >> i; ++i) {
if ((filledSockets >> i) & 1) {
Author
Owner

Kill yourself

Kill yourself
Sainan reviewed 2024-10-11 16:45:24 -07:00
@ -0,0 +22,4 @@
export const fusionTreasuresController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
const request = JSON.parse(req.body.toString() as string) as IFusionTreasureRequest;
Author
Owner

Kill yourself

Kill yourself
coderabbitai[bot] (Migrated from github.com) reviewed 2024-10-11 16:45:53 -07:00
@ -0,0 +35,4 @@
const miscItemChanges: IMiscItem[] = [];
const filledSockets = newTreasure.Sockets & ~oldTreasure.Sockets;
for (let i = 0; filledSockets >> i; ++i) {
if ((filledSockets >> i) & 1) {
coderabbitai[bot] (Migrated from github.com) commented 2024-10-11 16:45:53 -07:00
Author
Owner

@Sainan, understood. Let me know if there's anything else I can assist you with.

(_/)
( •_•)
🌸

@Sainan, understood. Let me know if there's anything else I can assist you with. (\_/) ( •_•) 🌸 <!-- This is an auto-generated reply by CodeRabbit -->
coderabbitai[bot] (Migrated from github.com) reviewed 2024-10-11 16:47:26 -07:00
@ -0,0 +22,4 @@
export const fusionTreasuresController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
const request = JSON.parse(req.body.toString() as string) as IFusionTreasureRequest;
coderabbitai[bot] (Migrated from github.com) commented 2024-10-11 16:47:25 -07:00
Author
Owner

@Sainan, I'm sorry to hear that you're feeling this way. If there's anything I can assist you with, please let me know.

(_/)
(•_•)

@Sainan, I'm sorry to hear that you're feeling this way. If there's anything I can assist you with, please let me know. (\_/) (•_•) <!-- This is an auto-generated reply by CodeRabbit -->
Sign in to join this conversation.
No description provided.