From 984c4ee43ebbab4555b0ae68acc91d65bb37e76c Mon Sep 17 00:00:00 2001 From: Sainan Date: Mon, 6 May 2024 15:39:27 +0200 Subject: [PATCH] feat: persist boot location (#159) --- src/controllers/api/setBootLocationController.ts | 10 +++++++--- src/models/personalRoomsModel.ts | 7 ++++++- src/types/personalRoomsTypes.ts | 3 ++- src/types/shipTypes.ts | 4 +++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/controllers/api/setBootLocationController.ts b/src/controllers/api/setBootLocationController.ts index b469c349..62fcd680 100644 --- a/src/controllers/api/setBootLocationController.ts +++ b/src/controllers/api/setBootLocationController.ts @@ -1,6 +1,10 @@ -import { logger } from "@/src/utils/logger"; -import { Request, Response } from "express"; +import { RequestHandler } from "express"; +import { getPersonalRooms } from "@/src/services/personalRoomsService"; +import { TBootLocation } from "@/src/types/shipTypes"; -export const setBootLocationController = (_req: Request, res: Response) => { +export const setBootLocationController: RequestHandler = async (req, res) => { + const personalRooms = await getPersonalRooms(req.query.accountId as string); + personalRooms.Ship.BootLocation = req.query.bootLocation as string as TBootLocation; + await personalRooms.save(); res.end(); }; diff --git a/src/models/personalRoomsModel.ts b/src/models/personalRoomsModel.ts index 6829932e..8f4abede 100644 --- a/src/models/personalRoomsModel.ts +++ b/src/models/personalRoomsModel.ts @@ -46,7 +46,12 @@ const apartmentSchema = new Schema( ); const orbiterSchema = new Schema( - { Features: [String], Rooms: [roomSchema], ContentUrlSignature: String }, + { + Features: [String], + Rooms: [roomSchema], + ContentUrlSignature: String, + BootLocation: String + }, { _id: false } ); diff --git a/src/types/personalRoomsTypes.ts b/src/types/personalRoomsTypes.ts index d481808a..68ddec83 100644 --- a/src/types/personalRoomsTypes.ts +++ b/src/types/personalRoomsTypes.ts @@ -1,10 +1,11 @@ -import { IApartment, IRooms, IPlacedDecosDatabase } from "@/src/types/shipTypes"; +import { IApartment, IRooms, IPlacedDecosDatabase, TBootLocation } from "@/src/types/shipTypes"; import { Model, Types } from "mongoose"; export interface IOrbiter { Features: string[]; Rooms: IRooms[]; ContentUrlSignature: string; + BootLocation?: TBootLocation; } export interface IPersonalRooms { diff --git a/src/types/shipTypes.ts b/src/types/shipTypes.ts index c8b82a1a..53cf1f87 100644 --- a/src/types/shipTypes.ts +++ b/src/types/shipTypes.ts @@ -19,13 +19,15 @@ export interface IShipInterior { SkinFlavourItem?: string; } +export type TBootLocation = "LISET" | "DRIFTER_CAMP" | "APARTMENT"; + export interface IShip { Features: string[]; ShipId: IOid; ShipInterior: IShipInterior; Rooms: IRooms[]; ContentUrlSignature: string; - BootLocation?: "LISET" | "DRIFTER_CAMP" | "APARTMENT"; + BootLocation?: TBootLocation; } export interface IShipDatabase {