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

fix: incorrect types for PersonalRooms & TailorShop (#618)

918e33f1
Sainan <sainan@calamity.inc>
提交于

代码差异

5 个文件 +33 -18
Modified src/controllers/api/getShipController.ts +6 -4
@@ -8,19 +8,21 @@ import { Loadout } from "@/src/models/inventoryModels/loadoutModel";
8 8 import { logger } from "@/src/utils/logger";
9 9 import { toOid } from "@/src/helpers/inventoryHelpers";
10 10 import { IGetShipResponse } from "@/src/types/shipTypes";
11 import { IPersonalRooms } from "@/src/types/personalRoomsTypes";
11 12
12 13 export const getShipController: RequestHandler = async (req, res) => {
13 14 const accountId = await getAccountIdForRequest(req);
14 const personalRooms = await getPersonalRooms(accountId);
15 const personalRoomsDb = await getPersonalRooms(accountId);
16 const personalRooms = personalRoomsDb.toJSON<IPersonalRooms>();
15 17 const loadout = await getLoadout(accountId);
16 const ship = await getShip(personalRooms.activeShipId, "ShipInteriorColors ShipAttachments SkinFlavourItem");
18 const ship = await getShip(personalRoomsDb.activeShipId, "ShipInteriorColors ShipAttachments SkinFlavourItem");
17 19
18 20 const getShipResponse: IGetShipResponse = {
19 21 ShipOwnerId: accountId,
20 22 LoadOutInventory: { LoadOutPresets: loadout.toJSON() },
21 23 Ship: {
22 ...personalRooms.toJSON().Ship,
23 ShipId: toOid(personalRooms.activeShipId),
24 ...personalRooms.Ship,
25 ShipId: toOid(personalRoomsDb.activeShipId),
24 26 ShipInterior: {
25 27 Colors: ship.ShipInteriorColors,
26 28 ShipAttachments: ship.ShipAttachments,
Modified src/helpers/inventoryHelpers.ts +1 -1
@@ -9,7 +9,7 @@ export const toInventoryResponse = (inventoryDatabase: { accountOwnerId: Types.O
9 9 return inventoryResponse as unknown as IInventoryResponse;
10 10 };
11 11
12 export const toOid = (objectId: Types.ObjectId) => {
12 export const toOid = (objectId: Types.ObjectId): IOid => {
13 13 return { $oid: objectId.toString() } satisfies IOid;
14 14 };
15 15
Modified src/models/personalRoomsModel.ts +8 -8
@@ -1,5 +1,5 @@
1 1 import { toOid } from "@/src/helpers/inventoryHelpers";
2 import { IOrbiter, IPersonalRooms, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes";
2 import { IOrbiter, IPersonalRoomsDatabase, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes";
3 3 import {
4 4 IApartment,
5 5 IFavouriteLoadoutDatabase,
@@ -56,7 +56,7 @@ const roomSchema = new Schema<IRoom>(
56 56 {
57 57 Name: String,
58 58 MaxCapacity: Number,
59 PlacedDecos: [placedDecosSchema]
59 PlacedDecos: { type: [placedDecosSchema], default: undefined }
60 60 },
61 61 { _id: false }
62 62 );
@@ -128,15 +128,15 @@ const tailorShopDefault: ITailorShopDatabase = {
128 128 ]
129 129 };
130 130
131 export const personalRoomsSchema = new Schema<IPersonalRooms>({
131 export const personalRoomsSchema = new Schema<IPersonalRoomsDatabase>({
132 132 personalRoomsOwnerId: Schema.Types.ObjectId,
133 133 activeShipId: Schema.Types.ObjectId,
134 134 Ship: orbiterSchema,
135 135 Apartment: apartmentSchema,
136 TailorShop: {
137 type: tailorShopSchema,
138 default: tailorShopDefault as any as undefined // Yeah, this is bad, but mongoose types here are wrong.
139 }
136 TailorShop: { type: tailorShopSchema, default: tailorShopDefault }
140 137 });
141 138
142 export const PersonalRooms = model<IPersonalRooms, PersonalRoomsModelType>("PersonalRooms", personalRoomsSchema);
139 export const PersonalRooms = model<IPersonalRoomsDatabase, PersonalRoomsModelType>(
140 "PersonalRooms",
141 personalRoomsSchema
142 );
Modified src/types/personalRoomsTypes.ts +17 -4
@@ -1,4 +1,11 @@
1 import { IApartment, IRoom, IPlacedDecosDatabase, ITailorShop, TBootLocation } from "@/src/types/shipTypes";
1 import {
2 IApartment,
3 IRoom,
4 IPlacedDecosDatabase,
5 ITailorShop,
6 ITailorShopDatabase,
7 TBootLocation
8 } from "@/src/types/shipTypes";
2 9 import { Model, Types } from "mongoose";
3 10
4 11 export interface IOrbiter {
@@ -9,11 +16,17 @@ export interface IOrbiter {
9 16 }
10 17
11 18 export interface IPersonalRooms {
19 Ship: IOrbiter;
20 Apartment: IApartment;
21 TailorShop: ITailorShop;
22 }
23
24 export interface IPersonalRoomsDatabase {
12 25 personalRoomsOwnerId: Types.ObjectId;
13 26 activeShipId: Types.ObjectId;
14 27 Ship: IOrbiter;
15 28 Apartment: IApartment;
16 TailorShop: ITailorShop;
29 TailorShop: ITailorShopDatabase;
17 30 }
18 31
19 32 export type RoomsType = { Name: string; MaxCapacity: number; PlacedDecos: Types.DocumentArray<IPlacedDecosDatabase> };
@@ -25,10 +38,10 @@ export type PersonalRoomsDocumentProps = {
25 38 Apartment: Omit<IApartment, "Rooms"> & {
26 39 Rooms: RoomsType[];
27 40 };
28 TailorShop: Omit<ITailorShop, "Rooms"> & {
41 TailorShop: Omit<ITailorShopDatabase, "Rooms"> & {
29 42 Rooms: RoomsType[];
30 43 };
31 44 };
32 45
33 46 // eslint-disable-next-line @typescript-eslint/ban-types
34 export type PersonalRoomsModelType = Model<IPersonalRooms, {}, PersonalRoomsDocumentProps>;
47 export type PersonalRoomsModelType = Model<IPersonalRoomsDatabase, {}, PersonalRoomsDocumentProps>;
Modified src/types/shipTypes.ts +1 -1
@@ -163,5 +163,5 @@ export interface ITailorShopDatabase {
163 163
164 164 export interface ITailorShop extends Omit<ITailorShopDatabase, "FavouriteLoadouts"> {
165 165 FavouriteLoadouts: IFavouriteLoadout[];
166 Colors: []; // ???
166 Colors?: []; // ???
167 167 }