fix: adjust mission update controller to add xp when aborting mission. #864

Merged
OrdisPrime merged 3 commits from faithful-abort-mission into main 2025-01-24 07:17:59 -08:00
OrdisPrime commented 2025-01-24 07:05:04 -08:00 (Migrated from github.com)

also creates ts-utils in utils

also creates ts-utils in utils
coderabbitai[bot] commented 2025-01-24 07:05:11 -08:00 (Migrated from github.com)

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request introduces changes across three files: missionInventoryUpdateController.ts, missionInventoryUpdateService.ts, and ts-utils.ts. The modifications primarily focus on error handling, response structure, and utility function implementation.

In the controller, the error handling and response mechanism for mission inventory updates have been refined, ensuring that InventoryJson is included in the response regardless of mission status and shifting to an exception-based error handling approach for missionRewardsResults. The service file now imports a utility function getEntriesUnsafe from the new utility module, replacing a local implementation and adjusting error logging severity from error to warning when reward information is missing.

The ts-utils.ts file is expanded with a new type alias Entries and a corresponding utility function getEntriesUnsafe, which provides a type-safe method for retrieving object entries. These changes enhance type handling and error management in the mission inventory update process.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 989f8eda4b and 6c9515a34d.

📒 Files selected for processing (1)
  • src/controllers/api/missionInventoryUpdateController.ts (2 hunks)
Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.
<!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- This is an auto-generated comment: failure by coderabbit.ai --> > [!CAUTION] > ## Review failed > > The pull request is closed. <!-- end of auto-generated comment: failure by coderabbit.ai --> <!-- internal state start --> <!-- FAHghAtBAEAqAWBLAztF0CGA7TBXALgPYQDmAplmQE4b5kAm0AxoQLasX4Bc0ADldEIAjAFZkm+RADcyqIQE9mhetQxChifADoMiaFAB8wY+CjGAxOegAFAErQAyrnYYq84wjJ9cAGx/QqMgBHXFl8aEl8HwZoACIAM0QADx4MehFcZHDWFGREQhxcXnpaLxYsfCpCP2pY6AB3DFRkXCEc/DpG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g3wSwGAfovZV9gIwCoBoAABOHYDA+IHYBgDAA4IQAAVgAHYLg9giCiZ4gSCABmLAsgPYGg/VegIggARh2BIIACZ6ADgAAGGgxgVAh/JiSA6A2AqFIheoRA8CISAwIAA== --> <!-- internal state end --> <!-- walkthrough_start --> ## Walkthrough The pull request introduces changes across three files: `missionInventoryUpdateController.ts`, `missionInventoryUpdateService.ts`, and `ts-utils.ts`. The modifications primarily focus on error handling, response structure, and utility function implementation. In the controller, the error handling and response mechanism for mission inventory updates have been refined, ensuring that `InventoryJson` is included in the response regardless of mission status and shifting to an exception-based error handling approach for `missionRewardsResults`. The service file now imports a utility function `getEntriesUnsafe` from the new utility module, replacing a local implementation and adjusting error logging severity from error to warning when reward information is missing. The `ts-utils.ts` file is expanded with a new type alias `Entries` and a corresponding utility function `getEntriesUnsafe`, which provides a type-safe method for retrieving object entries. These changes enhance type handling and error management in the mission inventory update process. <!-- walkthrough_end --> --- <details> <summary>📜 Recent 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 989f8eda4b57ca65eef7398e63beed51872d403d and 6c9515a34d90c6732ed8812a071a1e0576e6e2aa. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `src/controllers/api/missionInventoryUpdateController.ts` (2 hunks) </details> </details> <!-- finishing_touch_checkbox_start --> <details> <summary>✨ Finishing Touches</summary> - [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings (Beta) </details> <!-- finishing_touch_checkbox_end --> <!-- tips_start --> --- Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <details> <summary>🪧 Tips</summary> ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit <commit_id>, please review it.` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (Invoked using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR. ([Beta](https://docs.coderabbit.ai/early-access#beta)) - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### Documentation and Community - Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements. </details> <!-- tips_end -->
coderabbitai[bot] (Migrated from github.com) reviewed 2025-01-24 07:08:33 -08:00
coderabbitai[bot] (Migrated from github.com) left a comment

Actionable comments posted: 0

🧹 Nitpick comments (4)
src/utils/ts-utils.ts (1)

1-1: Consider clarifying the significance of "Unsafe" in the type name.
The name suggests a non-typesafe operation, yet the underlying usage of Object.entries is generally safe for own properties. Clarifying or renaming might avoid confusion.

src/services/missionInventoryUpdateService.ts (1)

183-183: Evaluate logging level for missing reward info.
Downgrading from error to warning is logical if missing reward information is not fatal. If it can indicate unexpected behavior, consider adding more context (e.g., user account ID or mission details) to help with troubleshooting.

src/controllers/api/missionInventoryUpdateController.ts (2)

69-72: Throwing an error halts the request.
Consider returning a structured error response or logging this scenario for debugging. If this is truly unrecoverable, throwing is appropriate.


Line range hint 11-11: Remove or utilize the unused 'logger' import to fix the pipeline warning.
If additional logging is forthcoming, keep it; otherwise, remove this import.

- import { logger } from "@/src/utils/logger";
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3cd66391b6 and 989f8eda4b.

📒 Files selected for processing (3)
  • src/controllers/api/missionInventoryUpdateController.ts (1 hunks)
  • src/services/missionInventoryUpdateService.ts (2 hunks)
  • src/utils/ts-utils.ts (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Build
src/controllers/api/missionInventoryUpdateController.ts

[error] 11-11: 'logger' is defined but never used

🔇 Additional comments (3)
src/utils/ts-utils.ts (1)

3-5: Implementation appears straightforward and consistently typed.
Casting the result of Object.entries to Entries<T> is common practice. Ensure that any calls passing less conventional object shapes (e.g., arrays or classes with symbol keys) are thoroughly tested.

src/services/missionInventoryUpdateService.ts (1)

24-24: New import usage is valid.
This externalizes the previous in-file definition nicely. No issues found.

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

62-65: Conditional return for unsuccessful missions seems consistent.
Returning partial data (inventory but no rewards) is a clear approach for non-success mission status.

**Actionable comments posted: 0** <details> <summary>🧹 Nitpick comments (4)</summary><blockquote> <details> <summary>src/utils/ts-utils.ts (1)</summary><blockquote> `1-1`: **Consider clarifying the significance of "Unsafe" in the type name.** The name suggests a non-typesafe operation, yet the underlying usage of `Object.entries` is generally safe for own properties. Clarifying or renaming might avoid confusion. </blockquote></details> <details> <summary>src/services/missionInventoryUpdateService.ts (1)</summary><blockquote> `183-183`: **Evaluate logging level for missing reward info.** Downgrading from error to warning is logical if missing reward information is not fatal. If it can indicate unexpected behavior, consider adding more context (e.g., user account ID or mission details) to help with troubleshooting. </blockquote></details> <details> <summary>src/controllers/api/missionInventoryUpdateController.ts (2)</summary><blockquote> `69-72`: **Throwing an error halts the request.** Consider returning a structured error response or logging this scenario for debugging. If this is truly unrecoverable, throwing is appropriate. --- Line range hint `11-11`: **Remove or utilize the unused 'logger' import to fix the pipeline warning.** If additional logging is forthcoming, keep it; otherwise, remove this import. ```diff - import { logger } from "@/src/utils/logger"; ``` </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 3cd66391b6e1f7aba9fd541ff1caf032b8fe7e28 and 989f8eda4b57ca65eef7398e63beed51872d403d. </details> <details> <summary>📒 Files selected for processing (3)</summary> * `src/controllers/api/missionInventoryUpdateController.ts` (1 hunks) * `src/services/missionInventoryUpdateService.ts` (2 hunks) * `src/utils/ts-utils.ts` (1 hunks) </details> <details> <summary>🧰 Additional context used</summary> <details> <summary>🪛 GitHub Actions: Build</summary> <details> <summary>src/controllers/api/missionInventoryUpdateController.ts</summary> [error] 11-11: 'logger' is defined but never used </details> </details> </details> <details> <summary>🔇 Additional comments (3)</summary><blockquote> <details> <summary>src/utils/ts-utils.ts (1)</summary> `3-5`: **Implementation appears straightforward and consistently typed.** Casting the result of `Object.entries` to `Entries<T>` is common practice. Ensure that any calls passing less conventional object shapes (e.g., arrays or classes with symbol keys) are thoroughly tested. </details> <details> <summary>src/services/missionInventoryUpdateService.ts (1)</summary> `24-24`: **New import usage is valid.** This externalizes the previous in-file definition nicely. No issues found. </details> <details> <summary>src/controllers/api/missionInventoryUpdateController.ts (1)</summary> `62-65`: **Conditional return for unsuccessful missions seems consistent.** Returning partial data (inventory but no rewards) is a clear approach for non-success mission status. </details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Sign in to join this conversation.
No description provided.