forked from OpenWF/SpaceNinjaServer
Reviewed-on: OpenWF/SpaceNinjaServer#2694 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
21 lines
738 B
TypeScript
21 lines
738 B
TypeScript
import { getAccountIdForRequest } from "../../services/loginService.ts";
|
|
import { getInventory, addItem } from "../../services/inventoryService.ts";
|
|
import type { 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) {
|
|
await addItem(inventory, request.ItemType, request.ItemCount, true, undefined, request.Fingerprint, true);
|
|
}
|
|
await inventory.save();
|
|
res.end();
|
|
};
|
|
|
|
interface IAddItemRequest {
|
|
ItemType: string;
|
|
ItemCount: number;
|
|
Fingerprint?: string;
|
|
}
|