SpaceNinjaServerOnlyGit/src/controllers/api/getCreditsController.ts
Jānis 0af98bc6c2 feat: mission rewards & more
fixes mission rewards, item xp, tutorial
2024-09-06 02:02:26 +03:00

30 lines
891 B
TypeScript

import { RequestHandler } from "express";
import { config } from "@/src/services/configService";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { getInventory } from "@/src/services/inventoryService";
// eslint-disable-next-line @typescript-eslint/no-misused-promises
export const getCreditsController: RequestHandler = async (req, res) => {
let accountId;
try {
accountId = await getAccountIdForRequest(req);
} catch (e) {
res.status(400).send("Log-in expired");
return;
}
if (config.infiniteResources) {
res.json({
RegularCredits: 999999999,
PremiumCredits: 999999999
});
return;
}
const inventory = await getInventory(accountId);
res.json({
RegularCredits: inventory.RegularCredits,
PremiumCredits: inventory.PremiumCredits
});
};