SpaceNinjaServer/src/controllers/custom/addItemsController.ts

20 lines
657 B
TypeScript
Raw Normal View History

import { getAccountIdForRequest } from "@/src/services/loginService";
2025-01-24 15:58:13 +01:00
import { getInventory, addItem } from "@/src/services/inventoryService";
2025-01-19 15:03:34 +01:00
import { RequestHandler } from "express";
export const addItemsController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const requests = req.body as IAddItemRequest[];
const inventory = await getInventory(accountId);
for (const request of requests) {
2025-01-24 15:58:13 +01:00
await addItem(inventory, request.ItemType, request.ItemCount);
}
await inventory.save();
res.end();
};
interface IAddItemRequest {
2025-01-24 15:58:13 +01:00
ItemType: string;
ItemCount: number;
}