fix: Unable to save settings when accepting trade policy. #966

Merged
OrdisPrime merged 5 commits from :main into main 2025-02-19 14:09:02 -08:00
2 changed files with 24 additions and 0 deletions
Showing only changes of commit 6c6403f460 - Show all commits

View 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 trainingResults = getJSONfromString<ISaveSettingsRequest>(String(req.body));
const inventory = await getInventory(accountId);
inventory.Settings = trainingResults.Settings;

training results?

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}}

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

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

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

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

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.

> 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 :)

It wil use Object.Assign now :)
await inventory.save();
res.json(inventory.Settings);
};
export { saveSettingsController };

View File

@ -86,6 +86,7 @@ import { updateQuestController } from "@/src/controllers/api/updateQuestControll
import { updateSessionGetController, updateSessionPostController } from "@/src/controllers/api/updateSessionController"; import { updateSessionGetController, updateSessionPostController } from "@/src/controllers/api/updateSessionController";
import { updateThemeController } from "../controllers/api/updateThemeController"; import { updateThemeController } from "../controllers/api/updateThemeController";
import { upgradesController } from "@/src/controllers/api/upgradesController"; import { upgradesController } from "@/src/controllers/api/upgradesController";
import { saveSettingsController } from "../controllers/api/saveSettingsController";
const apiRouter = express.Router(); const apiRouter = express.Router();
@ -182,5 +183,6 @@ apiRouter.post("/updateQuest.php", updateQuestController);
apiRouter.post("/updateSession.php", updateSessionPostController); apiRouter.post("/updateSession.php", updateSessionPostController);
apiRouter.post("/updateTheme.php", updateThemeController); apiRouter.post("/updateTheme.php", updateThemeController);
apiRouter.post("/upgrades.php", upgradesController); apiRouter.post("/upgrades.php", upgradesController);
apiRouter.post("/saveSettings.php", saveSettingsController);
export { apiRouter }; export { apiRouter };