refactor getItemByBlueprint stuff to make more sense
This commit is contained in:
parent
03ac8ab010
commit
7313d35ed9
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
import { logger } from "@/src/utils/logger";
|
import { logger } from "@/src/utils/logger";
|
||||||
import { getItemByBlueprint } from "@/src/services/itemDataService";
|
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";
|
||||||
@ -37,8 +37,8 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
|
|||||||
inventory.PendingRecipes.pull(pendingRecipe._id);
|
inventory.PendingRecipes.pull(pendingRecipe._id);
|
||||||
await inventory.save();
|
await inventory.save();
|
||||||
|
|
||||||
const buildable = getItemByBlueprint(pendingRecipe.ItemType);
|
const recipe = getRecipe(pendingRecipe.ItemType);
|
||||||
if (!buildable) {
|
if (!recipe) {
|
||||||
logger.error(`no completed item found for recipe ${pendingRecipe._id}`);
|
logger.error(`no completed item found for recipe ${pendingRecipe._id}`);
|
||||||
throw new Error(`no completed item found for recipe ${pendingRecipe._id}`);
|
throw new Error(`no completed item found for recipe ${pendingRecipe._id}`);
|
||||||
}
|
}
|
||||||
@ -47,18 +47,18 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
|
|||||||
// TODO: Refund items
|
// TODO: Refund items
|
||||||
res.json({});
|
res.json({});
|
||||||
} else {
|
} else {
|
||||||
logger.debug("Claiming Recipe", { buildable, pendingRecipe });
|
logger.debug("Claiming Recipe", { recipe, pendingRecipe });
|
||||||
if (buildable.consumeOnUse) {
|
if (recipe.consumeOnUse) {
|
||||||
// TODO: Remove one instance of this recipe, and include that in InventoryChanges.
|
// TODO: Remove one instance of this recipe, and include that in InventoryChanges.
|
||||||
}
|
}
|
||||||
let currencyChanges = {};
|
let currencyChanges = {};
|
||||||
if (req.query.rush && buildable.skipBuildTimePrice) {
|
if (req.query.rush && recipe.skipBuildTimePrice) {
|
||||||
currencyChanges = await updateCurrency(buildable.skipBuildTimePrice, true, accountId);
|
currencyChanges = await updateCurrency(recipe.skipBuildTimePrice, true, accountId);
|
||||||
}
|
}
|
||||||
res.json({
|
res.json({
|
||||||
InventoryChanges: {
|
InventoryChanges: {
|
||||||
...currencyChanges,
|
...currencyChanges,
|
||||||
...(await addItem(accountId, buildable.resultType, buildable.num)).InventoryChanges
|
...(await addItem(accountId, recipe.resultType, recipe.num)).InventoryChanges
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -97,8 +97,7 @@ export const blueprintNames = Object.fromEntries(
|
|||||||
.map(name => [name, craftNames[name]])
|
.map(name => [name, craftNames[name]])
|
||||||
);
|
);
|
||||||
|
|
||||||
// Gets a recipe by its uniqueName
|
export const getRecipe = (uniqueName: string): IRecipe | undefined => {
|
||||||
export const getItemByBlueprint = (uniqueName: string): IRecipe | undefined => {
|
|
||||||
return ExportRecipes[uniqueName];
|
return ExportRecipes[uniqueName];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { unixTimesInMs } from "@/src/constants/timeConstants";
|
import { unixTimesInMs } from "@/src/constants/timeConstants";
|
||||||
import { getInventory } from "@/src/services/inventoryService";
|
import { getInventory } from "@/src/services/inventoryService";
|
||||||
import { getItemByBlueprint } from "@/src/services/itemDataService";
|
import { getRecipe } from "@/src/services/itemDataService";
|
||||||
import { logger } from "@/src/utils/logger";
|
import { logger } from "@/src/utils/logger";
|
||||||
import { Types } from "mongoose";
|
import { Types } from "mongoose";
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ export interface IResource {
|
|||||||
// };
|
// };
|
||||||
|
|
||||||
export const startRecipe = async (recipeName: string, accountId: string) => {
|
export const startRecipe = async (recipeName: string, accountId: string) => {
|
||||||
const recipe = getItemByBlueprint(recipeName);
|
const recipe = getRecipe(recipeName);
|
||||||
|
|
||||||
if (!recipe) {
|
if (!recipe) {
|
||||||
logger.error(`unknown recipe ${recipeName}`);
|
logger.error(`unknown recipe ${recipeName}`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user