feat: theme saving #137
							
								
								
									
										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 { shipDecorationsController } from "@/src/controllers/api/shipDecorationsController";
 | 
				
			||||||
import { setShipCustomizationsController } from "@/src/controllers/api/setShipCustomizationsController";
 | 
					import { setShipCustomizationsController } from "@/src/controllers/api/setShipCustomizationsController";
 | 
				
			||||||
import { setActiveShipController } from "@/src/controllers/api/setActiveShipController";
 | 
					import { setActiveShipController } from "@/src/controllers/api/setActiveShipController";
 | 
				
			||||||
 | 
					import { updateThemeController } from "../controllers/api/updateThemeController";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const apiRouter = express.Router();
 | 
					const apiRouter = express.Router();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -90,5 +91,6 @@ apiRouter.post("/rerollRandomMod.php", rerollRandomModController);
 | 
				
			|||||||
apiRouter.post("/joinSession.php", joinSessionController);
 | 
					apiRouter.post("/joinSession.php", joinSessionController);
 | 
				
			||||||
apiRouter.post("/saveLoadout.php", saveLoadoutController);
 | 
					apiRouter.post("/saveLoadout.php", saveLoadoutController);
 | 
				
			||||||
apiRouter.post("/trainingResult.php", trainingResultController);
 | 
					apiRouter.post("/trainingResult.php", trainingResultController);
 | 
				
			||||||
 | 
					apiRouter.post("/updateTheme.php", updateThemeController);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export { apiRouter };
 | 
					export { apiRouter };
 | 
				
			||||||
 | 
				
			|||||||
@ -15,7 +15,7 @@ import {
 | 
				
			|||||||
    IRawUpgrade
 | 
					    IRawUpgrade
 | 
				
			||||||
} from "@/src/types/inventoryTypes/inventoryTypes";
 | 
					} from "@/src/types/inventoryTypes/inventoryTypes";
 | 
				
			||||||
import { IGenericUpdate } from "../types/genericUpdate";
 | 
					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 { logger } from "@/src/utils/logger";
 | 
				
			||||||
import { WeaponTypeInternal } from "@/src/services/itemDataService";
 | 
					import { WeaponTypeInternal } from "@/src/services/itemDataService";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -150,6 +150,15 @@ export const updateGeneric = async (data: IGenericUpdate, accountId: string) =>
 | 
				
			|||||||
    return data;
 | 
					    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 (
 | 
					export const addWeapon = async (
 | 
				
			||||||
    weaponType: WeaponTypeInternal,
 | 
					    weaponType: WeaponTypeInternal,
 | 
				
			||||||
    weaponName: string,
 | 
					    weaponName: string,
 | 
				
			||||||
 | 
				
			|||||||
@ -17,6 +17,12 @@ export interface IArtifactsRequest {
 | 
				
			|||||||
    FusionPointCost: number;
 | 
					    FusionPointCost: number;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface IThemeUpdateRequest {
 | 
				
			||||||
 | 
					    Style?: string;
 | 
				
			||||||
 | 
					    Background?: string;
 | 
				
			||||||
 | 
					    Sounds?: string;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface IMissionInventoryUpdateRequest {
 | 
					export interface IMissionInventoryUpdateRequest {
 | 
				
			||||||
    rewardsMultiplier?: number;
 | 
					    rewardsMultiplier?: number;
 | 
				
			||||||
    ActiveBoosters?: IBooster[];
 | 
					    ActiveBoosters?: IBooster[];
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user