XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

feat: toggle wishlisted items (#1289)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1289

bc6f03b7
Sainan <sainan@calamity.inc>
提交于

代码差异

2 个文件 +26 -0
Added src/controllers/api/wishlistController.ts +24 -0
@@ -0,0 +1,24 @@
1 import { getJSONfromString } from "@/src/helpers/stringHelpers";
2 import { getInventory } from "@/src/services/inventoryService";
3 import { getAccountIdForRequest } from "@/src/services/loginService";
4 import { RequestHandler } from "express";
5
6 export const wishlistController: RequestHandler = async (req, res) => {
7 const accountId = await getAccountIdForRequest(req);
8 const inventory = await getInventory(accountId, "Wishlist");
9 const body = getJSONfromString<IWishlistRequest>(String(req.body));
10 for (const item of body.WishlistItems) {
11 const i = inventory.Wishlist.findIndex(x => x == item);
12 if (i == -1) {
13 inventory.Wishlist.push(item);
14 } else {
15 inventory.Wishlist.splice(i, 1);
16 }
17 }
18 await inventory.save();
19 res.end();
20 };
21
22 interface IWishlistRequest {
23 WishlistItems: string[];
24 }
Modified src/routes/api.ts +2 -0
@@ -115,6 +115,7 @@ import { updateSongChallengeController } from "@/src/controllers/api/updateSongC
115 115 import { updateThemeController } from "@/src/controllers/api/updateThemeController";
116 116 import { upgradesController } from "@/src/controllers/api/upgradesController";
117 117 import { valenceSwapController } from "@/src/controllers/api/valenceSwapController";
118 import { wishlistController } from "@/src/controllers/api/wishlistController";
118 119
119 120 const apiRouter = express.Router();
120 121
@@ -245,5 +246,6 @@ apiRouter.post("/updateSongChallenge.php", updateSongChallengeController);
245 246 apiRouter.post("/updateTheme.php", updateThemeController);
246 247 apiRouter.post("/upgrades.php", upgradesController);
247 248 apiRouter.post("/valenceSwap.php", valenceSwapController);
249 apiRouter.post("/wishlist.php", wishlistController);
248 250
249 251 export { apiRouter };