2023-06-04 03:06:22 +02:00
|
|
|
/* eslint-disable @typescript-eslint/no-misused-promises */
|
|
|
|
import { toInventoryResponse } from "@/src/helpers/inventoryHelpers";
|
|
|
|
import { Inventory } from "@/src/models/inventoryModel";
|
2023-05-23 20:53:26 -04:00
|
|
|
import { Request, RequestHandler, Response } from "express";
|
2023-06-05 04:16:49 +08:00
|
|
|
import config from "@/config.json";
|
|
|
|
import testMissions from "@/static/fixed_responses/testMissions.json";
|
|
|
|
import testQuestKeys from "@/static/fixed_responses/testQuestKeys.json";
|
2023-05-19 15:22:48 -03:00
|
|
|
|
2023-06-04 03:06:22 +02:00
|
|
|
const inventoryController: RequestHandler = async (request: Request, response: Response) => {
|
2023-05-23 20:42:06 -04:00
|
|
|
const accountId = request.query.accountId;
|
2023-06-04 03:06:22 +02:00
|
|
|
|
|
|
|
if (!accountId) {
|
|
|
|
response.status(400).json({ error: "accountId was not provided" });
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const inventory = await Inventory.findOne({ accountOwnerId: accountId });
|
|
|
|
|
|
|
|
if (!inventory) {
|
|
|
|
response.status(400).json({ error: "inventory was undefined" });
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const inventoryJSON = inventory.toJSON();
|
|
|
|
|
|
|
|
const inventoreResponse = toInventoryResponse(inventoryJSON);
|
|
|
|
|
2023-06-05 04:16:49 +08:00
|
|
|
if (config.testMission) inventoreResponse.Missions = testMissions;
|
|
|
|
if (config.testQuestKey) inventoreResponse.QuestKeys = testQuestKeys;
|
|
|
|
|
2023-06-04 03:06:22 +02:00
|
|
|
response.json(inventoreResponse);
|
2023-05-19 15:22:48 -03:00
|
|
|
};
|
|
|
|
|
2023-06-02 00:20:49 -03:00
|
|
|
export { inventoryController };
|