34 lines
1.0 KiB
TypeScript
Raw Normal View History

2023-08-31 14:29:09 +04:00
import { RequestHandler } from "express";
2024-05-08 22:53:06 +02:00
import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
2024-05-03 21:04:01 +02:00
import { IStatsView } from "@/src/types/statTypes";
import config from "@/config.json";
import view from "@/static/fixed_responses/view.json";
2024-05-03 21:04:01 +02:00
import allScans from "@/static/fixed_responses/allScans.json";
2023-08-31 14:29:09 +04:00
2024-05-08 22:53:06 +02:00
const viewController: RequestHandler = async (req, res) => {
if (!req.query.accountId) {
res.status(400).json({ error: "accountId was not provided" });
return;
}
const inventory = await Inventory.findOne({ accountOwnerId: req.query.accountId });
if (!inventory) {
res.status(400).json({ error: "inventory was undefined" });
return;
}
const responseJson: IStatsView = view;
2024-05-08 22:53:06 +02:00
responseJson.Weapons = [];
for (const item of inventory.XPInfo) {
responseJson.Weapons.push({
type: item.ItemType,
xp: item.XP
});
}
2024-05-03 21:04:01 +02:00
if (config.unlockAllScans) {
responseJson.Scans = allScans;
}
res.json(responseJson);
2023-08-31 14:29:09 +04:00
};
export { viewController };