SpaceNinjaServer/src/controllers/api/inventoryController.ts

30 lines
925 B
TypeScript
Raw Normal View History

/* 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-05-19 15:22:48 -03:00
const inventoryController: RequestHandler = async (request: Request, response: Response) => {
const accountId = request.query.accountId;
if (!accountId) {
response.status(400).json({ error: "accountId was not provided" });
return;
}
console.log(accountId);
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);
response.json(inventoreResponse);
2023-05-19 15:22:48 -03:00
};
2023-06-02 00:20:49 -03:00
export { inventoryController };