chore: reuse inventory in claimCompletedRecipeController
All checks were successful
Build / build (18) (push) Successful in 39s
Build / build (22) (push) Successful in 1m6s
Build / build (20) (push) Successful in 1m7s
Build / build (18) (pull_request) Successful in 38s
Build / build (20) (pull_request) Successful in 1m4s
Build / build (22) (pull_request) Successful in 1m6s
All checks were successful
Build / build (18) (push) Successful in 39s
Build / build (22) (push) Successful in 1m6s
Build / build (20) (push) Successful in 1m7s
Build / build (18) (pull_request) Successful in 38s
Build / build (20) (pull_request) Successful in 1m4s
Build / build (22) (pull_request) Successful in 1m6s
This commit is contained in:
parent
50d687e59a
commit
930aa0233d
@ -7,14 +7,7 @@ import { getRecipe } from "@/src/services/itemDataService";
|
|||||||
import { IOid } from "@/src/types/commonTypes";
|
import { IOid } from "@/src/types/commonTypes";
|
||||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||||
import {
|
import { getInventory, updateCurrency, addItem, addMiscItems, addRecipes } from "@/src/services/inventoryService";
|
||||||
getInventory,
|
|
||||||
updateCurrency,
|
|
||||||
addItem,
|
|
||||||
addMiscItems,
|
|
||||||
addRecipes,
|
|
||||||
updateCurrencyByAccountId
|
|
||||||
} from "@/src/services/inventoryService";
|
|
||||||
|
|
||||||
export interface IClaimCompletedRecipeRequest {
|
export interface IClaimCompletedRecipeRequest {
|
||||||
RecipeIds: IOid[];
|
RecipeIds: IOid[];
|
||||||
@ -37,7 +30,6 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
inventory.PendingRecipes.pull(pendingRecipe._id);
|
inventory.PendingRecipes.pull(pendingRecipe._id);
|
||||||
await inventory.save();
|
|
||||||
|
|
||||||
const recipe = getRecipe(pendingRecipe.ItemType);
|
const recipe = getRecipe(pendingRecipe.ItemType);
|
||||||
if (!recipe) {
|
if (!recipe) {
|
||||||
@ -45,11 +37,10 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (req.query.cancel) {
|
if (req.query.cancel) {
|
||||||
const inventory = await getInventory(accountId);
|
|
||||||
const currencyChanges = updateCurrency(inventory, recipe.buildPrice * -1, false);
|
const currencyChanges = updateCurrency(inventory, recipe.buildPrice * -1, false);
|
||||||
addMiscItems(inventory, recipe.ingredients);
|
addMiscItems(inventory, recipe.ingredients);
|
||||||
await inventory.save();
|
|
||||||
|
|
||||||
|
await inventory.save();
|
||||||
// Not a bug: In the specific case of cancelling a recipe, InventoryChanges are expected to be the root.
|
// Not a bug: In the specific case of cancelling a recipe, InventoryChanges are expected to be the root.
|
||||||
res.json({
|
res.json({
|
||||||
...currencyChanges,
|
...currencyChanges,
|
||||||
@ -59,7 +50,6 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
|
|||||||
logger.debug("Claiming Recipe", { recipe, pendingRecipe });
|
logger.debug("Claiming Recipe", { recipe, pendingRecipe });
|
||||||
|
|
||||||
if (recipe.secretIngredientAction == "SIA_SPECTRE_LOADOUT_COPY") {
|
if (recipe.secretIngredientAction == "SIA_SPECTRE_LOADOUT_COPY") {
|
||||||
const inventory = await getInventory(accountId);
|
|
||||||
inventory.PendingSpectreLoadouts ??= [];
|
inventory.PendingSpectreLoadouts ??= [];
|
||||||
inventory.SpectreLoadouts ??= [];
|
inventory.SpectreLoadouts ??= [];
|
||||||
|
|
||||||
@ -77,7 +67,6 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
|
|||||||
);
|
);
|
||||||
inventory.SpectreLoadouts.push(inventory.PendingSpectreLoadouts[pendingLoadoutIndex]);
|
inventory.SpectreLoadouts.push(inventory.PendingSpectreLoadouts[pendingLoadoutIndex]);
|
||||||
inventory.PendingSpectreLoadouts.splice(pendingLoadoutIndex, 1);
|
inventory.PendingSpectreLoadouts.splice(pendingLoadoutIndex, 1);
|
||||||
await inventory.save();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,17 +81,14 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
|
|||||||
|
|
||||||
InventoryChanges = { ...InventoryChanges, Recipes: recipeChanges };
|
InventoryChanges = { ...InventoryChanges, Recipes: recipeChanges };
|
||||||
|
|
||||||
const inventory = await getInventory(accountId);
|
|
||||||
addRecipes(inventory, recipeChanges);
|
addRecipes(inventory, recipeChanges);
|
||||||
await inventory.save();
|
|
||||||
}
|
}
|
||||||
if (req.query.rush) {
|
if (req.query.rush) {
|
||||||
InventoryChanges = {
|
InventoryChanges = {
|
||||||
...InventoryChanges,
|
...InventoryChanges,
|
||||||
...(await updateCurrencyByAccountId(recipe.skipBuildTimePrice, true, accountId))
|
...updateCurrency(inventory, recipe.skipBuildTimePrice, true)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const inventory = await getInventory(accountId);
|
|
||||||
InventoryChanges = {
|
InventoryChanges = {
|
||||||
...InventoryChanges,
|
...InventoryChanges,
|
||||||
...(await addItem(inventory, recipe.resultType, recipe.num)).InventoryChanges
|
...(await addItem(inventory, recipe.resultType, recipe.num)).InventoryChanges
|
||||||
|
@ -650,20 +650,6 @@ export const updateCurrency = (
|
|||||||
return currencyChanges;
|
return currencyChanges;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateCurrencyByAccountId = async (
|
|
||||||
price: number,
|
|
||||||
usePremium: boolean,
|
|
||||||
accountId: string
|
|
||||||
): Promise<ICurrencyChanges> => {
|
|
||||||
if (!isCurrencyTracked(usePremium)) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
const inventory = await getInventory(accountId);
|
|
||||||
const currencyChanges = updateCurrency(inventory, price, usePremium);
|
|
||||||
await inventory.save();
|
|
||||||
return currencyChanges;
|
|
||||||
};
|
|
||||||
|
|
||||||
const standingLimitBinToInventoryKey: Record<
|
const standingLimitBinToInventoryKey: Record<
|
||||||
Exclude<TStandingLimitBin, "STANDING_LIMIT_BIN_NONE">,
|
Exclude<TStandingLimitBin, "STANDING_LIMIT_BIN_NONE">,
|
||||||
keyof IDailyAffiliations
|
keyof IDailyAffiliations
|
||||||
|
Loading…
x
Reference in New Issue
Block a user