fix: Unable to save settings when accepting trade policy. #966
							
								
								
									
										22
									
								
								src/controllers/api/saveSettingsController.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/controllers/api/saveSettingsController.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,22 @@ | ||||
| import { getAccountIdForRequest } from "@/src/services/loginService"; | ||||
| import { getJSONfromString } from "@/src/helpers/stringHelpers"; | ||||
| import { getInventory } from "@/src/services/inventoryService"; | ||||
| import { RequestHandler } from "express"; | ||||
| import { ISettings } from "../../types/inventoryTypes/inventoryTypes"; | ||||
| 
 | ||||
| interface ISaveSettingsRequest { | ||||
|     Settings: ISettings; | ||||
| } | ||||
| 
 | ||||
| const saveSettingsController: RequestHandler = async (req, res): Promise<void> => { | ||||
|     const accountId = await getAccountIdForRequest(req); | ||||
| 
 | ||||
|     const settingResults = getJSONfromString<ISaveSettingsRequest>(String(req.body)); | ||||
| 
 | ||||
|     const inventory = await getInventory(accountId); | ||||
|     inventory.Settings = Object.assign(inventory.Settings, settingResults.Settings); | ||||
|  | ||||
|     await inventory.save(); | ||||
|     res.json(inventory.Settings); | ||||
| }; | ||||
| 
 | ||||
| export { saveSettingsController }; | ||||
| @ -86,6 +86,7 @@ import { updateQuestController } from "@/src/controllers/api/updateQuestControll | ||||
| import { updateSessionGetController, updateSessionPostController } from "@/src/controllers/api/updateSessionController"; | ||||
| import { updateThemeController } from "../controllers/api/updateThemeController"; | ||||
| import { upgradesController } from "@/src/controllers/api/upgradesController"; | ||||
| import { saveSettingsController } from "../controllers/api/saveSettingsController"; | ||||
| 
 | ||||
| const apiRouter = express.Router(); | ||||
| 
 | ||||
| @ -182,5 +183,6 @@ apiRouter.post("/updateQuest.php", updateQuestController); | ||||
| apiRouter.post("/updateSession.php", updateSessionPostController); | ||||
| apiRouter.post("/updateTheme.php", updateThemeController); | ||||
| apiRouter.post("/upgrades.php", upgradesController); | ||||
| apiRouter.post("/saveSettings.php", saveSettingsController); | ||||
| 
 | ||||
| export { apiRouter }; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	
training results?
The client wil send the full settings object like so
{"Settings":{"GiftMode":"GIFT_MODE_ALL","FriendInvRestriction":"GIFT_MODE_ALL","GuildInvRestriction":"GIFT_MODE_ALL","ShowFriendInvNotifications":true,"TradingRulesConfirmed":true,"SubscribedToSurveys":true}}
yea that all makes sense, I was just wondering why its called training results :D
Also I was wondering if you know whether these settings are meant to be overwritten in full or whether this situation can exist:
inventory.Settings: { setting1: "something"}
server sends: Settings: { setting2: "something2", setting3: "something3"}
because in that case the old settings would get lost. Just wanna make sure we checked for that
I just forgot to edit the name when i copyt the file.
I was thinking that too but i havet found anything eles to trigger that endpoint
Okey, right.
You could just use Object.Assign(old, new). This way old settings will be overwritten and new added.
It wil use Object.Assign now :)