fix: acquiring ships #619
@ -15,7 +15,7 @@ export const getShipController: RequestHandler = async (req, res) => {
|
||||
const personalRoomsDb = await getPersonalRooms(accountId);
|
||||
const personalRooms = personalRoomsDb.toJSON<IPersonalRooms>();
|
||||
const loadout = await getLoadout(accountId);
|
||||
const ship = await getShip(personalRoomsDb.activeShipId, "ShipInteriorColors ShipAttachments SkinFlavourItem");
|
||||
const ship = await getShip(personalRoomsDb.activeShipId, "ShipAttachments SkinFlavourItem");
|
||||
|
||||
const getShipResponse: IGetShipResponse = {
|
||||
ShipOwnerId: accountId,
|
||||
@ -24,7 +24,7 @@ export const getShipController: RequestHandler = async (req, res) => {
|
||||
...personalRooms.Ship,
|
||||
ShipId: toOid(personalRoomsDb.activeShipId),
|
||||
ShipInterior: {
|
||||
Colors: ship.ShipInteriorColors,
|
||||
Colors: personalRooms.ShipInteriorColors,
|
||||
ShipAttachments: ship.ShipAttachments,
|
||||
SkinFlavourItem: ship.SkinFlavourItem
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ const inventoryController: RequestHandler = async (request, response) => {
|
||||
|
||||
const inventory = await Inventory.findOne({ accountOwnerId: account._id.toString() })
|
||||
.populate<{ LoadOutPresets: ILoadoutDatabase }>("LoadOutPresets")
|
||||
.populate<{ Ships: IShipInventory }>("Ships", "-ShipInteriorColors");
|
||||
.populate<{ Ships: IShipInventory }>("Ships");
|
||||
|
||||
if (!inventory) {
|
||||
response.status(400).json({ error: "inventory was undefined" });
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { setShipCustomizations } from "@/src/services/shipCustomizationsService";
|
||||
import { ISetShipCustomizationsRequest } from "@/src/types/shipTypes";
|
||||
import { logger } from "@/src/utils/logger";
|
||||
@ -5,9 +6,10 @@ import { RequestHandler } from "express";
|
||||
|
||||
export const setShipCustomizationsController: RequestHandler = async (req, res) => {
|
||||
try {
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
const setShipCustomizationsRequest = JSON.parse(req.body as string) as ISetShipCustomizationsRequest;
|
||||
|
||||
const setShipCustomizationsResponse = await setShipCustomizations(setShipCustomizationsRequest);
|
||||
const setShipCustomizationsResponse = await setShipCustomizations(accountId, setShipCustomizationsRequest);
|
||||
res.json(setShipCustomizationsResponse);
|
||||
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { toOid } from "@/src/helpers/inventoryHelpers";
|
||||
import { colorSchema } from "@/src/models/inventoryModels/inventoryModel";
|
||||
import { IOrbiter, IPersonalRoomsDatabase, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes";
|
||||
import {
|
||||
IApartment,
|
||||
@ -131,6 +132,7 @@ const tailorShopDefault: ITailorShopDatabase = {
|
||||
export const personalRoomsSchema = new Schema<IPersonalRoomsDatabase>({
|
||||
personalRoomsOwnerId: Schema.Types.ObjectId,
|
||||
activeShipId: Schema.Types.ObjectId,
|
||||
ShipInteriorColors: colorSchema,
|
||||
Ship: orbiterSchema,
|
||||
Apartment: apartmentSchema,
|
||||
TailorShop: { type: tailorShopSchema, default: tailorShopDefault }
|
||||
|
@ -8,7 +8,6 @@ const shipSchema = new Schema<IShipDatabase>(
|
||||
{
|
||||
ItemType: String,
|
||||
ShipOwnerId: Schema.Types.ObjectId,
|
||||
ShipInteriorColors: colorSchema,
|
||||
ShipExteriorColors: colorSchema,
|
||||
AirSupportPower: String,
|
||||
ShipAttachments: { HOOD_ORNAMENT: String },
|
||||
|
@ -41,6 +41,7 @@ import {
|
||||
ExportResources,
|
||||
ExportUpgrades
|
||||
} from "warframe-public-export-plus";
|
||||
import { createShip } from "./shipService";
|
||||
|
||||
export const createInventory = async (
|
||||
accountOwnerId: Types.ObjectId,
|
||||
@ -129,19 +130,35 @@ export const addItem = async (
|
||||
}
|
||||
if (typeName in ExportResources) {
|
||||
const inventory = await getInventory(accountId);
|
||||
const miscItemChanges = [
|
||||
{
|
||||
ItemType: typeName,
|
||||
ItemCount: quantity
|
||||
} satisfies IMiscItem
|
||||
];
|
||||
addMiscItems(inventory, miscItemChanges);
|
||||
await inventory.save();
|
||||
return {
|
||||
InventoryChanges: {
|
||||
MiscItems: miscItemChanges
|
||||
}
|
||||
};
|
||||
if (ExportResources[typeName].productCategory == "Ships") {
|
||||
const oid = await createShip(new Types.ObjectId(accountId), typeName);
|
||||
inventory.Ships.push(oid);
|
||||
await inventory.save();
|
||||
return {
|
||||
InventoryChanges: {
|
||||
Ships: [
|
||||
{
|
||||
ItemId: { $oid: oid },
|
||||
ItemType: typeName
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
} else {
|
||||
const miscItemChanges = [
|
||||
{
|
||||
ItemType: typeName,
|
||||
ItemCount: quantity
|
||||
} satisfies IMiscItem
|
||||
];
|
||||
addMiscItems(inventory, miscItemChanges);
|
||||
await inventory.save();
|
||||
return {
|
||||
InventoryChanges: {
|
||||
MiscItems: miscItemChanges
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
if (typeName in ExportCustoms) {
|
||||
return {
|
||||
|
@ -2,7 +2,6 @@ import { getPersonalRooms } from "@/src/services/personalRoomsService";
|
||||
import { getShip } from "@/src/services/shipService";
|
||||
import {
|
||||
ISetShipCustomizationsRequest,
|
||||
IShipDatabase,
|
||||
IShipDecorationsRequest,
|
||||
IShipDecorationsResponse,
|
||||
ISetPlacedDecoInfoRequest
|
||||
@ -10,25 +9,26 @@ import {
|
||||
import { logger } from "@/src/utils/logger";
|
||||
import { Types } from "mongoose";
|
||||
|
||||
export const setShipCustomizations = async (shipCustomization: ISetShipCustomizationsRequest) => {
|
||||
const ship = await getShip(new Types.ObjectId(shipCustomization.ShipId));
|
||||
|
||||
let shipChanges: Partial<IShipDatabase>;
|
||||
export const setShipCustomizations = async (
|
||||
accountId: string,
|
||||
shipCustomization: ISetShipCustomizationsRequest
|
||||
): Promise<void> => {
|
||||
if (shipCustomization.IsExterior) {
|
||||
shipChanges = {
|
||||
ShipExteriorColors: shipCustomization.Customization.Colors,
|
||||
SkinFlavourItem: shipCustomization.Customization.SkinFlavourItem,
|
||||
ShipAttachments: shipCustomization.Customization.ShipAttachments,
|
||||
AirSupportPower: shipCustomization.AirSupportPower!
|
||||
};
|
||||
const ship = await getShip(new Types.ObjectId(shipCustomization.ShipId));
|
||||
if (ship.ShipOwnerId.toString() == accountId) {
|
||||
ship.set({
|
||||
ShipExteriorColors: shipCustomization.Customization.Colors,
|
||||
SkinFlavourItem: shipCustomization.Customization.SkinFlavourItem,
|
||||
ShipAttachments: shipCustomization.Customization.ShipAttachments,
|
||||
AirSupportPower: shipCustomization.AirSupportPower!
|
||||
});
|
||||
await ship.save();
|
||||
}
|
||||
} else {
|
||||
shipChanges = {
|
||||
ShipInteriorColors: shipCustomization.Customization.Colors
|
||||
};
|
||||
const personalRooms = await getPersonalRooms(accountId);
|
||||
personalRooms.ShipInteriorColors = shipCustomization.Customization.Colors;
|
||||
await personalRooms.save();
|
||||
}
|
||||
ship.set(shipChanges);
|
||||
|
||||
await ship.save();
|
||||
};
|
||||
|
||||
export const handleSetShipDecorations = async (
|
||||
|
@ -3,10 +3,13 @@ import { ILoadoutDatabase } from "@/src/types/saveLoadoutTypes";
|
||||
import { logger } from "@/src/utils/logger";
|
||||
import { Types } from "mongoose";
|
||||
|
||||
export const createShip = async (accountOwnerId: Types.ObjectId) => {
|
||||
export const createShip = async (
|
||||
accountOwnerId: Types.ObjectId,
|
||||
typeName: string = "/Lotus/Types/Items/Ships/DefaultShip"
|
||||
) => {
|
||||
try {
|
||||
const ship = new Ship({
|
||||
ItemType: "/Lotus/Types/Items/Ships/DefaultShip",
|
||||
ItemType: typeName,
|
||||
ShipOwnerId: accountOwnerId
|
||||
});
|
||||
const newShip = await ship.save();
|
||||
@ -23,8 +26,8 @@ export const getShip = async (shipId: Types.ObjectId, fieldSelection: string = "
|
||||
const ship = await Ship.findOne({ _id: shipId }, fieldSelection);
|
||||
|
||||
if (!ship) {
|
||||
logger.error(`error finding a ship for account ${shipId}`);
|
||||
throw new Error(`error finding a ship for account ${shipId}`);
|
||||
logger.error(`error finding a ship with id ${shipId}`);
|
||||
throw new Error(`error finding a ship with id ${shipId}`);
|
||||
}
|
||||
|
||||
return ship;
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { IColor } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
||||
import {
|
||||
IApartment,
|
||||
IRoom,
|
||||
@ -16,12 +17,14 @@ export interface IOrbiter {
|
||||
}
|
||||
|
||||
export interface IPersonalRooms {
|
||||
ShipInteriorColors: IColor;
|
||||
Ship: IOrbiter;
|
||||
Apartment: IApartment;
|
||||
TailorShop: ITailorShop;
|
||||
}
|
||||
|
||||
export interface IPersonalRoomsDatabase {
|
||||
ShipInteriorColors: IColor;
|
||||
personalRoomsOwnerId: Types.ObjectId;
|
||||
activeShipId: Types.ObjectId;
|
||||
Ship: IOrbiter;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Schema, Types } from "mongoose";
|
||||
import { Types } from "mongoose";
|
||||
import { IOid } from "@/src/types/commonTypes";
|
||||
import { IColor } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
||||
import { ILoadoutClient } from "./saveLoadoutTypes";
|
||||
@ -34,8 +34,7 @@ export interface IShip {
|
||||
|
||||
export interface IShipDatabase {
|
||||
ItemType: string;
|
||||
ShipOwnerId: Schema.Types.ObjectId;
|
||||
ShipInteriorColors?: IColor;
|
||||
ShipOwnerId: Types.ObjectId;
|
||||
ShipExteriorColors?: IColor;
|
||||
AirSupportPower: string;
|
||||
ShipAttachments?: IShipAttachments;
|
||||
|
@ -1,32 +0,0 @@
|
||||
{
|
||||
"ShipOwnerId": "647bce8a1caba352f90b6a09",
|
||||
"Ship": {
|
||||
"Rooms": [
|
||||
{ "Name": "AlchemyRoom", "MaxCapacity": 1600 },
|
||||
{ "Name": "BridgeRoom", "MaxCapacity": 1600 },
|
||||
{ "Name": "LisetRoom", "MaxCapacity": 1000 },
|
||||
{ "Name": "OperatorChamberRoom", "MaxCapacity": 1600 },
|
||||
{ "Name": "OutsideRoom", "MaxCapacity": 1600 },
|
||||
{ "Name": "PersonalQuartersRoom", "MaxCapacity": 1600 }
|
||||
],
|
||||
"ContentUrlSignature": "removed",
|
||||
"Features": [
|
||||
"/Lotus/Types/Items/ShipFeatureItems/EarthNavigationFeatureItem",
|
||||
"/Lotus/Types/Items/ShipFeatureItems/ArsenalFeatureItem",
|
||||
"/Lotus/Types/Items/ShipFeatureItems/SocialMenuFeatureItem",
|
||||
"/Lotus/Types/Items/ShipFeatureItems/ModsFeatureItem",
|
||||
"/Lotus/Types/Items/ShipFeatureItems/FoundryFeatureItem",
|
||||
"/Lotus/Types/Items/ShipFeatureItems/MercuryNavigationFeatureItem"
|
||||
]
|
||||
},
|
||||
"Apartment": {
|
||||
"Rooms": [
|
||||
{ "Name": "ElevatorLanding", "MaxCapacity": 1600 },
|
||||
{ "Name": "ApartmentRoomA", "MaxCapacity": 1000 },
|
||||
{ "Name": "ApartmentRoomB", "MaxCapacity": 1600 },
|
||||
{ "Name": "ApartmentRoomC", "MaxCapacity": 1600 },
|
||||
{ "Name": "DuviriHallway", "MaxCapacity": 1600 }
|
||||
],
|
||||
"FavouriteLoadouts": []
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user
🛠️ Refactor suggestion
Return type mismatch
setShipCustomizations now returns void, so setShipCustomizationsResponse will always be undefined. Consider removing the variable assignment or updating setShipCustomizations to return meaningful data.
Well, it already returned void before, so, meh.
@Sainan, understood! Thanks for clarifying your stance on it.
┌(・。・)┘♪ … ┋(ノ﹏ヽ) … ┋( •_•)>⌐□-□ … ┋(╯︵╰,) … ┋ … ┋ … ┋ … ┋ … ┋ … ┋
(…the rabbit appears a bit sad as its suggestion was turned down…)