SpaceNinjaServer/src/controllers/api/purchaseController.ts
Sainan f928bdba74
All checks were successful
Build / build (pull_request) Successful in 51s
feat(webui): update inventory when in-game changes are made
2025-06-21 20:35:13 +02:00

17 lines
815 B
TypeScript

import { RequestHandler } from "express";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { IPurchaseRequest } from "@/src/types/purchaseTypes";
import { handlePurchase } from "@/src/services/purchaseService";
import { getInventory } from "@/src/services/inventoryService";
import { sendWsBroadcastTo } from "@/src/services/webService";
export const purchaseController: RequestHandler = async (req, res) => {
const purchaseRequest = JSON.parse(String(req.body)) as IPurchaseRequest;
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
const response = await handlePurchase(purchaseRequest, inventory);
await inventory.save();
res.json(response);
sendWsBroadcastTo(accountId, { update_inventory: true });
};