chore: use inventory projection for updateTheme (#1302)
All checks were successful
Build / build (18) (push) Successful in 52s
Build / build (20) (push) Successful in 1m8s
Build Docker image / docker (push) Successful in 38s
Build / build (22) (push) Successful in 1m26s

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

View File

@ -29,11 +29,7 @@ import {
ICrewShipWeaponClient ICrewShipWeaponClient
} from "@/src/types/inventoryTypes/inventoryTypes"; } from "@/src/types/inventoryTypes/inventoryTypes";
import { IGenericUpdate, IUpdateNodeIntrosResponse } from "../types/genericUpdate"; import { IGenericUpdate, IUpdateNodeIntrosResponse } from "../types/genericUpdate";
import { import { IMissionInventoryUpdateRequest, IUpdateChallengeProgressRequest } from "../types/requestTypes";
IMissionInventoryUpdateRequest,
IThemeUpdateRequest,
IUpdateChallengeProgressRequest
} from "../types/requestTypes";
import { logger } from "@/src/utils/logger"; import { logger } from "@/src/utils/logger";
import { convertInboxMessage, fromStoreItem, getExalted, getKeyChainItems } from "@/src/services/itemDataService"; import { convertInboxMessage, fromStoreItem, getExalted, getKeyChainItems } from "@/src/services/itemDataService";
import { 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 = ( export const addEquipment = (
inventory: TInventoryDatabaseDocument, inventory: TInventoryDatabaseDocument,
category: TEquipmentKey, category: TEquipmentKey,

View File

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