feat: archon shard fusion #785

Merged
Sainan merged 2 commits from shard-fusion into main 2025-01-16 20:09:26 -08:00
Showing only changes of commit 94c2232745 - Show all commits

View File

@ -8,7 +8,9 @@ export const archonFusionController: RequestHandler = async (req, res) => {
coderabbitai[bot] commented 2025-01-16 06:25:00 -08:00 (Migrated from github.com)
Review

🛠️ Refactor suggestion

Add input validation for the request.

The controller needs validation for:

  1. Empty or undefined request.Consumed array
  2. Minimum required items for each fusion type
  3. Invalid color combinations that could crash the combineColors function

Consider adding this validation at the start of the controller:

if (!request.Consumed?.length) {
    throw new Error("No items provided for fusion");
}

switch (request.FusionType) {
    case "AFT_ASCENT":
        if (request.Consumed.length < 1) {
            throw new Error("AFT_ASCENT requires at least 1 item");
        }
        break;
    case "AFT_COALESCENT":
        if (request.Consumed.length < 2) {
            throw new Error("AFT_COALESCENT requires at least 2 items");
        }
        // Validate colors exist in shardToColor mapping
        const color1 = shardToColor[request.Consumed[0].ItemType];
        const color2 = shardToColor[request.Consumed[1].ItemType];
        if (!color1 || !color2) {
            throw new Error("Invalid shard types provided");
        }
        break;
    default:
        throw new Error(`Unknown fusion type: ${request.FusionType}`);
}
_:hammer_and_wrench: Refactor suggestion_ **Add input validation for the request.** The controller needs validation for: 1. Empty or undefined `request.Consumed` array 2. Minimum required items for each fusion type 3. Invalid color combinations that could crash the `combineColors` function Consider adding this validation at the start of the controller: ```typescript if (!request.Consumed?.length) { throw new Error("No items provided for fusion"); } switch (request.FusionType) { case "AFT_ASCENT": if (request.Consumed.length < 1) { throw new Error("AFT_ASCENT requires at least 1 item"); } break; case "AFT_COALESCENT": if (request.Consumed.length < 2) { throw new Error("AFT_COALESCENT requires at least 2 items"); } // Validate colors exist in shardToColor mapping const color1 = shardToColor[request.Consumed[0].ItemType]; const color2 = shardToColor[request.Consumed[1].ItemType]; if (!color1 || !color2) { throw new Error("Invalid shard types provided"); } break; default: throw new Error(`Unknown fusion type: ${request.FusionType}`); } ``` <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2025-01-16 06:25:00 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Fix the item count negation logic.

The line request.Consumed.forEach(x => x.ItemCount * -1) performs the multiplication but doesn't assign the result back to x.ItemCount.

Apply this diff to fix the negation:

-request.Consumed.forEach(x => x.ItemCount * -1);
+request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1);
📝 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.

    request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1);
_:warning: Potential issue_ **Fix the item count negation logic.** The line `request.Consumed.forEach(x => x.ItemCount * -1)` performs the multiplication but doesn't assign the result back to `x.ItemCount`. Apply this diff to fix the negation: ```diff -request.Consumed.forEach(x => x.ItemCount * -1); +request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1); ``` <!-- 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 request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1); ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2025-01-16 06:25:00 -08:00 (Migrated from github.com)
Review

🛠️ Refactor suggestion

Add input validation for the request.

The controller needs validation for:

  1. Empty or undefined request.Consumed array
  2. Minimum required items for each fusion type
  3. Invalid color combinations that could crash the combineColors function

Consider adding this validation at the start of the controller:

if (!request.Consumed?.length) {
    throw new Error("No items provided for fusion");
}

switch (request.FusionType) {
    case "AFT_ASCENT":
        if (request.Consumed.length < 1) {
            throw new Error("AFT_ASCENT requires at least 1 item");
        }
        break;
    case "AFT_COALESCENT":
        if (request.Consumed.length < 2) {
            throw new Error("AFT_COALESCENT requires at least 2 items");
        }
        // Validate colors exist in shardToColor mapping
        const color1 = shardToColor[request.Consumed[0].ItemType];
        const color2 = shardToColor[request.Consumed[1].ItemType];
        if (!color1 || !color2) {
            throw new Error("Invalid shard types provided");
        }
        break;
    default:
        throw new Error(`Unknown fusion type: ${request.FusionType}`);
}
_:hammer_and_wrench: Refactor suggestion_ **Add input validation for the request.** The controller needs validation for: 1. Empty or undefined `request.Consumed` array 2. Minimum required items for each fusion type 3. Invalid color combinations that could crash the `combineColors` function Consider adding this validation at the start of the controller: ```typescript if (!request.Consumed?.length) { throw new Error("No items provided for fusion"); } switch (request.FusionType) { case "AFT_ASCENT": if (request.Consumed.length < 1) { throw new Error("AFT_ASCENT requires at least 1 item"); } break; case "AFT_COALESCENT": if (request.Consumed.length < 2) { throw new Error("AFT_COALESCENT requires at least 2 items"); } // Validate colors exist in shardToColor mapping const color1 = shardToColor[request.Consumed[0].ItemType]; const color2 = shardToColor[request.Consumed[1].ItemType]; if (!color1 || !color2) { throw new Error("Invalid shard types provided"); } break; default: throw new Error(`Unknown fusion type: ${request.FusionType}`); } ``` <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2025-01-16 06:25:00 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Fix the item count negation logic.

The line request.Consumed.forEach(x => x.ItemCount * -1) performs the multiplication but doesn't assign the result back to x.ItemCount.

Apply this diff to fix the negation:

-request.Consumed.forEach(x => x.ItemCount * -1);
+request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1);
📝 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.

    request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1);
_:warning: Potential issue_ **Fix the item count negation logic.** The line `request.Consumed.forEach(x => x.ItemCount * -1)` performs the multiplication but doesn't assign the result back to `x.ItemCount`. Apply this diff to fix the negation: ```diff -request.Consumed.forEach(x => x.ItemCount * -1); +request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1); ``` <!-- 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 request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1); ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
const accountId = await getAccountIdForRequest(req);
const request = JSON.parse(String(req.body)) as IArchonFusionRequest;
const inventory = await getInventory(accountId);
request.Consumed.forEach(x => x.ItemCount * -1);
coderabbitai[bot] commented 2025-01-16 06:25:00 -08:00 (Migrated from github.com)
Review

🛠️ Refactor suggestion

Add input validation for the request.

The controller needs validation for:

  1. Empty or undefined request.Consumed array
  2. Minimum required items for each fusion type
  3. Invalid color combinations that could crash the combineColors function

Consider adding this validation at the start of the controller:

if (!request.Consumed?.length) {
    throw new Error("No items provided for fusion");
}

switch (request.FusionType) {
    case "AFT_ASCENT":
        if (request.Consumed.length < 1) {
            throw new Error("AFT_ASCENT requires at least 1 item");
        }
        break;
    case "AFT_COALESCENT":
        if (request.Consumed.length < 2) {
            throw new Error("AFT_COALESCENT requires at least 2 items");
        }
        // Validate colors exist in shardToColor mapping
        const color1 = shardToColor[request.Consumed[0].ItemType];
        const color2 = shardToColor[request.Consumed[1].ItemType];
        if (!color1 || !color2) {
            throw new Error("Invalid shard types provided");
        }
        break;
    default:
        throw new Error(`Unknown fusion type: ${request.FusionType}`);
}
_:hammer_and_wrench: Refactor suggestion_ **Add input validation for the request.** The controller needs validation for: 1. Empty or undefined `request.Consumed` array 2. Minimum required items for each fusion type 3. Invalid color combinations that could crash the `combineColors` function Consider adding this validation at the start of the controller: ```typescript if (!request.Consumed?.length) { throw new Error("No items provided for fusion"); } switch (request.FusionType) { case "AFT_ASCENT": if (request.Consumed.length < 1) { throw new Error("AFT_ASCENT requires at least 1 item"); } break; case "AFT_COALESCENT": if (request.Consumed.length < 2) { throw new Error("AFT_COALESCENT requires at least 2 items"); } // Validate colors exist in shardToColor mapping const color1 = shardToColor[request.Consumed[0].ItemType]; const color2 = shardToColor[request.Consumed[1].ItemType]; if (!color1 || !color2) { throw new Error("Invalid shard types provided"); } break; default: throw new Error(`Unknown fusion type: ${request.FusionType}`); } ``` <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2025-01-16 06:25:00 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Fix the item count negation logic.

The line request.Consumed.forEach(x => x.ItemCount * -1) performs the multiplication but doesn't assign the result back to x.ItemCount.

Apply this diff to fix the negation:

-request.Consumed.forEach(x => x.ItemCount * -1);
+request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1);
📝 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.

    request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1);
_:warning: Potential issue_ **Fix the item count negation logic.** The line `request.Consumed.forEach(x => x.ItemCount * -1)` performs the multiplication but doesn't assign the result back to `x.ItemCount`. Apply this diff to fix the negation: ```diff -request.Consumed.forEach(x => x.ItemCount * -1); +request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1); ``` <!-- 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 request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1); ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
request.Consumed.forEach(x => {
coderabbitai[bot] commented 2025-01-16 06:25:00 -08:00 (Migrated from github.com)
Review

🛠️ Refactor suggestion

Add input validation for the request.

The controller needs validation for:

  1. Empty or undefined request.Consumed array
  2. Minimum required items for each fusion type
  3. Invalid color combinations that could crash the combineColors function

Consider adding this validation at the start of the controller:

if (!request.Consumed?.length) {
    throw new Error("No items provided for fusion");
}

switch (request.FusionType) {
    case "AFT_ASCENT":
        if (request.Consumed.length < 1) {
            throw new Error("AFT_ASCENT requires at least 1 item");
        }
        break;
    case "AFT_COALESCENT":
        if (request.Consumed.length < 2) {
            throw new Error("AFT_COALESCENT requires at least 2 items");
        }
        // Validate colors exist in shardToColor mapping
        const color1 = shardToColor[request.Consumed[0].ItemType];
        const color2 = shardToColor[request.Consumed[1].ItemType];
        if (!color1 || !color2) {
            throw new Error("Invalid shard types provided");
        }
        break;
    default:
        throw new Error(`Unknown fusion type: ${request.FusionType}`);
}
_:hammer_and_wrench: Refactor suggestion_ **Add input validation for the request.** The controller needs validation for: 1. Empty or undefined `request.Consumed` array 2. Minimum required items for each fusion type 3. Invalid color combinations that could crash the `combineColors` function Consider adding this validation at the start of the controller: ```typescript if (!request.Consumed?.length) { throw new Error("No items provided for fusion"); } switch (request.FusionType) { case "AFT_ASCENT": if (request.Consumed.length < 1) { throw new Error("AFT_ASCENT requires at least 1 item"); } break; case "AFT_COALESCENT": if (request.Consumed.length < 2) { throw new Error("AFT_COALESCENT requires at least 2 items"); } // Validate colors exist in shardToColor mapping const color1 = shardToColor[request.Consumed[0].ItemType]; const color2 = shardToColor[request.Consumed[1].ItemType]; if (!color1 || !color2) { throw new Error("Invalid shard types provided"); } break; default: throw new Error(`Unknown fusion type: ${request.FusionType}`); } ``` <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2025-01-16 06:25:00 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Fix the item count negation logic.

The line request.Consumed.forEach(x => x.ItemCount * -1) performs the multiplication but doesn't assign the result back to x.ItemCount.

Apply this diff to fix the negation:

-request.Consumed.forEach(x => x.ItemCount * -1);
+request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1);
📝 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.

    request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1);
_:warning: Potential issue_ **Fix the item count negation logic.** The line `request.Consumed.forEach(x => x.ItemCount * -1)` performs the multiplication but doesn't assign the result back to `x.ItemCount`. Apply this diff to fix the negation: ```diff -request.Consumed.forEach(x => x.ItemCount * -1); +request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1); ``` <!-- 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 request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1); ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
x.ItemCount *= -1;
coderabbitai[bot] commented 2025-01-16 06:25:00 -08:00 (Migrated from github.com)
Review

🛠️ Refactor suggestion

Add input validation for the request.

The controller needs validation for:

  1. Empty or undefined request.Consumed array
  2. Minimum required items for each fusion type
  3. Invalid color combinations that could crash the combineColors function

Consider adding this validation at the start of the controller:

if (!request.Consumed?.length) {
    throw new Error("No items provided for fusion");
}

switch (request.FusionType) {
    case "AFT_ASCENT":
        if (request.Consumed.length < 1) {
            throw new Error("AFT_ASCENT requires at least 1 item");
        }
        break;
    case "AFT_COALESCENT":
        if (request.Consumed.length < 2) {
            throw new Error("AFT_COALESCENT requires at least 2 items");
        }
        // Validate colors exist in shardToColor mapping
        const color1 = shardToColor[request.Consumed[0].ItemType];
        const color2 = shardToColor[request.Consumed[1].ItemType];
        if (!color1 || !color2) {
            throw new Error("Invalid shard types provided");
        }
        break;
    default:
        throw new Error(`Unknown fusion type: ${request.FusionType}`);
}
_:hammer_and_wrench: Refactor suggestion_ **Add input validation for the request.** The controller needs validation for: 1. Empty or undefined `request.Consumed` array 2. Minimum required items for each fusion type 3. Invalid color combinations that could crash the `combineColors` function Consider adding this validation at the start of the controller: ```typescript if (!request.Consumed?.length) { throw new Error("No items provided for fusion"); } switch (request.FusionType) { case "AFT_ASCENT": if (request.Consumed.length < 1) { throw new Error("AFT_ASCENT requires at least 1 item"); } break; case "AFT_COALESCENT": if (request.Consumed.length < 2) { throw new Error("AFT_COALESCENT requires at least 2 items"); } // Validate colors exist in shardToColor mapping const color1 = shardToColor[request.Consumed[0].ItemType]; const color2 = shardToColor[request.Consumed[1].ItemType]; if (!color1 || !color2) { throw new Error("Invalid shard types provided"); } break; default: throw new Error(`Unknown fusion type: ${request.FusionType}`); } ``` <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2025-01-16 06:25:00 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Fix the item count negation logic.

The line request.Consumed.forEach(x => x.ItemCount * -1) performs the multiplication but doesn't assign the result back to x.ItemCount.

Apply this diff to fix the negation:

-request.Consumed.forEach(x => x.ItemCount * -1);
+request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1);
📝 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.

    request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1);
_:warning: Potential issue_ **Fix the item count negation logic.** The line `request.Consumed.forEach(x => x.ItemCount * -1)` performs the multiplication but doesn't assign the result back to `x.ItemCount`. Apply this diff to fix the negation: ```diff -request.Consumed.forEach(x => x.ItemCount * -1); +request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1); ``` <!-- 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 request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1); ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
});
coderabbitai[bot] commented 2025-01-16 06:25:00 -08:00 (Migrated from github.com)
Review

🛠️ Refactor suggestion

Add input validation for the request.

The controller needs validation for:

  1. Empty or undefined request.Consumed array
  2. Minimum required items for each fusion type
  3. Invalid color combinations that could crash the combineColors function

Consider adding this validation at the start of the controller:

if (!request.Consumed?.length) {
    throw new Error("No items provided for fusion");
}

switch (request.FusionType) {
    case "AFT_ASCENT":
        if (request.Consumed.length < 1) {
            throw new Error("AFT_ASCENT requires at least 1 item");
        }
        break;
    case "AFT_COALESCENT":
        if (request.Consumed.length < 2) {
            throw new Error("AFT_COALESCENT requires at least 2 items");
        }
        // Validate colors exist in shardToColor mapping
        const color1 = shardToColor[request.Consumed[0].ItemType];
        const color2 = shardToColor[request.Consumed[1].ItemType];
        if (!color1 || !color2) {
            throw new Error("Invalid shard types provided");
        }
        break;
    default:
        throw new Error(`Unknown fusion type: ${request.FusionType}`);
}
_:hammer_and_wrench: Refactor suggestion_ **Add input validation for the request.** The controller needs validation for: 1. Empty or undefined `request.Consumed` array 2. Minimum required items for each fusion type 3. Invalid color combinations that could crash the `combineColors` function Consider adding this validation at the start of the controller: ```typescript if (!request.Consumed?.length) { throw new Error("No items provided for fusion"); } switch (request.FusionType) { case "AFT_ASCENT": if (request.Consumed.length < 1) { throw new Error("AFT_ASCENT requires at least 1 item"); } break; case "AFT_COALESCENT": if (request.Consumed.length < 2) { throw new Error("AFT_COALESCENT requires at least 2 items"); } // Validate colors exist in shardToColor mapping const color1 = shardToColor[request.Consumed[0].ItemType]; const color2 = shardToColor[request.Consumed[1].ItemType]; if (!color1 || !color2) { throw new Error("Invalid shard types provided"); } break; default: throw new Error(`Unknown fusion type: ${request.FusionType}`); } ``` <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2025-01-16 06:25:00 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Fix the item count negation logic.

The line request.Consumed.forEach(x => x.ItemCount * -1) performs the multiplication but doesn't assign the result back to x.ItemCount.

Apply this diff to fix the negation:

-request.Consumed.forEach(x => x.ItemCount * -1);
+request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1);
📝 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.

    request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1);
_:warning: Potential issue_ **Fix the item count negation logic.** The line `request.Consumed.forEach(x => x.ItemCount * -1)` performs the multiplication but doesn't assign the result back to `x.ItemCount`. Apply this diff to fix the negation: ```diff -request.Consumed.forEach(x => x.ItemCount * -1); +request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1); ``` <!-- 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 request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1); ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
addMiscItems(inventory, request.Consumed);
const newArchons: IMiscItem[] = [];
switch (request.FusionType) {

coderabbitai[bot] commented 2025-01-16 06:25:00 -08:00 (Migrated from github.com)
Review

🛠️ Refactor suggestion

Add input validation for the request.

The controller needs validation for:

  1. Empty or undefined request.Consumed array
  2. Minimum required items for each fusion type
  3. Invalid color combinations that could crash the combineColors function

Consider adding this validation at the start of the controller:

if (!request.Consumed?.length) {
    throw new Error("No items provided for fusion");
}

switch (request.FusionType) {
    case "AFT_ASCENT":
        if (request.Consumed.length < 1) {
            throw new Error("AFT_ASCENT requires at least 1 item");
        }
        break;
    case "AFT_COALESCENT":
        if (request.Consumed.length < 2) {
            throw new Error("AFT_COALESCENT requires at least 2 items");
        }
        // Validate colors exist in shardToColor mapping
        const color1 = shardToColor[request.Consumed[0].ItemType];
        const color2 = shardToColor[request.Consumed[1].ItemType];
        if (!color1 || !color2) {
            throw new Error("Invalid shard types provided");
        }
        break;
    default:
        throw new Error(`Unknown fusion type: ${request.FusionType}`);
}
_:hammer_and_wrench: Refactor suggestion_ **Add input validation for the request.** The controller needs validation for: 1. Empty or undefined `request.Consumed` array 2. Minimum required items for each fusion type 3. Invalid color combinations that could crash the `combineColors` function Consider adding this validation at the start of the controller: ```typescript if (!request.Consumed?.length) { throw new Error("No items provided for fusion"); } switch (request.FusionType) { case "AFT_ASCENT": if (request.Consumed.length < 1) { throw new Error("AFT_ASCENT requires at least 1 item"); } break; case "AFT_COALESCENT": if (request.Consumed.length < 2) { throw new Error("AFT_COALESCENT requires at least 2 items"); } // Validate colors exist in shardToColor mapping const color1 = shardToColor[request.Consumed[0].ItemType]; const color2 = shardToColor[request.Consumed[1].ItemType]; if (!color1 || !color2) { throw new Error("Invalid shard types provided"); } break; default: throw new Error(`Unknown fusion type: ${request.FusionType}`); } ``` <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2025-01-16 06:25:00 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Fix the item count negation logic.

The line request.Consumed.forEach(x => x.ItemCount * -1) performs the multiplication but doesn't assign the result back to x.ItemCount.

Apply this diff to fix the negation:

-request.Consumed.forEach(x => x.ItemCount * -1);
+request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1);
📝 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.

    request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1);
_:warning: Potential issue_ **Fix the item count negation logic.** The line `request.Consumed.forEach(x => x.ItemCount * -1)` performs the multiplication but doesn't assign the result back to `x.ItemCount`. Apply this diff to fix the negation: ```diff -request.Consumed.forEach(x => x.ItemCount * -1); +request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1); ``` <!-- 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 request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1); ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2025-01-16 06:25:00 -08:00 (Migrated from github.com)
Review

🛠️ Refactor suggestion

Add input validation for the request.

The controller needs validation for:

  1. Empty or undefined request.Consumed array
  2. Minimum required items for each fusion type
  3. Invalid color combinations that could crash the combineColors function

Consider adding this validation at the start of the controller:

if (!request.Consumed?.length) {
    throw new Error("No items provided for fusion");
}

switch (request.FusionType) {
    case "AFT_ASCENT":
        if (request.Consumed.length < 1) {
            throw new Error("AFT_ASCENT requires at least 1 item");
        }
        break;
    case "AFT_COALESCENT":
        if (request.Consumed.length < 2) {
            throw new Error("AFT_COALESCENT requires at least 2 items");
        }
        // Validate colors exist in shardToColor mapping
        const color1 = shardToColor[request.Consumed[0].ItemType];
        const color2 = shardToColor[request.Consumed[1].ItemType];
        if (!color1 || !color2) {
            throw new Error("Invalid shard types provided");
        }
        break;
    default:
        throw new Error(`Unknown fusion type: ${request.FusionType}`);
}
_:hammer_and_wrench: Refactor suggestion_ **Add input validation for the request.** The controller needs validation for: 1. Empty or undefined `request.Consumed` array 2. Minimum required items for each fusion type 3. Invalid color combinations that could crash the `combineColors` function Consider adding this validation at the start of the controller: ```typescript if (!request.Consumed?.length) { throw new Error("No items provided for fusion"); } switch (request.FusionType) { case "AFT_ASCENT": if (request.Consumed.length < 1) { throw new Error("AFT_ASCENT requires at least 1 item"); } break; case "AFT_COALESCENT": if (request.Consumed.length < 2) { throw new Error("AFT_COALESCENT requires at least 2 items"); } // Validate colors exist in shardToColor mapping const color1 = shardToColor[request.Consumed[0].ItemType]; const color2 = shardToColor[request.Consumed[1].ItemType]; if (!color1 || !color2) { throw new Error("Invalid shard types provided"); } break; default: throw new Error(`Unknown fusion type: ${request.FusionType}`); } ``` <!-- This is an auto-generated comment by CodeRabbit -->
coderabbitai[bot] commented 2025-01-16 06:25:00 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Fix the item count negation logic.

The line request.Consumed.forEach(x => x.ItemCount * -1) performs the multiplication but doesn't assign the result back to x.ItemCount.

Apply this diff to fix the negation:

-request.Consumed.forEach(x => x.ItemCount * -1);
+request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1);
📝 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.

    request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1);
_:warning: Potential issue_ **Fix the item count negation logic.** The line `request.Consumed.forEach(x => x.ItemCount * -1)` performs the multiplication but doesn't assign the result back to `x.ItemCount`. Apply this diff to fix the negation: ```diff -request.Consumed.forEach(x => x.ItemCount * -1); +request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1); ``` <!-- 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 request.Consumed.forEach(x => x.ItemCount = x.ItemCount * -1); ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->