From a9cf95242c14caecfa6841a20350ff00e7c0a9fe Mon Sep 17 00:00:00 2001 From: Master Date: Tue, 25 Jun 2024 13:52:13 +0800 Subject: [PATCH] unlockShipFeature --- .../api/unlockShipFeatureController.ts | 18 ++++++++++++++++++ src/services/personalRoomsService.ts | 7 +++++++ 2 files changed, 25 insertions(+) create mode 100644 src/controllers/api/unlockShipFeatureController.ts diff --git a/src/controllers/api/unlockShipFeatureController.ts b/src/controllers/api/unlockShipFeatureController.ts new file mode 100644 index 00000000..430e3a85 --- /dev/null +++ b/src/controllers/api/unlockShipFeatureController.ts @@ -0,0 +1,18 @@ +import { RequestHandler } from "express"; +import { unlockShipFeature } from "@/src/services/personalRoomsService"; +import { parseString } from "@/src/helpers/general"; + +export interface IUnlockShipFeatureRequest { + Feature: string; + KeyChain: string; + ChainStage: number; +} + +// eslint-disable-next-line @typescript-eslint/no-misused-promises +export const unlockShipFeatureController: RequestHandler = async (req, res) => { + const accountId = parseString(req.query.accountId); + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call + const shipFeatureRequest = JSON.parse(req.body as string) as IUnlockShipFeatureRequest; + await unlockShipFeature(accountId, shipFeatureRequest.Feature); + res.send([]); +}; diff --git a/src/services/personalRoomsService.ts b/src/services/personalRoomsService.ts index c2d0b629..cb3d69b3 100644 --- a/src/services/personalRoomsService.ts +++ b/src/services/personalRoomsService.ts @@ -10,3 +10,10 @@ export const getPersonalRooms = async (accountId: string) => { } return personalRooms; }; + +export const unlockShipFeature = async (accountId: string, shipFeature: string) => { + const personalRooms = await getPersonalRooms(accountId); + if (!personalRooms.Ship.Features.includes(shipFeature)) personalRooms.Ship.Features.push(shipFeature); + await personalRooms.save(); +}; +