2025-01-20 12:19:32 +01:00
|
|
|
import { importInventory, importLoadOutPresets } from "@/src/services/importService";
|
|
|
|
import { getInventory } from "@/src/services/inventoryService";
|
|
|
|
import { getLoadout } from "@/src/services/loadoutService";
|
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
|
|
|
import { IInventoryClient } from "@/src/types/inventoryTypes/inventoryTypes";
|
|
|
|
import { RequestHandler } from "express";
|
|
|
|
|
|
|
|
export const importController: RequestHandler = async (req, res) => {
|
|
|
|
const accountId = await getAccountIdForRequest(req);
|
2025-01-24 16:12:39 +01:00
|
|
|
const request = req.body as IImportRequest;
|
2025-01-20 12:19:32 +01:00
|
|
|
|
|
|
|
const inventory = await getInventory(accountId);
|
|
|
|
importInventory(inventory, request.inventory);
|
|
|
|
await inventory.save();
|
|
|
|
|
|
|
|
if (request.inventory.LoadOutPresets) {
|
|
|
|
const loadout = await getLoadout(accountId);
|
|
|
|
importLoadOutPresets(loadout, request.inventory.LoadOutPresets);
|
|
|
|
await loadout.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
res.end();
|
|
|
|
};
|
|
|
|
|
|
|
|
interface IImportRequest {
|
|
|
|
inventory: Partial<IInventoryClient>;
|
|
|
|
}
|