SpaceNinjaServer/src/controllers/api/giveKeyChainTriggeredItemsController.ts

18 lines
787 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";
import { giveKeyChainItem } from "@/src/services/questService";
import { IKeyChainRequest } from "@/src/types/requestTypes";
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 = await 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
};