fix: incorrect types for PersonalRooms & TailorShop (#618)
This commit is contained in:
parent
68335aa91b
commit
918e33f126
@ -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,
|
||||||
|
@ -9,7 +9,7 @@ export const toInventoryResponse = (inventoryDatabase: { accountOwnerId: Types.O
|
|||||||
return inventoryResponse as unknown as IInventoryResponse;
|
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;
|
return { $oid: objectId.toString() } satisfies IOid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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,
|
||||||
@ -56,7 +56,7 @@ const roomSchema = new Schema<IRoom>(
|
|||||||
{
|
{
|
||||||
Name: String,
|
Name: String,
|
||||||
MaxCapacity: Number,
|
MaxCapacity: Number,
|
||||||
PlacedDecos: [placedDecosSchema]
|
PlacedDecos: { type: [placedDecosSchema], default: undefined }
|
||||||
},
|
},
|
||||||
{ _id: false }
|
{ _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,
|
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
|
||||||
|
);
|
||||||
|
@ -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>;
|
||||||
|
@ -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?: []; // ???
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user