forked from OpenWF/SpaceNinjaServer
chore: use inventory projection for updateTheme (#1302)
Reviewed-on: OpenWF/SpaceNinjaServer#1302
This commit is contained in:
parent
cf3007b744
commit
8a29f06207
@ -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;
|
||||||
|
}
|
||||||
|
@ -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,
|
||||||
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user