feat: theme saving (#137)
This commit is contained in:
		
							parent
							
								
									6a6d2cb41b
								
							
						
					
					
						commit
						1c28a40258
					
				
							
								
								
									
										25
									
								
								src/controllers/api/updateThemeController.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/controllers/api/updateThemeController.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,25 @@
 | 
			
		||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
			
		||||
import { updateTheme } from "@/src/services/inventoryService";
 | 
			
		||||
import { IThemeUpdateRequest } from "@/src/types/requestTypes";
 | 
			
		||||
import { RequestHandler } from "express";
 | 
			
		||||
 | 
			
		||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
 | 
			
		||||
const updateThemeController: RequestHandler = async (request, response) => {
 | 
			
		||||
    const accountId = request.query.accountId as string;
 | 
			
		||||
    const body = String(request.body);
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
        const json = getJSONfromString(body) as IThemeUpdateRequest;
 | 
			
		||||
        if (typeof json !== "object") {
 | 
			
		||||
            throw new Error("Invalid data format");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        await updateTheme(json, accountId);
 | 
			
		||||
    } catch (err) {
 | 
			
		||||
        console.error("Error parsing JSON data:", err);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    response.json({});
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export { updateThemeController };
 | 
			
		||||
@ -40,6 +40,7 @@ import { claimCompletedRecipeController } from "@/src/controllers/api/claimCompl
 | 
			
		||||
import { shipDecorationsController } from "@/src/controllers/api/shipDecorationsController";
 | 
			
		||||
import { setShipCustomizationsController } from "@/src/controllers/api/setShipCustomizationsController";
 | 
			
		||||
import { setActiveShipController } from "@/src/controllers/api/setActiveShipController";
 | 
			
		||||
import { updateThemeController } from "../controllers/api/updateThemeController";
 | 
			
		||||
 | 
			
		||||
const apiRouter = express.Router();
 | 
			
		||||
 | 
			
		||||
@ -90,5 +91,6 @@ apiRouter.post("/rerollRandomMod.php", rerollRandomModController);
 | 
			
		||||
apiRouter.post("/joinSession.php", joinSessionController);
 | 
			
		||||
apiRouter.post("/saveLoadout.php", saveLoadoutController);
 | 
			
		||||
apiRouter.post("/trainingResult.php", trainingResultController);
 | 
			
		||||
apiRouter.post("/updateTheme.php", updateThemeController);
 | 
			
		||||
 | 
			
		||||
export { apiRouter };
 | 
			
		||||
 | 
			
		||||
@ -15,7 +15,7 @@ import {
 | 
			
		||||
    IRawUpgrade
 | 
			
		||||
} from "@/src/types/inventoryTypes/inventoryTypes";
 | 
			
		||||
import { IGenericUpdate } from "../types/genericUpdate";
 | 
			
		||||
import { IArtifactsRequest, IMissionInventoryUpdateRequest } from "../types/requestTypes";
 | 
			
		||||
import { IArtifactsRequest, IMissionInventoryUpdateRequest, IThemeUpdateRequest } from "../types/requestTypes";
 | 
			
		||||
import { logger } from "@/src/utils/logger";
 | 
			
		||||
import { WeaponTypeInternal } from "@/src/services/itemDataService";
 | 
			
		||||
 | 
			
		||||
@ -150,6 +150,15 @@ export const updateGeneric = async (data: IGenericUpdate, accountId: string) =>
 | 
			
		||||
    return data;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const updateTheme = async (data: IThemeUpdateRequest, accountId: string) => {
 | 
			
		||||
    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 addWeapon = async (
 | 
			
		||||
    weaponType: WeaponTypeInternal,
 | 
			
		||||
    weaponName: string,
 | 
			
		||||
 | 
			
		||||
@ -17,6 +17,12 @@ export interface IArtifactsRequest {
 | 
			
		||||
    FusionPointCost: number;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface IThemeUpdateRequest {
 | 
			
		||||
    Style?: string;
 | 
			
		||||
    Background?: string;
 | 
			
		||||
    Sounds?: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface IMissionInventoryUpdateRequest {
 | 
			
		||||
    rewardsMultiplier?: number;
 | 
			
		||||
    ActiveBoosters?: IBooster[];
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user