SpaceNinjaServer/src/controllers/custom/addCurrencyController.ts
Sainan 7a8b12b372
Some checks failed
Build / build (push) Has been cancelled
Build Docker image / docker (push) Has been cancelled
chore: cap FusionPoints balance at 2147483647 (#1797)
Same idea as with typeCountSchema. The game needs to be able to store these safely in an i32 on the C++ side.

Reviewed-on: #1797
Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com>
Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
2025-04-23 11:37:10 -07:00

22 lines
804 B
TypeScript

import { RequestHandler } from "express";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { addFusionPoints, getInventory } from "@/src/services/inventoryService";
export const addCurrencyController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const request = req.body as IAddCurrencyRequest;
const inventory = await getInventory(accountId, request.currency);
if (request.currency == "FusionPoints") {
addFusionPoints(inventory, request.delta);
} else {
inventory[request.currency] += request.delta;
}
await inventory.save();
res.end();
};
interface IAddCurrencyRequest {
currency: "RegularCredits" | "PremiumCredits" | "FusionPoints" | "PrimeTokens";
delta: number;
}