feat: Kinematic Instant Messaging #801

Merged
Sainan merged 2 commits from pom2 into main 2025-01-18 16:57:25 -08:00
Owner

Closes #577

Closes #577
coderabbitai[bot] commented 2025-01-17 20:58:18 -08:00 (Migrated from github.com)
Author
Owner

Walkthrough

The pull request introduces new functionality for managing dialogue history in the application. Two new controller functions, clearDialogueHistoryController and saveDialogueController, have been implemented to handle clearing specific dialogues and saving dialogue-related data. These controllers are integrated into the API routes in src/routes/api.ts.

The changes extend the inventory model by adding new schemas for dialogue management, including dialogueGiftSchema, completedDialogueSchema, dialogueSchema, and dialogueHistorySchema. The IInventoryResponse interface has been updated to include a new optional DialogueHistory property. These modifications support tracking dialogue interactions, including ranks, chemistry, completed dialogues, and year iterations.

Assessment against linked issues

Objective Addressed Explanation
Update year iteration [#577]
Save completed chat [#577]
Forget relationships at year rollover [#577]
Implement DialogueHistory inventory format [#577]

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

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

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

CodeRabbit Commands (Invoked using PR comments)

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

Other keywords and placeholders

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

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.
<!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- walkthrough_start --> ## Walkthrough The pull request introduces new functionality for managing dialogue history in the application. Two new controller functions, `clearDialogueHistoryController` and `saveDialogueController`, have been implemented to handle clearing specific dialogues and saving dialogue-related data. These controllers are integrated into the API routes in `src/routes/api.ts`. The changes extend the inventory model by adding new schemas for dialogue management, including `dialogueGiftSchema`, `completedDialogueSchema`, `dialogueSchema`, and `dialogueHistorySchema`. The `IInventoryResponse` interface has been updated to include a new optional `DialogueHistory` property. These modifications support tracking dialogue interactions, including ranks, chemistry, completed dialogues, and year iterations. ## Assessment against linked issues | Objective | Addressed | Explanation | |----------|-----------|-------------| | Update year iteration [#577] | ✅ | | | Save completed chat [#577] | ✅ | | | Forget relationships at year rollover [#577] | ✅ | | | Implement DialogueHistory inventory format [#577] | ✅ | | <!-- walkthrough_end --> <!-- internal state start --> <!-- FAHghAtBAEAqAWBLAztF0CGA7TBXALgPYQDmAplmQE4b5kAm0AxoQLasX4Bc0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4FOYOofdnsY9oAA= --> <!-- internal state end --> <!-- finishing_touch_checkbox_start --> ## Finishing Touches - [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings (Beta) <!-- finishing_touch_checkbox_end --> <!-- tips_start --> --- Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <details> <summary>🪧 Tips</summary> ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit <commit_id>, please review it.` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (Invoked using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR. ([Beta](https://docs.coderabbit.ai/early-access#beta)) - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### Documentation and Community - Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements. </details> <!-- tips_end -->
coderabbitai[bot] (Migrated from github.com) reviewed 2025-01-17 21:00:20 -08:00
coderabbitai[bot] (Migrated from github.com) left a comment
Author
Owner

Actionable comments posted: 3

🧹 Nitpick comments (7)
src/controllers/api/saveDialogueController.ts (3)

48-48: Remove commented out code.

The commented line suggests incomplete implementation or abandoned code.

Remove the commented line:

-    //dialogue.QueuedDialogues = request.QueuedDialogues;

59-60: Extract date calculation logic into a constant.

The date calculation uses magic numbers and could be made more readable.

Apply this diff to improve readability:

+    const MILLISECONDS_PER_DAY = 86400 * 1000;
+    const getTomorrowAtMidnightUTC = () => {
+        const now = Date.now();
+        return (Math.trunc(now / MILLISECONDS_PER_DAY) + 1) * MILLISECONDS_PER_DAY;
+    };
-    const tomorrowAt0Utc = (Math.trunc(Date.now() / (86400 * 1000)) + 1) * 86400 * 1000;
-    dialogue.AvailableDate = new Date(tomorrowAt0Utc);
+    const nextAvailableDate = getTomorrowAtMidnightUTC();
+    dialogue.AvailableDate = new Date(nextAvailableDate);

49-57: Use Set for efficient boolean operations.

The current implementation of boolean operations using arrays could be optimized using Set.

Apply this diff to improve performance:

+    const booleanSet = new Set(dialogue.Booleans);
     for (const bool of request.Booleans) {
-        dialogue.Booleans.push(bool);
+        booleanSet.add(bool);
     }
     for (const bool of request.ResetBooleans) {
-        const index = dialogue.Booleans.findIndex(x => x == bool);
-        if (index != -1) {
-            dialogue.Booleans.splice(index, 1);
-        }
+        booleanSet.delete(bool);
     }
+    dialogue.Booleans = Array.from(booleanSet);
src/types/inventoryTypes/inventoryTypes.ts (2)

970-970: Remove commented out code.

The commented line suggests incomplete implementation or abandoned code.

Remove the commented line:

-    //QueuedDialogues: any[];

953-994: Add JSDoc documentation for the new interfaces.

The new interfaces lack documentation explaining their purpose and usage.

Add JSDoc comments to improve code maintainability:

+/**
+ * Client-side representation of dialogue history.
+ */
 export interface IDialogueHistoryClient {
     YearIteration: number;
     Dialogues?: IDialogueClient[];
 }

+/**
+ * Database representation of dialogue history.
+ */
 export interface IDialogueHistoryDatabase {
     YearIteration: number;
     Dialogues?: IDialogueDatabase[];
 }

+/**
+ * Client-side representation of a dialogue entry.
+ */
 export interface IDialogueClient {
     Rank: number;
     Chemistry: number;
     AvailableDate: IMongoDate;
     AvailableGiftDate: IMongoDate;
     RankUpExpiry: IMongoDate;
     BountyChemExpiry: IMongoDate;
     Gifts: IDialogueGift[];
     Booleans: string[];
     Completed: ICompletedDialogue[];
     DialogueName: string;
 }

+/**
+ * Database representation of a dialogue entry.
+ * Converts IMongoDate properties to native Date objects.
+ */
 export interface IDialogueDatabase
     extends Omit<IDialogueClient, "AvailableDate" | "AvailableGiftDate" | "RankUpExpiry" | "BountyChemExpiry"> {
     AvailableDate: Date;
     AvailableGiftDate: Date;
     RankUpExpiry: Date;
     BountyChemExpiry: Date;
 }

+/**
+ * Represents a gift given during a dialogue.
+ */
 export interface IDialogueGift {
     Item: string;
     GiftedQuantity: number;
 }

+/**
+ * Represents a completed dialogue with its choices and state.
+ */
 export interface ICompletedDialogue {
     Id: string;
     Booleans: string[];
     Choices: number[];
 }
src/models/inventoryModels/inventoryModel.ts (2)

726-733: Consider adding array validation.

While the schema structure is good, consider adding validation for the array fields to ensure data integrity:

 const completedDialogueSchema = new Schema<ICompletedDialogue>(
     {
         Id: { type: String, required: true },
-        Booleans: { type: [String], required: true },
-        Choices: { type: [Number], required: true }
+        Booleans: { 
+            type: [String], 
+            required: true,
+            validate: [
+                (arr: string[]) => arr.length > 0,
+                'Booleans array cannot be empty'
+            ]
+        },
+        Choices: { 
+            type: [Number], 
+            required: true,
+            validate: [
+                (arr: number[]) => arr.length > 0,
+                'Choices array cannot be empty'
+            ]
+        }
     },
     { _id: false }
 );

764-770: Remove redundant required: false.

The required: false on the Dialogues field is redundant as it's the default behavior in Mongoose schemas.

 const dialogueHistorySchema = new Schema<IDialogueHistoryDatabase>(
     {
         YearIteration: { type: Number, required: true },
-        Dialogues: { type: [dialogueSchema], required: false }
+        Dialogues: { type: [dialogueSchema] }
     },
     { _id: false }
 );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1e4092e7f8 and d8201594b4.

📒 Files selected for processing (5)
  • src/controllers/api/clearDialogueHistoryController.ts (1 hunks)
  • src/controllers/api/saveDialogueController.ts (1 hunks)
  • src/models/inventoryModels/inventoryModel.ts (3 hunks)
  • src/routes/api.ts (4 hunks)
  • src/types/inventoryTypes/inventoryTypes.ts (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/controllers/api/clearDialogueHistoryController.ts

[error] 9-9: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (5)
src/routes/api.ts (1)

9-9: LGTM!

The new imports and routes are correctly added following the established pattern in the codebase.

Also applies to: 56-56, 123-123, 148-148

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

718-724: LGTM! Well-structured schema for dialogue gifts.

The schema correctly defines the structure for tracking gifted items and their quantities.


743-743: Address the commented out field.

The QueuedDialogues field is commented out. If this field is needed, please implement it. If not, remove the comment.

Would you like me to help implement this field or create a GitHub issue to track this task?


735-762: LGTM! Well-implemented date transformations.

The schema correctly handles date transformations and provides appropriate default values for array fields. The toJSON transform ensures proper date formatting in the response.


1131-1133: LGTM! Clean integration with inventory schema.

The DialogueHistory field is properly integrated into the inventory schema.

**Actionable comments posted: 3** <details> <summary>🧹 Nitpick comments (7)</summary><blockquote> <details> <summary>src/controllers/api/saveDialogueController.ts (3)</summary><blockquote> `48-48`: **Remove commented out code.** The commented line suggests incomplete implementation or abandoned code. Remove the commented line: ```diff - //dialogue.QueuedDialogues = request.QueuedDialogues; ``` --- `59-60`: **Extract date calculation logic into a constant.** The date calculation uses magic numbers and could be made more readable. Apply this diff to improve readability: ```diff + const MILLISECONDS_PER_DAY = 86400 * 1000; + const getTomorrowAtMidnightUTC = () => { + const now = Date.now(); + return (Math.trunc(now / MILLISECONDS_PER_DAY) + 1) * MILLISECONDS_PER_DAY; + }; - const tomorrowAt0Utc = (Math.trunc(Date.now() / (86400 * 1000)) + 1) * 86400 * 1000; - dialogue.AvailableDate = new Date(tomorrowAt0Utc); + const nextAvailableDate = getTomorrowAtMidnightUTC(); + dialogue.AvailableDate = new Date(nextAvailableDate); ``` --- `49-57`: **Use Set for efficient boolean operations.** The current implementation of boolean operations using arrays could be optimized using Set. Apply this diff to improve performance: ```diff + const booleanSet = new Set(dialogue.Booleans); for (const bool of request.Booleans) { - dialogue.Booleans.push(bool); + booleanSet.add(bool); } for (const bool of request.ResetBooleans) { - const index = dialogue.Booleans.findIndex(x => x == bool); - if (index != -1) { - dialogue.Booleans.splice(index, 1); - } + booleanSet.delete(bool); } + dialogue.Booleans = Array.from(booleanSet); ``` </blockquote></details> <details> <summary>src/types/inventoryTypes/inventoryTypes.ts (2)</summary><blockquote> `970-970`: **Remove commented out code.** The commented line suggests incomplete implementation or abandoned code. Remove the commented line: ```diff - //QueuedDialogues: any[]; ``` --- `953-994`: **Add JSDoc documentation for the new interfaces.** The new interfaces lack documentation explaining their purpose and usage. Add JSDoc comments to improve code maintainability: ```diff +/** + * Client-side representation of dialogue history. + */ export interface IDialogueHistoryClient { YearIteration: number; Dialogues?: IDialogueClient[]; } +/** + * Database representation of dialogue history. + */ export interface IDialogueHistoryDatabase { YearIteration: number; Dialogues?: IDialogueDatabase[]; } +/** + * Client-side representation of a dialogue entry. + */ export interface IDialogueClient { Rank: number; Chemistry: number; AvailableDate: IMongoDate; AvailableGiftDate: IMongoDate; RankUpExpiry: IMongoDate; BountyChemExpiry: IMongoDate; Gifts: IDialogueGift[]; Booleans: string[]; Completed: ICompletedDialogue[]; DialogueName: string; } +/** + * Database representation of a dialogue entry. + * Converts IMongoDate properties to native Date objects. + */ export interface IDialogueDatabase extends Omit<IDialogueClient, "AvailableDate" | "AvailableGiftDate" | "RankUpExpiry" | "BountyChemExpiry"> { AvailableDate: Date; AvailableGiftDate: Date; RankUpExpiry: Date; BountyChemExpiry: Date; } +/** + * Represents a gift given during a dialogue. + */ export interface IDialogueGift { Item: string; GiftedQuantity: number; } +/** + * Represents a completed dialogue with its choices and state. + */ export interface ICompletedDialogue { Id: string; Booleans: string[]; Choices: number[]; } ``` </blockquote></details> <details> <summary>src/models/inventoryModels/inventoryModel.ts (2)</summary><blockquote> `726-733`: **Consider adding array validation.** While the schema structure is good, consider adding validation for the array fields to ensure data integrity: ```diff const completedDialogueSchema = new Schema<ICompletedDialogue>( { Id: { type: String, required: true }, - Booleans: { type: [String], required: true }, - Choices: { type: [Number], required: true } + Booleans: { + type: [String], + required: true, + validate: [ + (arr: string[]) => arr.length > 0, + 'Booleans array cannot be empty' + ] + }, + Choices: { + type: [Number], + required: true, + validate: [ + (arr: number[]) => arr.length > 0, + 'Choices array cannot be empty' + ] + } }, { _id: false } ); ``` --- `764-770`: **Remove redundant required: false.** The `required: false` on the Dialogues field is redundant as it's the default behavior in Mongoose schemas. ```diff const dialogueHistorySchema = new Schema<IDialogueHistoryDatabase>( { YearIteration: { type: Number, required: true }, - Dialogues: { type: [dialogueSchema], required: false } + Dialogues: { type: [dialogueSchema] } }, { _id: false } ); ``` </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 1e4092e7f8816a9da5ec42523c80c368e12ee0ec and d8201594b4ca06ffc8237e598a6f66b3a432a49a. </details> <details> <summary>📒 Files selected for processing (5)</summary> * `src/controllers/api/clearDialogueHistoryController.ts` (1 hunks) * `src/controllers/api/saveDialogueController.ts` (1 hunks) * `src/models/inventoryModels/inventoryModel.ts` (3 hunks) * `src/routes/api.ts` (4 hunks) * `src/types/inventoryTypes/inventoryTypes.ts` (2 hunks) </details> <details> <summary>🧰 Additional context used</summary> <details> <summary>🪛 Biome (1.9.4)</summary> <details> <summary>src/controllers/api/clearDialogueHistoryController.ts</summary> [error] 9-9: Change to an optional chain. Unsafe fix: Change to an optional chain. (lint/complexity/useOptionalChain) </details> </details> </details> <details> <summary>🔇 Additional comments (5)</summary><blockquote> <details> <summary>src/routes/api.ts (1)</summary> `9-9`: **LGTM!** The new imports and routes are correctly added following the established pattern in the codebase. Also applies to: 56-56, 123-123, 148-148 </details> <details> <summary>src/models/inventoryModels/inventoryModel.ts (4)</summary> `718-724`: **LGTM! Well-structured schema for dialogue gifts.** The schema correctly defines the structure for tracking gifted items and their quantities. --- `743-743`: **Address the commented out field.** The `QueuedDialogues` field is commented out. If this field is needed, please implement it. If not, remove the comment. Would you like me to help implement this field or create a GitHub issue to track this task? --- `735-762`: **LGTM! Well-implemented date transformations.** The schema correctly handles date transformations and provides appropriate default values for array fields. The `toJSON` transform ensures proper date formatting in the response. --- `1131-1133`: **LGTM! Clean integration with inventory schema.** The DialogueHistory field is properly integrated into the inventory schema. </details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
@ -0,0 +5,4 @@
export const clearDialogueHistoryController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
const request = JSON.parse(String(req.body)) as IClearDialogueRequest;
coderabbitai[bot] (Migrated from github.com) commented 2025-01-17 21:00:19 -08:00
Author
Owner

⚠️ Potential issue

Add error handling for JSON parsing.

The JSON parsing operation could throw an exception if the request body is malformed.

Apply this diff to add error handling:

-    const request = JSON.parse(String(req.body)) as IClearDialogueRequest;
+    let request: IClearDialogueRequest;
+    try {
+        request = JSON.parse(String(req.body)) as IClearDialogueRequest;
+    } catch (error) {
+        res.status(400).json({ error: 'Invalid request body' });
+        return;
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    let request: IClearDialogueRequest;
    try {
        request = JSON.parse(String(req.body)) as IClearDialogueRequest;
    } catch (error) {
        res.status(400).json({ error: 'Invalid request body' });
        return;
    }
_:warning: Potential issue_ **Add error handling for JSON parsing.** The JSON parsing operation could throw an exception if the request body is malformed. Apply this diff to add error handling: ```diff - const request = JSON.parse(String(req.body)) as IClearDialogueRequest; + let request: IClearDialogueRequest; + try { + request = JSON.parse(String(req.body)) as IClearDialogueRequest; + } catch (error) { + res.status(400).json({ error: 'Invalid request body' }); + return; + } ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion let request: IClearDialogueRequest; try { request = JSON.parse(String(req.body)) as IClearDialogueRequest; } catch (error) { res.status(400).json({ error: 'Invalid request body' }); return; } ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
@ -0,0 +13,4 @@
inventory.DialogueHistory.Dialogues.splice(index, 1);
}
}
}
coderabbitai[bot] (Migrated from github.com) commented 2025-01-17 21:00:20 -08:00
Author
Owner

⚠️ Potential issue

Add request validation and error handling.

The function should validate the request structure and handle potential errors during inventory operations.

Apply this diff to add validation and error handling:

+    if (!request.Dialogues || !Array.isArray(request.Dialogues)) {
+        res.status(400).json({ error: 'Invalid request: Dialogues array is required' });
+        return;
+    }
+
     if (inventory.DialogueHistory && inventory.DialogueHistory.Dialogues) {
         for (const dialogueName of request.Dialogues) {
+            if (typeof dialogueName !== 'string') {
+                res.status(400).json({ error: 'Invalid request: Dialogue names must be strings' });
+                return;
+            }
+
             const index = inventory.DialogueHistory.Dialogues.findIndex(x => x.DialogueName == dialogueName);
             if (index != -1) {
                 inventory.DialogueHistory.Dialogues.splice(index, 1);
             }
         }
     }
-    await inventory.save();
-    res.end();
+    try {
+        await inventory.save();
+        res.status(200).json({
+            success: true,
+            message: 'Dialogue history cleared successfully'
+        });
+    } catch (error) {
+        res.status(500).json({ error: 'Failed to save inventory' });
+    }
📝 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.

    if (!request.Dialogues || !Array.isArray(request.Dialogues)) {
        res.status(400).json({ error: 'Invalid request: Dialogues array is required' });
        return;
    }

    if (inventory.DialogueHistory && inventory.DialogueHistory.Dialogues) {
        for (const dialogueName of request.Dialogues) {
            if (typeof dialogueName !== 'string') {
                res.status(400).json({ error: 'Invalid request: Dialogue names must be strings' });
                return;
            }

            const index = inventory.DialogueHistory.Dialogues.findIndex(x => x.DialogueName == dialogueName);
            if (index != -1) {
                inventory.DialogueHistory.Dialogues.splice(index, 1);
            }
        }
    }
    try {
        await inventory.save();
        res.status(200).json({
            success: true,
            message: 'Dialogue history cleared successfully'
        });
    } catch (error) {
        res.status(500).json({ error: 'Failed to save inventory' });
    }
🧰 Tools
🪛 Biome (1.9.4)

[error] 9-9: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

_:warning: Potential issue_ **Add request validation and error handling.** The function should validate the request structure and handle potential errors during inventory operations. Apply this diff to add validation and error handling: ```diff + if (!request.Dialogues || !Array.isArray(request.Dialogues)) { + res.status(400).json({ error: 'Invalid request: Dialogues array is required' }); + return; + } + if (inventory.DialogueHistory && inventory.DialogueHistory.Dialogues) { for (const dialogueName of request.Dialogues) { + if (typeof dialogueName !== 'string') { + res.status(400).json({ error: 'Invalid request: Dialogue names must be strings' }); + return; + } + const index = inventory.DialogueHistory.Dialogues.findIndex(x => x.DialogueName == dialogueName); if (index != -1) { inventory.DialogueHistory.Dialogues.splice(index, 1); } } } - await inventory.save(); - res.end(); + try { + await inventory.save(); + res.status(200).json({ + success: true, + message: 'Dialogue history cleared successfully' + }); + } catch (error) { + res.status(500).json({ error: 'Failed to save inventory' }); + } ``` <!-- 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 if (!request.Dialogues || !Array.isArray(request.Dialogues)) { res.status(400).json({ error: 'Invalid request: Dialogues array is required' }); return; } if (inventory.DialogueHistory && inventory.DialogueHistory.Dialogues) { for (const dialogueName of request.Dialogues) { if (typeof dialogueName !== 'string') { res.status(400).json({ error: 'Invalid request: Dialogue names must be strings' }); return; } const index = inventory.DialogueHistory.Dialogues.findIndex(x => x.DialogueName == dialogueName); if (index != -1) { inventory.DialogueHistory.Dialogues.splice(index, 1); } } } try { await inventory.save(); res.status(200).json({ success: true, message: 'Dialogue history cleared successfully' }); } catch (error) { res.status(500).json({ error: 'Failed to save inventory' }); } ````` </details> <!-- suggestion_end --> <details> <summary>🧰 Tools</summary> <details> <summary>🪛 Biome (1.9.4)</summary> [error] 9-9: Change to an optional chain. Unsafe fix: Change to an optional chain. (lint/complexity/useOptionalChain) </details> </details> <!-- This is an auto-generated comment by CodeRabbit -->
@ -0,0 +6,4 @@
export const saveDialogueController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const request = JSON.parse(String(req.body)) as SaveDialogueRequest;
coderabbitai[bot] (Migrated from github.com) commented 2025-01-17 21:00:20 -08:00
Author
Owner

⚠️ Potential issue

Add error handling for JSON parsing and type validation.

The JSON parsing operation could throw an exception if the request body is malformed.

Apply this diff to add error handling:

-    const request = JSON.parse(String(req.body)) as SaveDialogueRequest;
+    let request: SaveDialogueRequest;
+    try {
+        request = JSON.parse(String(req.body));
+        if (!('YearIteration' in request || 'DialogueName' in request)) {
+            throw new Error('Invalid request type');
+        }
+    } catch (error) {
+        res.status(400).json({ error: 'Invalid request body' });
+        return;
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    let request: SaveDialogueRequest;
    try {
        request = JSON.parse(String(req.body));
        if (!('YearIteration' in request || 'DialogueName' in request)) {
            throw new Error('Invalid request type');
        }
    } catch (error) {
        res.status(400).json({ error: 'Invalid request body' });
        return;
    }
_:warning: Potential issue_ **Add error handling for JSON parsing and type validation.** The JSON parsing operation could throw an exception if the request body is malformed. Apply this diff to add error handling: ```diff - const request = JSON.parse(String(req.body)) as SaveDialogueRequest; + let request: SaveDialogueRequest; + try { + request = JSON.parse(String(req.body)); + if (!('YearIteration' in request || 'DialogueName' in request)) { + throw new Error('Invalid request type'); + } + } catch (error) { + res.status(400).json({ error: 'Invalid request body' }); + return; + } ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion let request: SaveDialogueRequest; try { request = JSON.parse(String(req.body)); if (!('YearIteration' in request || 'DialogueName' in request)) { throw new Error('Invalid request type'); } } catch (error) { res.status(400).json({ error: 'Invalid request body' }); return; } ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
Sign in to join this conversation.
No description provided.