chore: use inventory projection for updateTheme (#1302)

Reviewed-on: OpenWF/SpaceNinjaServer#1302
This commit is contained in:
Sainan 2025-03-23 09:06:28 -07:00
parent cf3007b744
commit 8a29f06207
3 changed files with 14 additions and 35 deletions

View File

@ -1,25 +1,23 @@
import { getAccountIdForRequest } from "@/src/services/loginService";
import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { updateTheme } from "@/src/services/inventoryService";
import { IThemeUpdateRequest } from "@/src/types/requestTypes";
import { RequestHandler } from "express";
import { getInventory } from "@/src/services/inventoryService";
const updateThemeController: RequestHandler = async (request, response) => {
export const updateThemeController: RequestHandler = async (request, response) => {
const accountId = await getAccountIdForRequest(request);
const body = String(request.body);
const data = getJSONfromString<IThemeUpdateRequest>(String(request.body));
try {
const json = getJSONfromString<IThemeUpdateRequest>(body);
if (typeof json !== "object") {
throw new Error("Invalid data format");
}
await updateTheme(json, accountId);
} catch (err) {
console.error("Error parsing JSON data:", err);
}
const inventory = await getInventory(accountId, "ThemeStyle ThemeBackground ThemeSounds");
if (data.Style) inventory.ThemeStyle = data.Style;
if (data.Background) inventory.ThemeBackground = data.Background;
if (data.Sounds) inventory.ThemeSounds = data.Sounds;
await inventory.save();
response.json({});
};
export { updateThemeController };
interface IThemeUpdateRequest {
Style?: string;
Background?: string;
Sounds?: string;
}

View File

@ -29,11 +29,7 @@ import {
ICrewShipWeaponClient
} from "@/src/types/inventoryTypes/inventoryTypes";
import { IGenericUpdate, IUpdateNodeIntrosResponse } from "../types/genericUpdate";
import {
IMissionInventoryUpdateRequest,
IThemeUpdateRequest,
IUpdateChallengeProgressRequest
} from "../types/requestTypes";
import { IMissionInventoryUpdateRequest, IUpdateChallengeProgressRequest } from "../types/requestTypes";
import { logger } from "@/src/utils/logger";
import { convertInboxMessage, fromStoreItem, getExalted, getKeyChainItems } from "@/src/services/itemDataService";
import {
@ -891,15 +887,6 @@ export const updateGeneric = async (data: IGenericUpdate, accountId: string): Pr
};
};
export const updateTheme = async (data: IThemeUpdateRequest, accountId: string): Promise<void> => {
const inventory = await getInventory(accountId);
if (data.Style) inventory.ThemeStyle = data.Style;
if (data.Background) inventory.ThemeBackground = data.Background;
if (data.Sounds) inventory.ThemeSounds = data.Sounds;
await inventory.save();
};
export const addEquipment = (
inventory: TInventoryDatabaseDocument,
category: TEquipmentKey,

View File

@ -19,12 +19,6 @@ import {
ICollectibleEntry
} from "./inventoryTypes/inventoryTypes";
export interface IThemeUpdateRequest {
Style?: string;
Background?: string;
Sounds?: string;
}
export interface IAffiliationChange {
Tag: string;
Standing: number;