diff --git a/src/controllers/api/setPlacedDecoInfoController.ts b/src/controllers/api/setPlacedDecoInfoController.ts index 56b9afe7..59477c52 100644 --- a/src/controllers/api/setPlacedDecoInfoController.ts +++ b/src/controllers/api/setPlacedDecoInfoController.ts @@ -1,11 +1,34 @@ import { getAccountIdForRequest } from "@/src/services/loginService"; -import { ISetPlacedDecoInfoRequest } from "@/src/types/shipTypes"; import { RequestHandler } from "express"; -import { handleSetPlacedDecoInfo } from "@/src/services/shipCustomizationsService"; +import { getPersonalRooms } from "@/src/services/personalRoomsService"; +import { IPictureFrameInfo } from "@/src/types/shipTypes"; export const setPlacedDecoInfoController: RequestHandler = async (req, res) => { const accountId = await getAccountIdForRequest(req); + const personalRooms = await getPersonalRooms(accountId); const payload = JSON.parse(req.body as string) as ISetPlacedDecoInfoRequest; - await handleSetPlacedDecoInfo(accountId, payload); + + const room = personalRooms.Ship.Rooms.find(room => room.Name === payload.Room); + if (!room) { + throw new Error("room not found"); + } + + const placedDeco = room.PlacedDecos?.find(x => x._id.toString() == payload.DecoId); + if (!placedDeco) { + throw new Error("deco not found"); + } + + placedDeco.PictureFrameInfo = payload.PictureFrameInfo; + + await personalRooms.save(); + res.end(); }; + +interface ISetPlacedDecoInfoRequest { + DecoType: string; + DecoId: string; + Room: string; + PictureFrameInfo: IPictureFrameInfo; + BootLocation: string; +} diff --git a/src/services/shipCustomizationsService.ts b/src/services/shipCustomizationsService.ts deleted file mode 100644 index 28a391d5..00000000 --- a/src/services/shipCustomizationsService.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { getPersonalRooms } from "@/src/services/personalRoomsService"; -import { ISetPlacedDecoInfoRequest } from "@/src/types/shipTypes"; - -export const handleSetPlacedDecoInfo = async (accountId: string, req: ISetPlacedDecoInfoRequest): Promise => { - const personalRooms = await getPersonalRooms(accountId); - - const room = personalRooms.Ship.Rooms.find(room => room.Name === req.Room); - if (!room) { - throw new Error("room not found"); - } - - const placedDeco = room.PlacedDecos?.find(x => x._id.toString() == req.DecoId); - if (!placedDeco) { - throw new Error("deco not found"); - } - - placedDeco.PictureFrameInfo = req.PictureFrameInfo; - - await personalRooms.save(); -}; diff --git a/src/types/shipTypes.ts b/src/types/shipTypes.ts index 012beb80..81d6bf9e 100644 --- a/src/types/shipTypes.ts +++ b/src/types/shipTypes.ts @@ -90,14 +90,6 @@ export interface ShipAttachments { HOOD_ORNAMENT: string; } -export interface ISetPlacedDecoInfoRequest { - DecoType: string; - DecoId: string; - Room: string; - PictureFrameInfo: IPictureFrameInfo; - BootLocation: string; -} - export interface IPictureFrameInfo { Image: string; Filter: string;