forked from OpenWF/SpaceNinjaServer
Reviewed-on: OpenWF/SpaceNinjaServer#2408 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
23 lines
874 B
TypeScript
23 lines
874 B
TypeScript
import { getAccountIdForRequest } from "@/src/services/loginService";
|
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
|
import { getInventory } from "@/src/services/inventoryService";
|
|
import { RequestHandler } from "express";
|
|
import { ISettings } from "@/src/types/inventoryTypes/inventoryTypes";
|
|
|
|
interface ISaveSettingsRequest {
|
|
Settings: ISettings;
|
|
}
|
|
|
|
const saveSettingsController: RequestHandler = async (req, res): Promise<void> => {
|
|
const accountId = await getAccountIdForRequest(req);
|
|
|
|
const settingResults = getJSONfromString<ISaveSettingsRequest>(String(req.body));
|
|
|
|
const inventory = await getInventory(accountId, "Settings");
|
|
inventory.Settings = Object.assign(inventory.Settings ?? {}, settingResults.Settings);
|
|
await inventory.save();
|
|
res.json({ Settings: inventory.Settings });
|
|
};
|
|
|
|
export { saveSettingsController };
|