fix: update DojoCapacity & DojoEnergy when cancelling a room
All checks were successful
Build / build (18) (push) Successful in 42s
Build / build (20) (push) Successful in 48s
Build / build (22) (push) Successful in 39s
Build / build (18) (pull_request) Successful in 53s
Build / build (20) (pull_request) Successful in 39s
Build / build (22) (pull_request) Successful in 52s

This commit is contained in:
Sainan 2025-03-05 05:13:15 +01:00
parent 6e8ef2d186
commit cc61cc6257
3 changed files with 19 additions and 13 deletions

View File

@ -1,4 +1,4 @@
import { getDojoClient, getGuildForRequestEx } from "@/src/services/guildService";
import { getDojoClient, getGuildForRequestEx, removeDojoRoom } from "@/src/services/guildService";
import { getInventory } from "@/src/services/inventoryService";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { RequestHandler } from "express";
@ -14,7 +14,7 @@ export const abortDojoComponentController: RequestHandler = async (req, res) =>
const decoIndex = component.Decos!.findIndex(x => x._id.equals(request.DecoId));
component.Decos!.splice(decoIndex, 1);
} else {
guild.DojoComponents.pull({ _id: request.ComponentId });
removeDojoRoom(guild, request.ComponentId);
}
await guild.save();
res.json(getDojoClient(guild, 0));

View File

@ -1,19 +1,12 @@
import { getDojoClient, getGuildForRequest } from "@/src/services/guildService";
import { getDojoClient, getGuildForRequest, removeDojoRoom } from "@/src/services/guildService";
import { RequestHandler } from "express";
import { ExportDojoRecipes } from "warframe-public-export-plus";
export const queueDojoComponentDestructionController: RequestHandler = async (req, res) => {
const guild = await getGuildForRequest(req);
const componentId = req.query.componentId as string;
const component = guild.DojoComponents.splice(
guild.DojoComponents.findIndex(x => x._id.toString() === componentId),
1
)[0];
const room = Object.values(ExportDojoRecipes.rooms).find(x => x.resultType == component.pf);
if (room) {
guild.DojoCapacity -= room.capacity;
guild.DojoEnergy -= room.energy;
}
removeDojoRoom(guild, componentId);
await guild.save();
res.json(getDojoClient(guild, 1));
};

View File

@ -6,6 +6,7 @@ import { TInventoryDatabaseDocument } from "@/src/models/inventoryModels/invento
import { IDojoClient, IDojoComponentClient } from "@/src/types/guildTypes";
import { toMongoDate, toOid } from "@/src/helpers/inventoryHelpers";
import { Types } from "mongoose";
import { ExportDojoRecipes } from "warframe-public-export-plus";
export const getGuildForRequest = async (req: Request): Promise<TGuildDatabaseDocument> => {
const accountId = await getAccountIdForRequest(req);
@ -90,3 +91,15 @@ export const scaleRequiredCount = (count: number): number => {
// The recipes in the export are for Moon clans. For now we'll just assume we only have Ghost clans.
return Math.max(1, Math.trunc(count / 100));
};
export const removeDojoRoom = (guild: TGuildDatabaseDocument, componentId: string): void => {
const component = guild.DojoComponents.splice(
guild.DojoComponents.findIndex(x => x._id.toString() === componentId),
1
)[0];
const meta = Object.values(ExportDojoRecipes.rooms).find(x => x.resultType == component.pf);
if (meta) {
guild.DojoCapacity -= meta.capacity;
guild.DojoEnergy -= meta.energy;
}
};