2023-06-01 17:08:05 -07:00
|
|
|
import { RequestHandler } from "express";
|
2024-05-15 21:55:59 +02:00
|
|
|
import { config } from "@/src/services/configService";
|
2024-05-28 13:45:06 +02:00
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
2023-12-28 16:24:52 +01:00
|
|
|
import { getInventory } from "@/src/services/inventoryService";
|
2023-06-01 17:08:05 -07:00
|
|
|
|
2023-12-28 16:24:52 +01:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
|
|
export const getCreditsController: RequestHandler = async (req, res) => {
|
2024-05-31 13:17:10 +02:00
|
|
|
let accountId;
|
|
|
|
try {
|
|
|
|
accountId = await getAccountIdForRequest(req);
|
|
|
|
} catch (e) {
|
|
|
|
res.status(400).send("Log-in expired");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-06 16:26:58 +01:00
|
|
|
if (config.infiniteResources) {
|
2023-12-28 16:24:52 +01:00
|
|
|
res.json({
|
|
|
|
RegularCredits: 999999999,
|
|
|
|
TradesRemaining: 999999999,
|
|
|
|
PremiumCreditsFree: 999999999,
|
|
|
|
PremiumCredits: 999999999
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const inventory = await getInventory(accountId);
|
|
|
|
res.json({
|
|
|
|
RegularCredits: inventory.RegularCredits,
|
|
|
|
TradesRemaining: inventory.TradesRemaining,
|
|
|
|
PremiumCreditsFree: inventory.PremiumCreditsFree,
|
|
|
|
PremiumCredits: inventory.PremiumCredits
|
|
|
|
});
|
|
|
|
};
|