feat: basic implementation of endlessXp.php we can play The Circuit #596

Merged
Sainan merged 1 commits from endlessxp into main 2024-12-22 11:36:01 -08:00
Owner

Closes #433

Closes #433
coderabbitai[bot] commented 2024-12-21 19:10:49 -08:00 (Migrated from github.com)
Author
Owner

Walkthrough

This pull request introduces a new feature for managing Endless XP (Experience Points) in the application. The implementation spans multiple files to create a comprehensive system for tracking and updating Endless XP progress.

The changes include:

  • Creating a new controller (endlessXpController.ts) to handle Endless XP-related API requests
  • Extending the inventory model (inventoryModel.ts) to include an EndlessXP field with a specific schema
  • Adding a new route in the API router (api.ts) to handle POST requests for Endless XP
  • Updating the inventory types (inventoryTypes.ts) to support the new Endless XP functionality

The new system allows for tracking Endless XP progress with two categories (NORMAL and HARD) and supports storing and updating choices associated with each category. The implementation enables clients to interact with the Endless XP feature through a dedicated API endpoint.

Assessment against linked issues

Objective Addressed Explanation
Resolve 404 error for /api/endlessXp.php
Enable Circuit reward selection Endpoint is now implemented, but full functionality requires client-side verification
  • #582: Shares similarities in inventory data management logic
  • #586: Complements the interface updates for inventory-related data structures

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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 This pull request introduces a new feature for managing Endless XP (Experience Points) in the application. The implementation spans multiple files to create a comprehensive system for tracking and updating Endless XP progress. The changes include: - Creating a new controller (`endlessXpController.ts`) to handle Endless XP-related API requests - Extending the inventory model (`inventoryModel.ts`) to include an `EndlessXP` field with a specific schema - Adding a new route in the API router (`api.ts`) to handle POST requests for Endless XP - Updating the inventory types (`inventoryTypes.ts`) to support the new Endless XP functionality The new system allows for tracking Endless XP progress with two categories (NORMAL and HARD) and supports storing and updating choices associated with each category. The implementation enables clients to interact with the Endless XP feature through a dedicated API endpoint. ## Assessment against linked issues | Objective | Addressed | Explanation | |----------|-----------|-------------| | Resolve 404 error for `/api/endlessXp.php` | ✅ | | | Enable Circuit reward selection | ❓ | Endpoint is now implemented, but full functionality requires client-side verification | ## Possibly related PRs - **#582**: Shares similarities in inventory data management logic - **#586**: Complements the interface updates for inventory-related data structures <!-- walkthrough_end --> <!-- announcements_start --> > [!TIP] > CodeRabbit's [docstrings feature](https://docs.coderabbit.ai/finishing-touches/docstrings) is now available as part of our [Early Access Program](https://docs.coderabbit.ai/early-access)! Simply use the command `@coderabbitai generate docstrings` to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on [Discord](https://discord.com/channels/1134356397673414807/1317286905557287022). <!-- announcements_end --> <!-- internal state start --> <!-- FAHghAtBAEAqAWBLAztF0CGA7TBXALgPYQDmAplmQE4b5kAm0AxoQLasX4Bc0ADldEIAjAFZkm+RADcyqIQE9mhetQxChifADoMiaFAB8wY+CjGAxOegAFAErQAyrnYYq84wjJ9cAGx/QqMgBHXFl8aEl8HwZoACIAMzJaHiEMZEQmNFZeaI4sfFpEQhxCeOgKemjkZAANXi1eeF5oAHcvJmw+HwxFT2gAYUQqJlxNWNa06GRcIVZNOkYFCPgvXGRqR10sTuxGdCxnIWoYgFYATgA2LTgVvipEVldFXlwqXkJ1wTL8JFQ7NFQRCyOTIeXCGGgqXSmRkVHSxS+yy8AAMKlVavVGrxkdB4ohogAaVpIJjwAFofIVGJA+IYJj4zS0LwkDAcHI9XGEASxPqDYajbTjACC9HomiK2z88iJP3QLz8AWCoWQ4NFgWqskwWEYTB8H01KGmXgOrCOAgALABmS3XABiXNxrx+GxUBXxyBlt3+HRwR0wTCYsnWjFoSLuhCkiBUjAAqrYADI8ADa8Hw+F4yC4AHosyRNPAZloWKws8heHSKIgsCI0tRYVmHOXAwA5Ks1hx16hZ+U+LPnC4AXQAFKn05mc3mfoXi6Wm5Xq7WqPXGxXWwuO0uuz2+5cAJRaYyGEyQGAVREYAjEciUGgLJTsTg8fiCUTiSQyOSKFg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AABGcGh6i61IS0PCAic6uCLanavalqZqUDbks8QwIAA=== --> <!-- 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 06:45:15 -08:00
coderabbitai[bot] (Migrated from github.com) left a comment
Author
Owner

Actionable comments posted: 2

🔭 Outside diff range comments (1)
src/models/inventoryModels/inventoryModel.ts (1)

Line range hint 1022-1052: Add EndlessXP to InventoryDocumentProps type definition.

The EndlessXP field is missing from the InventoryDocumentProps interface. This could lead to type-safety issues when accessing the field in TypeScript code.

Add the following line to the InventoryDocumentProps interface:

type InventoryDocumentProps = {
    Suits: Types.DocumentArray<IEquipmentDatabase>;
    LongGuns: Types.DocumentArray<IEquipmentDatabase>;
+   EndlessXP: Types.DocumentArray<IEndlessXpProgress>;
    // ... other fields
};
🧹 Nitpick comments (2)
src/controllers/api/endlessXpController.ts (1)

56-60: Add JSDoc comments and strengthen type safety.

The interface lacks documentation and type constraints.

Add documentation and improve type safety:

+/**
+ * Request payload for Endless XP updates
+ * @property {string} Mode - Operation mode, currently only supports "r"
+ * @property {TEndlessXpCategory} Category - Difficulty category
+ * @property {string[]} Choices - Selected choices for the endless mode
+ */
 interface IEndlessXpRequest {
-    Mode: string; // "r"
+    Mode: "r";
     Category: TEndlessXpCategory;
     Choices: string[];
 }
src/types/inventoryTypes/inventoryTypes.ts (1)

937-942: Add JSDoc comments for new types.

The new types would benefit from documentation explaining their purpose and constraints.

Add documentation:

+/**
+ * Categories for Endless XP progression
+ * @enum {string}
+ */
 export type TEndlessXpCategory = "EXC_NORMAL" | "EXC_HARD";

+/**
+ * Tracks progress in Endless XP mode
+ * @interface IEndlessXpProgress
+ * @property {TEndlessXpCategory} Category - Difficulty level of the endless mode
+ * @property {string[]} Choices - Selected choices affecting the gameplay
+ */
 export interface IEndlessXpProgress {
     Category: TEndlessXpCategory;
     Choices: string[];
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 987b05a334 and 7458acb80e.

📒 Files selected for processing (4)
  • src/controllers/api/endlessXpController.ts (1 hunks)
  • src/models/inventoryModels/inventoryModel.ts (3 hunks)
  • src/routes/api.ts (2 hunks)
  • src/types/inventoryTypes/inventoryTypes.ts (2 hunks)
🔇 Additional comments (4)
src/routes/api.ts (1)

11-11: LGTM!

The route addition follows the established pattern and is correctly implemented.

Also applies to: 112-112

src/types/inventoryTypes/inventoryTypes.ts (1)

304-304: LGTM!

The EndlessXP field is correctly added to the IInventoryResponse interface.

src/models/inventoryModels/inventoryModel.ts (2)

585-591: LGTM! Schema definition follows established patterns.

The endlessXpProgressSchema is well-structured with appropriate field types and correctly excludes the _id field.


950-952: LGTM! Field integration follows schema patterns.

The EndlessXP field is correctly integrated into the inventory schema with proper typing and default value handling.

**Actionable comments posted: 2** <details> <summary>🔭 Outside diff range comments (1)</summary><blockquote> <details> <summary>src/models/inventoryModels/inventoryModel.ts (1)</summary><blockquote> Line range hint `1022-1052`: **Add EndlessXP to InventoryDocumentProps type definition.** The `EndlessXP` field is missing from the `InventoryDocumentProps` interface. This could lead to type-safety issues when accessing the field in TypeScript code. Add the following line to the `InventoryDocumentProps` interface: ```diff type InventoryDocumentProps = { Suits: Types.DocumentArray<IEquipmentDatabase>; LongGuns: Types.DocumentArray<IEquipmentDatabase>; + EndlessXP: Types.DocumentArray<IEndlessXpProgress>; // ... other fields }; ``` </blockquote></details> </blockquote></details> <details> <summary>🧹 Nitpick comments (2)</summary><blockquote> <details> <summary>src/controllers/api/endlessXpController.ts (1)</summary><blockquote> `56-60`: **Add JSDoc comments and strengthen type safety.** The interface lacks documentation and type constraints. Add documentation and improve type safety: ```diff +/** + * Request payload for Endless XP updates + * @property {string} Mode - Operation mode, currently only supports "r" + * @property {TEndlessXpCategory} Category - Difficulty category + * @property {string[]} Choices - Selected choices for the endless mode + */ interface IEndlessXpRequest { - Mode: string; // "r" + Mode: "r"; Category: TEndlessXpCategory; Choices: string[]; } ``` </blockquote></details> <details> <summary>src/types/inventoryTypes/inventoryTypes.ts (1)</summary><blockquote> `937-942`: **Add JSDoc comments for new types.** The new types would benefit from documentation explaining their purpose and constraints. Add documentation: ```diff +/** + * Categories for Endless XP progression + * @enum {string} + */ export type TEndlessXpCategory = "EXC_NORMAL" | "EXC_HARD"; +/** + * Tracks progress in Endless XP mode + * @interface IEndlessXpProgress + * @property {TEndlessXpCategory} Category - Difficulty level of the endless mode + * @property {string[]} Choices - Selected choices affecting the gameplay + */ export interface IEndlessXpProgress { Category: TEndlessXpCategory; Choices: string[]; } ``` </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 987b05a3346a7486ed75f8ae36826049eac093e1 and 7458acb80ec64ff2b62ddbe5c3a0aaab11b87ba3. </details> <details> <summary>📒 Files selected for processing (4)</summary> * `src/controllers/api/endlessXpController.ts` (1 hunks) * `src/models/inventoryModels/inventoryModel.ts` (3 hunks) * `src/routes/api.ts` (2 hunks) * `src/types/inventoryTypes/inventoryTypes.ts` (2 hunks) </details> <details> <summary>🔇 Additional comments (4)</summary> <details> <summary>src/routes/api.ts (1)</summary> `11-11`: **LGTM!** The route addition follows the established pattern and is correctly implemented. Also applies to: 112-112 </details> <details> <summary>src/types/inventoryTypes/inventoryTypes.ts (1)</summary> `304-304`: **LGTM!** The EndlessXP field is correctly added to the IInventoryResponse interface. </details> <details> <summary>src/models/inventoryModels/inventoryModel.ts (2)</summary> `585-591`: **LGTM! Schema definition follows established patterns.** The `endlessXpProgressSchema` is well-structured with appropriate field types and correctly excludes the `_id` field. --- `950-952`: **LGTM! Field integration follows schema patterns.** The `EndlessXP` field is correctly integrated into the inventory schema with proper typing and default value handling. </details> </details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
@ -0,0 +8,4 @@
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
const payload = getJSONfromString(String(req.body)) as IEndlessXpRequest;
coderabbitai[bot] (Migrated from github.com) commented 2024-12-22 06:45:14 -08:00
Author
Owner

⚠️ Potential issue

Add error handling and input validation.

The controller lacks error handling for potential failures and input validation.

Add try-catch and validation:

 export const endlessXpController: RequestHandler = async (req, res) => {
+    try {
+        if (!req.body) {
+            return res.status(400).json({ error: 'Missing request body' });
+        }
+
         const accountId = await getAccountIdForRequest(req);
+        if (!accountId) {
+            return res.status(401).json({ error: 'Unauthorized' });
+        }
+
         const inventory = await getInventory(accountId);
         const payload = getJSONfromString(String(req.body)) as IEndlessXpRequest;
+
+        if (!payload.Category || !Array.isArray(payload.Choices)) {
+            return res.status(400).json({ error: 'Invalid payload format' });
+        }
+    } catch (error) {
+        console.error('Error in endlessXpController:', error);
+        return res.status(500).json({ error: 'Internal server error' });
+    }

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Add error handling and input validation.** The controller lacks error handling for potential failures and input validation. Add try-catch and validation: ```diff export const endlessXpController: RequestHandler = async (req, res) => { + try { + if (!req.body) { + return res.status(400).json({ error: 'Missing request body' }); + } + const accountId = await getAccountIdForRequest(req); + if (!accountId) { + return res.status(401).json({ error: 'Unauthorized' }); + } + const inventory = await getInventory(accountId); const payload = getJSONfromString(String(req.body)) as IEndlessXpRequest; + + if (!payload.Category || !Array.isArray(payload.Choices)) { + return res.status(400).json({ error: 'Invalid payload format' }); + } + } catch (error) { + console.error('Error in endlessXpController:', error); + return res.status(500).json({ error: 'Internal server error' }); + } ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
@ -0,0 +50,4 @@
// ...
]
}
});
coderabbitai[bot] (Migrated from github.com) commented 2024-12-22 06:45:14 -08:00
Author
Owner

⚠️ Potential issue

Add validation and remove hardcoded values.

The response contains hardcoded values which should be dynamic:

  • Earn/Claim values are set to 0
  • BonusAvailable/Expiry dates use hardcoded "9999999999999"
  • PendingRewards contains a hardcoded reward

Consider:

  1. Calculate Earn/Claim values based on user progress
  2. Use actual dates for BonusAvailable/Expiry
  3. Load PendingRewards from a configuration source
     res.json({
         NewProgress: {
             Category: payload.Category,
-            Earn: 0,
-            Claim: 0,
+            Earn: calculateEarnValue(inventory, payload.Category),
+            Claim: calculateClaimValue(inventory, payload.Category),
             BonusAvailable: {
                 $date: {
-                    $numberLong: "9999999999999"
+                    $numberLong: calculateBonusDate().toString()
                 }
             },
             Expiry: {
                 $date: {
-                    $numberLong: "9999999999999"
+                    $numberLong: calculateExpiryDate().toString()
                 }
             },
             Choices: payload.Choices,
-            PendingRewards: [
-                {
-                    RequiredTotalXp: 190,
-                    Rewards: [
-                        {
-                            StoreItem: "/Lotus/StoreItems/Upgrades/Mods/Aura/PlayerHealthAuraMod",
-                            ItemCount: 1
-                        }
-                    ]
-                }
-            ]
+            PendingRewards: await loadPendingRewards(payload.Category)
         }
     });

Committable suggestion skipped: line range outside the PR's diff.

_:warning: Potential issue_ **Add validation and remove hardcoded values.** The response contains hardcoded values which should be dynamic: - Earn/Claim values are set to 0 - BonusAvailable/Expiry dates use hardcoded "9999999999999" - PendingRewards contains a hardcoded reward Consider: 1. Calculate Earn/Claim values based on user progress 2. Use actual dates for BonusAvailable/Expiry 3. Load PendingRewards from a configuration source ```diff res.json({ NewProgress: { Category: payload.Category, - Earn: 0, - Claim: 0, + Earn: calculateEarnValue(inventory, payload.Category), + Claim: calculateClaimValue(inventory, payload.Category), BonusAvailable: { $date: { - $numberLong: "9999999999999" + $numberLong: calculateBonusDate().toString() } }, Expiry: { $date: { - $numberLong: "9999999999999" + $numberLong: calculateExpiryDate().toString() } }, Choices: payload.Choices, - PendingRewards: [ - { - RequiredTotalXp: 190, - Rewards: [ - { - StoreItem: "/Lotus/StoreItems/Upgrades/Mods/Aura/PlayerHealthAuraMod", - ItemCount: 1 - } - ] - } - ] + PendingRewards: await loadPendingRewards(payload.Category) } }); ``` > Committable suggestion skipped: line range outside the PR's diff. <!-- This is an auto-generated comment by CodeRabbit -->
Sign in to join this conversation.
No description provided.