SpaceNinjaServer/src/controllers/api/giveKeyChainTriggeredItemsController.ts

24 lines
877 B
TypeScript
Raw Normal View History

2025-01-24 14:13:21 +01:00
import { RequestHandler } from "express";
import { parseString } from "@/src/helpers/general";
2025-01-24 14:13:21 +01:00
import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { getInventory } from "@/src/services/inventoryService";
2025-01-31 17:24:42 +01:00
import { IGroup } from "@/src/types/loginTypes";
import { giveKeyChainItem } 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);
const inventoryChanges = giveKeyChainItem(inventory, keyChainInfo);
2025-01-24 14:13:21 +01:00
await inventory.save();
res.send(inventoryChanges);
2025-01-24 14:13:21 +01:00
};
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
}