SpaceNinjaServer/src/controllers/api/giveKeyChainTriggeredItemsController.ts

39 lines
1.8 KiB
TypeScript
Raw Normal View History

2025-01-24 14:13:21 +01:00
import { RequestHandler } from "express";
import { isEmptyObject, parseString } from "@/src/helpers/general";
import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { addKeyChainItems, getInventory } from "@/src/services/inventoryService";
2025-01-31 17:24:42 +01:00
import { IGroup } from "@/src/types/loginTypes";
import { updateQuestStage } from "@/src/services/questService";
2025-01-24 14:13:21 +01:00
export const giveKeyChainTriggeredItemsController: RequestHandler = async (req, res) => {
const accountId = parseString(req.query.accountId);
2025-01-31 17:24:42 +01:00
const keyChainInfo = getJSONfromString<IKeyChainRequest>((req.body as string).toString());
2025-01-24 14:13:21 +01:00
const inventory = await getInventory(accountId);
2025-01-31 17:24:42 +01:00
const inventoryChanges = await addKeyChainItems(inventory, keyChainInfo);
2025-01-24 14:13:21 +01:00
if (isEmptyObject(inventoryChanges)) {
throw new Error("inventory changes was empty after getting keychain items: should not happen");
}
// items were added: update quest stage's i (item was given)
2025-01-31 17:24:42 +01:00
updateQuestStage(inventory, keyChainInfo, { i: true });
2025-01-24 14:13:21 +01:00
await inventory.save();
res.send(inventoryChanges);
//TODO: Check whether Wishlist is used to track items which should exist uniquely in the inventory
/*
some items are added or removed (not sure) to the wishlist, in that case a
WishlistChanges: ["/Lotus/Types/Items/ShipFeatureItems/ArsenalFeatureItem"],
is added to the response, need to determine for which items this is the case and what purpose this has.
*/
//{"KeyChain":"/Lotus/Types/Keys/VorsPrize/VorsPrizeQuestKeyChain","ChainStage":0}
//{"WishlistChanges":["/Lotus/Types/Items/ShipFeatureItems/ArsenalFeatureItem"],"MiscItems":[{"ItemType":"/Lotus/Types/Items/ShipFeatureItems/ArsenalFeatureItem","ItemCount":1}]}
};
2025-01-31 17:24:42 +01:00
export interface IKeyChainRequest {
2025-01-24 14:13:21 +01:00
KeyChain: string;
ChainStage: number;
2025-01-31 17:24:42 +01:00
Groups?: IGroup[];
2025-01-24 14:13:21 +01:00
}