XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

chore: use inventory projection for updateTheme (#1302)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1302

8a29f062
Sainan <sainan@calamity.inc>
提交于

代码差异

3 个文件 +14 -35
Modified src/controllers/api/updateThemeController.ts +13 -15
@@ -1,25 +1,23 @@
1 1 import { getAccountIdForRequest } from "@/src/services/loginService";
2 2 import { getJSONfromString } from "@/src/helpers/stringHelpers";
3 import { updateTheme } from "@/src/services/inventoryService";
4 import { IThemeUpdateRequest } from "@/src/types/requestTypes";
5 3 import { RequestHandler } from "express";
4 import { getInventory } from "@/src/services/inventoryService";
6 5
7 const updateThemeController: RequestHandler = async (request, response) => {
6 export const updateThemeController: RequestHandler = async (request, response) => {
8 7 const accountId = await getAccountIdForRequest(request);
9 const body = String(request.body);
8 const data = getJSONfromString<IThemeUpdateRequest>(String(request.body));
10 9
11 try {
12 const json = getJSONfromString<IThemeUpdateRequest>(body);
13 if (typeof json !== "object") {
14 throw new Error("Invalid data format");
15 }
16
17 await updateTheme(json, accountId);
18 } catch (err) {
19 console.error("Error parsing JSON data:", err);
20 }
10 const inventory = await getInventory(accountId, "ThemeStyle ThemeBackground ThemeSounds");
11 if (data.Style) inventory.ThemeStyle = data.Style;
12 if (data.Background) inventory.ThemeBackground = data.Background;
13 if (data.Sounds) inventory.ThemeSounds = data.Sounds;
14 await inventory.save();
21 15
22 16 response.json({});
23 17 };
24 18
25 export { updateThemeController };
19 interface IThemeUpdateRequest {
20 Style?: string;
21 Background?: string;
22 Sounds?: string;
23 }
Modified src/services/inventoryService.ts +1 -14
@@ -29,11 +29,7 @@ import {
29 29 ICrewShipWeaponClient
30 30 } from "@/src/types/inventoryTypes/inventoryTypes";
31 31 import { IGenericUpdate, IUpdateNodeIntrosResponse } from "../types/genericUpdate";
32 import {
33 IMissionInventoryUpdateRequest,
34 IThemeUpdateRequest,
35 IUpdateChallengeProgressRequest
36 } from "../types/requestTypes";
32 import { IMissionInventoryUpdateRequest, IUpdateChallengeProgressRequest } from "../types/requestTypes";
37 33 import { logger } from "@/src/utils/logger";
38 34 import { convertInboxMessage, fromStoreItem, getExalted, getKeyChainItems } from "@/src/services/itemDataService";
39 35 import {
@@ -891,15 +887,6 @@ export const updateGeneric = async (data: IGenericUpdate, accountId: string): Pr
891 887 };
892 888 };
893 889
894 export const updateTheme = async (data: IThemeUpdateRequest, accountId: string): Promise<void> => {
895 const inventory = await getInventory(accountId);
896 if (data.Style) inventory.ThemeStyle = data.Style;
897 if (data.Background) inventory.ThemeBackground = data.Background;
898 if (data.Sounds) inventory.ThemeSounds = data.Sounds;
899
900 await inventory.save();
901 };
902
903 890 export const addEquipment = (
904 891 inventory: TInventoryDatabaseDocument,
905 892 category: TEquipmentKey,
Modified src/types/requestTypes.ts +0 -6
@@ -19,12 +19,6 @@ import {
19 19 ICollectibleEntry
20 20 } from "./inventoryTypes/inventoryTypes";
21 21
22 export interface IThemeUpdateRequest {
23 Style?: string;
24 Background?: string;
25 Sounds?: string;
26 }
27
28 22 export interface IAffiliationChange {
29 23 Tag: string;
30 24 Standing: number;