fix: incorrect types for PersonalRooms & TailorShop #618

Merged
Sainan merged 3 commits from tailor-type into main 2024-12-22 21:21:48 -08:00
5 changed files with 33 additions and 18 deletions

View File

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

View File

@ -9,7 +9,7 @@ export const toInventoryResponse = (inventoryDatabase: { accountOwnerId: Types.O
return inventoryResponse as unknown as IInventoryResponse;
};
export const toOid = (objectId: Types.ObjectId) => {
export const toOid = (objectId: Types.ObjectId): IOid => {
return { $oid: objectId.toString() } satisfies IOid;
};

View File

@ -1,5 +1,5 @@
import { toOid } from "@/src/helpers/inventoryHelpers";
import { IOrbiter, IPersonalRooms, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes";
import { IOrbiter, IPersonalRoomsDatabase, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes";
import {
IApartment,
IFavouriteLoadoutDatabase,
@ -56,7 +56,7 @@ const roomSchema = new Schema<IRoom>(
{
Name: String,
MaxCapacity: Number,
PlacedDecos: [placedDecosSchema]
PlacedDecos: { type: [placedDecosSchema], default: undefined }
},
{ _id: false }
);
@ -128,15 +128,15 @@ const tailorShopDefault: ITailorShopDatabase = {
]
};
export const personalRoomsSchema = new Schema<IPersonalRooms>({
export const personalRoomsSchema = new Schema<IPersonalRoomsDatabase>({
personalRoomsOwnerId: Schema.Types.ObjectId,
activeShipId: Schema.Types.ObjectId,
Ship: orbiterSchema,
Apartment: apartmentSchema,
TailorShop: {
type: tailorShopSchema,
default: tailorShopDefault as any as undefined // Yeah, this is bad, but mongoose types here are wrong.
}
TailorShop: { type: tailorShopSchema, default: tailorShopDefault }
});
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";
export interface IOrbiter {
@ -9,11 +16,17 @@ export interface IOrbiter {
}
export interface IPersonalRooms {
Ship: IOrbiter;
Apartment: IApartment;
TailorShop: ITailorShop;
}
export interface IPersonalRoomsDatabase {
personalRoomsOwnerId: Types.ObjectId;
activeShipId: Types.ObjectId;
Ship: IOrbiter;
Apartment: IApartment;
TailorShop: ITailorShop;
TailorShop: ITailorShopDatabase;
}
export type RoomsType = { Name: string; MaxCapacity: number; PlacedDecos: Types.DocumentArray<IPlacedDecosDatabase> };
@ -25,10 +38,10 @@ export type PersonalRoomsDocumentProps = {
Apartment: Omit<IApartment, "Rooms"> & {
Rooms: RoomsType[];
};
TailorShop: Omit<ITailorShop, "Rooms"> & {
TailorShop: Omit<ITailorShopDatabase, "Rooms"> & {
Rooms: RoomsType[];
};
};
// 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"> {
FavouriteLoadouts: IFavouriteLoadout[];
Colors: []; // ???
Colors?: []; // ???
}