fix: track FreeFavorsEarned & FreeFavorsUsed #792

Merged
Sainan merged 2 commits from track-favors into main 2025-01-17 05:43:51 -08:00
2 changed files with 33 additions and 16 deletions

View File

@ -50,6 +50,13 @@ export const syndicateSacrificeController: RequestHandler = async (request, resp
syndicate.Title ??= 0; syndicate.Title ??= 0;
syndicate.Title += 1; syndicate.Title += 1;
if (syndicate.Title > 0 && manifest.favours.length != 0) {
syndicate.FreeFavorsEarned ??= [];
if (!syndicate.FreeFavorsEarned.includes(syndicate.Title)) {
syndicate.FreeFavorsEarned.push(syndicate.Title);
}
}
coderabbitai[bot] commented 2025-01-16 21:43:11 -08:00 (Migrated from github.com)
Review

⚠️ Potential issue

Add null check for manifest and type safety

The code needs additional safety checks:

  1. Add null check for manifest before accessing favours
  2. Consider adding type definitions for FreeFavorsEarned

Apply this diff to add the necessary checks:

-    if (syndicate.Title > 0 && manifest.favours.length != 0) {
+    if (syndicate.Title > 0 && manifest?.favours?.length > 0) {
         syndicate.FreeFavorsEarned ??= [];
         if (!syndicate.FreeFavorsEarned.includes(syndicate.Title)) {
             syndicate.FreeFavorsEarned.push(syndicate.Title);
         }
     }
📝 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 (syndicate.Title > 0 && manifest?.favours?.length > 0) {
        syndicate.FreeFavorsEarned ??= [];
        if (!syndicate.FreeFavorsEarned.includes(syndicate.Title)) {
            syndicate.FreeFavorsEarned.push(syndicate.Title);
        }
    }
_:warning: Potential issue_ **Add null check for manifest and type safety** The code needs additional safety checks: 1. Add null check for `manifest` before accessing `favours` 2. Consider adding type definitions for `FreeFavorsEarned` Apply this diff to add the necessary checks: ```diff - if (syndicate.Title > 0 && manifest.favours.length != 0) { + if (syndicate.Title > 0 && manifest?.favours?.length > 0) { syndicate.FreeFavorsEarned ??= []; if (!syndicate.FreeFavorsEarned.includes(syndicate.Title)) { syndicate.FreeFavorsEarned.push(syndicate.Title); } } ``` <!-- 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 (syndicate.Title > 0 && manifest?.favours?.length > 0) { syndicate.FreeFavorsEarned ??= []; if (!syndicate.FreeFavorsEarned.includes(syndicate.Title)) { syndicate.FreeFavorsEarned.push(syndicate.Title); } } ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
await inventory.save(); await inventory.save();
if (reward) { if (reward) {

View File

@ -79,11 +79,20 @@ export const handlePurchase = async (
switch (purchaseRequest.PurchaseParams.Source) { switch (purchaseRequest.PurchaseParams.Source) {
case 2: case 2:
if (!purchaseRequest.PurchaseParams.UseFreeFavor!) { {
const syndicateTag = purchaseRequest.PurchaseParams.SyndicateTag!; const syndicateTag = purchaseRequest.PurchaseParams.SyndicateTag!;
if (purchaseRequest.PurchaseParams.UseFreeFavor!) {
const inventory = await getInventory(accountId);
const affiliation = inventory.Affiliations.find(x => x.Tag == syndicateTag)!;
affiliation.FreeFavorsUsed ??= [];
affiliation.FreeFavorsUsed.push(affiliation.FreeFavorsEarned![affiliation.FreeFavorsUsed.length]);
await inventory.save();
} else {
const syndicate = ExportSyndicates[syndicateTag]; const syndicate = ExportSyndicates[syndicateTag];
if (syndicate) { if (syndicate) {
const favour = syndicate.favours.find(x => x.storeItem == purchaseRequest.PurchaseParams.StoreItem); const favour = syndicate.favours.find(
x => x.storeItem == purchaseRequest.PurchaseParams.StoreItem
);
if (favour) { if (favour) {
const inventory = await getInventory(accountId); const inventory = await getInventory(accountId);
const affiliation = inventory.Affiliations.find(x => x.Tag == syndicateTag); const affiliation = inventory.Affiliations.find(x => x.Tag == syndicateTag);
@ -100,6 +109,7 @@ export const handlePurchase = async (
} }
} }
} }
}
break; break;
case 7: case 7:
if (purchaseRequest.PurchaseParams.SourceId! in ExportVendors) { if (purchaseRequest.PurchaseParams.SourceId! in ExportVendors) {