SpaceNinjaServer/src/controllers/api/purchaseController.ts
Sainan 6dd9b42f40 feat(webui): update inventory when in-game changes are made (#2239)
A bit of a rough initial implementation, but already works pretty well.

Closes #2224

Reviewed-on: OpenWF/SpaceNinjaServer#2239
Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com>
Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
2025-06-22 06:36:47 -07: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 });
};