2025-02-09 07:17:42 -08:00
|
|
|
import { RequestHandler } from "express";
|
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
2025-04-23 11:37:10 -07:00
|
|
|
import { addFusionPoints, getInventory } from "@/src/services/inventoryService";
|
2025-02-09 07:17:42 -08:00
|
|
|
|
|
|
|
export const addCurrencyController: RequestHandler = async (req, res) => {
|
|
|
|
const accountId = await getAccountIdForRequest(req);
|
|
|
|
const request = req.body as IAddCurrencyRequest;
|
2025-04-23 11:37:10 -07:00
|
|
|
const inventory = await getInventory(accountId, request.currency);
|
|
|
|
if (request.currency == "FusionPoints") {
|
|
|
|
addFusionPoints(inventory, request.delta);
|
|
|
|
} else {
|
|
|
|
inventory[request.currency] += request.delta;
|
|
|
|
}
|
2025-02-09 07:17:42 -08:00
|
|
|
await inventory.save();
|
|
|
|
res.end();
|
|
|
|
};
|
|
|
|
|
|
|
|
interface IAddCurrencyRequest {
|
|
|
|
currency: "RegularCredits" | "PremiumCredits" | "FusionPoints" | "PrimeTokens";
|
|
|
|
delta: number;
|
|
|
|
}
|