fix: incorrect types for PersonalRooms & TailorShop

This commit is contained in:
Sainan 2024-12-23 06:12:44 +01:00
parent 07b0d37440
commit 38583b1fc4
4 changed files with 31 additions and 16 deletions

View File

@ -8,19 +8,21 @@ import { Loadout } from "@/src/models/inventoryModels/loadoutModel";
import { logger } from "@/src/utils/logger"; import { logger } from "@/src/utils/logger";
import { toOid } from "@/src/helpers/inventoryHelpers"; import { toOid } from "@/src/helpers/inventoryHelpers";
import { IGetShipResponse } from "@/src/types/shipTypes"; import { IGetShipResponse } from "@/src/types/shipTypes";
import { IPersonalRooms } from "@/src/types/personalRoomsTypes";
export const getShipController: RequestHandler = async (req, res) => { export const getShipController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req); const accountId = await getAccountIdForRequest(req);
const personalRooms = await getPersonalRooms(accountId); const personalRoomsDb = await getPersonalRooms(accountId);
const personalRooms = personalRoomsDb.toJSON<IPersonalRooms>();
const loadout = await getLoadout(accountId); const loadout = await getLoadout(accountId);
const ship = await getShip(personalRooms.activeShipId, "ShipInteriorColors ShipAttachments SkinFlavourItem"); const ship = await getShip(personalRoomsDb.activeShipId, "ShipInteriorColors ShipAttachments SkinFlavourItem");
const getShipResponse: IGetShipResponse = { const getShipResponse: IGetShipResponse = {
ShipOwnerId: accountId, ShipOwnerId: accountId,
LoadOutInventory: { LoadOutPresets: loadout.toJSON() }, LoadOutInventory: { LoadOutPresets: loadout.toJSON() },
Ship: { Ship: {
...personalRooms.toJSON().Ship, ...personalRooms.Ship,
ShipId: toOid(personalRooms.activeShipId), ShipId: toOid(personalRoomsDb.activeShipId),
ShipInterior: { ShipInterior: {
Colors: ship.ShipInteriorColors, Colors: ship.ShipInteriorColors,
ShipAttachments: ship.ShipAttachments, ShipAttachments: ship.ShipAttachments,

View File

@ -1,5 +1,5 @@
import { toOid } from "@/src/helpers/inventoryHelpers"; import { toOid } from "@/src/helpers/inventoryHelpers";
import { IOrbiter, IPersonalRooms, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes"; import { IOrbiter, IPersonalRoomsDatabase, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes";
import { import {
IApartment, IApartment,
IFavouriteLoadoutDatabase, IFavouriteLoadoutDatabase,
@ -128,15 +128,15 @@ const tailorShopDefault: ITailorShopDatabase = {
] ]
}; };
export const personalRoomsSchema = new Schema<IPersonalRooms>({ export const personalRoomsSchema = new Schema<IPersonalRoomsDatabase>({
personalRoomsOwnerId: Schema.Types.ObjectId, personalRoomsOwnerId: Schema.Types.ObjectId,
activeShipId: Schema.Types.ObjectId, activeShipId: Schema.Types.ObjectId,
Ship: orbiterSchema, Ship: orbiterSchema,
Apartment: apartmentSchema, Apartment: apartmentSchema,
TailorShop: { TailorShop: { type: tailorShopSchema, default: tailorShopDefault }
type: tailorShopSchema,
default: tailorShopDefault as any as undefined // Yeah, this is bad, but mongoose types here are wrong.
}
}); });
export const PersonalRooms = model<IPersonalRooms, PersonalRoomsModelType>("PersonalRooms", personalRoomsSchema); export const PersonalRooms = model<IPersonalRoomsDatabase, PersonalRoomsModelType>(
"PersonalRooms",
personalRoomsSchema
);

View File

@ -1,4 +1,11 @@
import { IApartment, IRoom, IPlacedDecosDatabase, ITailorShop, TBootLocation } from "@/src/types/shipTypes"; import {
IApartment,
IRoom,
IPlacedDecosDatabase,
ITailorShop,
ITailorShopDatabase,
TBootLocation
} from "@/src/types/shipTypes";
import { Model, Types } from "mongoose"; import { Model, Types } from "mongoose";
export interface IOrbiter { export interface IOrbiter {
@ -9,11 +16,17 @@ export interface IOrbiter {
} }
export interface IPersonalRooms { export interface IPersonalRooms {
Ship: IOrbiter;
Apartment: IApartment;
TailorShop: ITailorShop;
}
export interface IPersonalRoomsDatabase {
personalRoomsOwnerId: Types.ObjectId; personalRoomsOwnerId: Types.ObjectId;
activeShipId: Types.ObjectId; activeShipId: Types.ObjectId;
Ship: IOrbiter; Ship: IOrbiter;
Apartment: IApartment; Apartment: IApartment;
TailorShop: ITailorShop; TailorShop: ITailorShopDatabase;
} }
export type RoomsType = { Name: string; MaxCapacity: number; PlacedDecos: Types.DocumentArray<IPlacedDecosDatabase> }; export type RoomsType = { Name: string; MaxCapacity: number; PlacedDecos: Types.DocumentArray<IPlacedDecosDatabase> };
@ -25,10 +38,10 @@ export type PersonalRoomsDocumentProps = {
Apartment: Omit<IApartment, "Rooms"> & { Apartment: Omit<IApartment, "Rooms"> & {
Rooms: RoomsType[]; Rooms: RoomsType[];
}; };
TailorShop: Omit<ITailorShop, "Rooms"> & { TailorShop: Omit<ITailorShopDatabase, "Rooms"> & {
Rooms: RoomsType[]; Rooms: RoomsType[];
}; };
}; };
// eslint-disable-next-line @typescript-eslint/ban-types // eslint-disable-next-line @typescript-eslint/ban-types
export type PersonalRoomsModelType = Model<IPersonalRooms, {}, PersonalRoomsDocumentProps>; export type PersonalRoomsModelType = Model<IPersonalRoomsDatabase, {}, PersonalRoomsDocumentProps>;

View File

@ -163,5 +163,5 @@ export interface ITailorShopDatabase {
export interface ITailorShop extends Omit<ITailorShopDatabase, "FavouriteLoadouts"> { export interface ITailorShop extends Omit<ITailorShopDatabase, "FavouriteLoadouts"> {
FavouriteLoadouts: IFavouriteLoadout[]; FavouriteLoadouts: IFavouriteLoadout[];
Colors: []; // ??? Colors?: []; // ???
} }