SpaceNinjaServer/src/controllers/custom/addItemsController.ts
Sainan 2c2d90ba23
All checks were successful
Build / build (pull_request) Successful in 1m0s
make sure all webui options trigger respective inventory syncs
2025-09-08 05:39:40 +02:00

23 lines
845 B
TypeScript

import { getAccountIdForRequest } from "../../services/loginService.ts";
import { getInventory, addItem } from "../../services/inventoryService.ts";
import type { RequestHandler } from "express";
import { broadcastInventoryUpdate } from "../../services/wsService.ts";
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) {
await addItem(inventory, request.ItemType, request.ItemCount, true, undefined, request.Fingerprint, true);
}
await inventory.save();
res.end();
broadcastInventoryUpdate(req);
};
interface IAddItemRequest {
ItemType: string;
ItemCount: number;
Fingerprint?: string;
}