From 03704d0f963cfa74cdc4dc8468fbffcdf41bf139 Mon Sep 17 00:00:00 2001 From: Sainan Date: Tue, 28 May 2024 13:52:27 +0200 Subject: [PATCH 1/2] feat: handle updateChallengeProgress (#235) --- .../api/updateChallengeProgressController.ts | 17 +++++++++++++++-- src/services/inventoryService.ts | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/controllers/api/updateChallengeProgressController.ts b/src/controllers/api/updateChallengeProgressController.ts index b822d818..887224e3 100644 --- a/src/controllers/api/updateChallengeProgressController.ts +++ b/src/controllers/api/updateChallengeProgressController.ts @@ -1,7 +1,20 @@ import { RequestHandler } from "express"; +import { IChallengeProgress } from "@/src/types/inventoryTypes/inventoryTypes"; +import { getJSONfromString } from "@/src/helpers/stringHelpers"; +import { getAccountIdForRequest } from "@/src/services/loginService"; +import { getInventory, addChallenges } from "@/src/services/inventoryService"; -const updateChallengeProgressController: RequestHandler = (_request, response) => { - response.sendStatus(200); +interface IUpdateChallengeProgessRequest { + ChallengeProgress: IChallengeProgress[]; +} + +const updateChallengeProgressController: RequestHandler = async (req, res) => { + const payload: IUpdateChallengeProgessRequest = getJSONfromString(req.body.toString()); + const accountId = await getAccountIdForRequest(req); + const inventory = await getInventory(accountId); + addChallenges(inventory, payload.ChallengeProgress); + inventory.save(); + res.status(200).end(); }; export { updateChallengeProgressController }; diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 0d685258..550cbc62 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -290,7 +290,7 @@ const addMods = (inventory: IInventoryDatabaseDocument, itemsArray: IRawUpgrade[ }); }; -const addChallenges = (inventory: IInventoryDatabaseDocument, itemsArray: IChallengeProgress[] | undefined) => { +export const addChallenges = (inventory: IInventoryDatabaseDocument, itemsArray: IChallengeProgress[] | undefined) => { const category = inventory.ChallengeProgress; itemsArray?.forEach(({ Name, Progress }) => { -- 2.47.2 From dd76ef6227c5d8cf241a07293f8f5b1dc7e30331 Mon Sep 17 00:00:00 2001 From: Sainan Date: Thu, 16 May 2024 17:18:09 +0200 Subject: [PATCH 2/2] improve: remove buildConfig.json from git I think it makes more sense for this file to be distributed with the cache file --- .github/workflows/build.yml | 1 + .gitignore | 3 ++- static/data/.gitkeep | 0 static/data/buildConfig.json | 5 ----- 4 files changed, 3 insertions(+), 6 deletions(-) create mode 100644 static/data/.gitkeep delete mode 100644 static/data/buildConfig.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 795b187a..a5bff297 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,4 +16,5 @@ jobs: node-version: "20.x" - run: npm ci - run: cp config.json.example config.json + - run: echo '{"version":"","buildLabel":"","matchmakingBuildId":""}' > static/data/buildConfig.json - run: npm run build diff --git a/.gitignore b/.gitignore index 0b1cf50b..d1ec7373 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,8 @@ /.env /config.json -/static/data/*.bin +/static/data/** +!/static/data/.gitkeep yarn.lock /tmp diff --git a/static/data/.gitkeep b/static/data/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/static/data/buildConfig.json b/static/data/buildConfig.json deleted file mode 100644 index 405d395a..00000000 --- a/static/data/buildConfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "version": "35.6.0", - "buildLabel": "2024.05.15.11.07/4mPWinb13ZgMDySNQo3VeA", - "matchmakingBuildId": "6945333874579955227" -} -- 2.47.2