返回提交历史
Modified
src/controllers/api/claimCompletedRecipeController.ts
+3
-17
Modified
src/services/inventoryService.ts
+0
-14
XFEstudio/XFESpaceNinjaServer
chore: reuse inventory in claimCompletedRecipeController (#999)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/999 Co-authored-by: Sainan <sainan@calamity.inc> Co-committed-by: Sainan <sainan@calamity.inc>
d69cba6b
代码差异
2 个文件
+3
-31
@@ -7,14 +7,7 @@ import { getRecipe } from "@/src/services/itemDataService";
7
7
import { IOid } from "@/src/types/commonTypes";
8
8
import { getJSONfromString } from "@/src/helpers/stringHelpers";
9
9
import { getAccountIdForRequest } from "@/src/services/loginService";
10
import {
11
getInventory,
12
updateCurrency,
13
addItem,
14
addMiscItems,
15
addRecipes,
16
updateCurrencyByAccountId
17
} from "@/src/services/inventoryService";
10
import { getInventory, updateCurrency, addItem, addMiscItems, addRecipes } from "@/src/services/inventoryService";
18
11
19
12
export interface IClaimCompletedRecipeRequest {
20
13
RecipeIds: IOid[];
@@ -37,7 +30,6 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
37
30
// }
38
31
39
32
inventory.PendingRecipes.pull(pendingRecipe._id);
40
await inventory.save();
41
33
42
34
const recipe = getRecipe(pendingRecipe.ItemType);
43
35
if (!recipe) {
@@ -45,11 +37,10 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
45
37
}
46
38
47
39
if (req.query.cancel) {
48
const inventory = await getInventory(accountId);
49
40
const currencyChanges = updateCurrency(inventory, recipe.buildPrice * -1, false);
50
41
addMiscItems(inventory, recipe.ingredients);
51
await inventory.save();
52
42
43
await inventory.save();
53
44
// Not a bug: In the specific case of cancelling a recipe, InventoryChanges are expected to be the root.
54
45
res.json({
55
46
...currencyChanges,
@@ -59,7 +50,6 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
59
50
logger.debug("Claiming Recipe", { recipe, pendingRecipe });
60
51
61
52
if (recipe.secretIngredientAction == "SIA_SPECTRE_LOADOUT_COPY") {
62
const inventory = await getInventory(accountId);
63
53
inventory.PendingSpectreLoadouts ??= [];
64
54
inventory.SpectreLoadouts ??= [];
65
55
@@ -77,7 +67,6 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
77
67
);
78
68
inventory.SpectreLoadouts.push(inventory.PendingSpectreLoadouts[pendingLoadoutIndex]);
79
69
inventory.PendingSpectreLoadouts.splice(pendingLoadoutIndex, 1);
80
await inventory.save();
81
70
}
82
71
}
83
72
@@ -92,17 +81,14 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
92
81
93
82
InventoryChanges = { ...InventoryChanges, Recipes: recipeChanges };
94
83
95
const inventory = await getInventory(accountId);
96
84
addRecipes(inventory, recipeChanges);
97
await inventory.save();
98
85
}
99
86
if (req.query.rush) {
100
87
InventoryChanges = {
101
88
...InventoryChanges,
102
...(await updateCurrencyByAccountId(recipe.skipBuildTimePrice, true, accountId))
89
...updateCurrency(inventory, recipe.skipBuildTimePrice, true)
103
90
};
104
91
}
105
const inventory = await getInventory(accountId);
106
92
InventoryChanges = {
107
93
...InventoryChanges,
108
94
...(await addItem(inventory, recipe.resultType, recipe.num)).InventoryChanges
@@ -650,20 +650,6 @@ export const updateCurrency = (
650
650
return currencyChanges;
651
651
};
652
652
653
export const updateCurrencyByAccountId = async (
654
price: number,
655
usePremium: boolean,
656
accountId: string
657
): Promise<ICurrencyChanges> => {
658
if (!isCurrencyTracked(usePremium)) {
659
return {};
660
}
661
const inventory = await getInventory(accountId);
662
const currencyChanges = updateCurrency(inventory, price, usePremium);
663
await inventory.save();
664
return currencyChanges;
665
};
666
667
653
const standingLimitBinToInventoryKey: Record<
668
654
Exclude<TStandingLimitBin, "STANDING_LIMIT_BIN_NONE">,
669
655
keyof IDailyAffiliations