workaround for a weird MongoDB restriction
All checks were successful
Build / build (18) (push) Successful in 41s
Build / build (22) (push) Successful in 53s
Build / build (20) (push) Successful in 52s
Build / build (18) (pull_request) Successful in 42s
Build / build (20) (pull_request) Successful in 54s
Build / build (22) (pull_request) Successful in 53s
All checks were successful
Build / build (18) (push) Successful in 41s
Build / build (22) (push) Successful in 53s
Build / build (20) (push) Successful in 52s
Build / build (18) (pull_request) Successful in 42s
Build / build (20) (pull_request) Successful in 54s
Build / build (22) (pull_request) Successful in 53s
This commit is contained in:
parent
b62b62f486
commit
a0ccf17130
@ -1,3 +1,4 @@
|
||||
import { TGuildDatabaseDocument } from "@/src/models/guildModel";
|
||||
import { TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
|
||||
import { getDojoClient, getGuildForRequestEx, scaleRequiredCount } from "@/src/services/guildService";
|
||||
import { addMiscItems, getInventory, updateCurrency } from "@/src/services/inventoryService";
|
||||
@ -36,13 +37,13 @@ export const contributeToDojoComponentController: RequestHandler = async (req, r
|
||||
throw new Error("attempt to contribute to a deco in an unfinished room?!");
|
||||
}
|
||||
const meta = Object.values(ExportDojoRecipes.rooms).find(x => x.resultType == component.pf)!;
|
||||
processContribution(request, inventory, inventoryChanges, meta, component);
|
||||
await processContribution(guild, request, inventory, inventoryChanges, meta, component);
|
||||
} else {
|
||||
// Room is past "Collecting Materials"
|
||||
if (request.DecoId) {
|
||||
const deco = component.Decos!.find(x => x._id.equals(request.DecoId))!;
|
||||
const meta = Object.values(ExportDojoRecipes.decos).find(x => x.resultType == deco.Type)!;
|
||||
processContribution(request, inventory, inventoryChanges, meta, deco);
|
||||
await processContribution(guild, request, inventory, inventoryChanges, meta, deco);
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,13 +55,14 @@ export const contributeToDojoComponentController: RequestHandler = async (req, r
|
||||
});
|
||||
};
|
||||
|
||||
const processContribution = (
|
||||
const processContribution = async (
|
||||
guild: TGuildDatabaseDocument,
|
||||
request: IContributeToDojoComponentRequest,
|
||||
inventory: TInventoryDatabaseDocument,
|
||||
inventoryChanges: IInventoryChanges,
|
||||
meta: IDojoRecipe,
|
||||
component: IDojoContributable
|
||||
): void => {
|
||||
): Promise<void> => {
|
||||
component.RegularCredits ??= 0;
|
||||
if (component.RegularCredits + request.RegularCredits > scaleRequiredCount(meta.price)) {
|
||||
request.RegularCredits = scaleRequiredCount(meta.price) - component.RegularCredits;
|
||||
@ -104,6 +106,10 @@ const processContribution = (
|
||||
}
|
||||
}
|
||||
if (fullyFunded) {
|
||||
if (request.IngredientContributions.length) {
|
||||
// We've already updated subpaths of MiscItems, we need to allow MongoDB to save this before we remove MiscItems.
|
||||
await guild.save();
|
||||
}
|
||||
component.RegularCredits = undefined;
|
||||
component.MiscItems = undefined;
|
||||
component.CompletionTime = new Date(Date.now() + meta.time * 1000);
|
||||
|
Loading…
x
Reference in New Issue
Block a user