2025-01-15 05:20:17 +01:00
|
|
|
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";
|
2025-01-15 05:20:17 +01:00
|
|
|
|
|
|
|
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);
|
2025-01-15 05:20:17 +01:00
|
|
|
}
|
|
|
|
await inventory.save();
|
|
|
|
res.end();
|
|
|
|
};
|
|
|
|
|
|
|
|
interface IAddItemRequest {
|
2025-01-24 15:58:13 +01:00
|
|
|
ItemType: string;
|
|
|
|
ItemCount: number;
|
2025-01-15 05:20:17 +01:00
|
|
|
}
|