fix: acquiring ships #619
@ -15,7 +15,7 @@ export const getShipController: RequestHandler = async (req, res) => {
|
|||||||
const personalRoomsDb = await getPersonalRooms(accountId);
|
const personalRoomsDb = await getPersonalRooms(accountId);
|
||||||
const personalRooms = personalRoomsDb.toJSON<IPersonalRooms>();
|
const personalRooms = personalRoomsDb.toJSON<IPersonalRooms>();
|
||||||
const loadout = await getLoadout(accountId);
|
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 = {
|
const getShipResponse: IGetShipResponse = {
|
||||||
ShipOwnerId: accountId,
|
ShipOwnerId: accountId,
|
||||||
@ -24,7 +24,7 @@ export const getShipController: RequestHandler = async (req, res) => {
|
|||||||
...personalRooms.Ship,
|
...personalRooms.Ship,
|
||||||
ShipId: toOid(personalRoomsDb.activeShipId),
|
ShipId: toOid(personalRoomsDb.activeShipId),
|
||||||
ShipInterior: {
|
ShipInterior: {
|
||||||
Colors: ship.ShipInteriorColors,
|
Colors: personalRooms.ShipInteriorColors,
|
||||||
ShipAttachments: ship.ShipAttachments,
|
ShipAttachments: ship.ShipAttachments,
|
||||||
SkinFlavourItem: ship.SkinFlavourItem
|
SkinFlavourItem: ship.SkinFlavourItem
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ const inventoryController: RequestHandler = async (request, response) => {
|
|||||||
|
|
||||||
const inventory = await Inventory.findOne({ accountOwnerId: account._id.toString() })
|
const inventory = await Inventory.findOne({ accountOwnerId: account._id.toString() })
|
||||||
.populate<{ LoadOutPresets: ILoadoutDatabase }>("LoadOutPresets")
|
.populate<{ LoadOutPresets: ILoadoutDatabase }>("LoadOutPresets")
|
||||||
.populate<{ Ships: IShipInventory }>("Ships", "-ShipInteriorColors");
|
.populate<{ Ships: IShipInventory }>("Ships");
|
||||||
|
|
||||||
if (!inventory) {
|
if (!inventory) {
|
||||||
response.status(400).json({ error: "inventory was undefined" });
|
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 { setShipCustomizations } from "@/src/services/shipCustomizationsService";
|
||||||
import { ISetShipCustomizationsRequest } from "@/src/types/shipTypes";
|
import { ISetShipCustomizationsRequest } from "@/src/types/shipTypes";
|
||||||
import { logger } from "@/src/utils/logger";
|
import { logger } from "@/src/utils/logger";
|
||||||
@ -5,9 +6,10 @@ import { RequestHandler } from "express";
|
|||||||
|
|
||||||
export const setShipCustomizationsController: RequestHandler = async (req, res) => {
|
export const setShipCustomizationsController: RequestHandler = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
const accountId = await getAccountIdForRequest(req);
|
||||||
const setShipCustomizationsRequest = JSON.parse(req.body as string) as ISetShipCustomizationsRequest;
|
const setShipCustomizationsRequest = JSON.parse(req.body as string) as ISetShipCustomizationsRequest;
|
||||||
|
|
||||||
const setShipCustomizationsResponse = await setShipCustomizations(setShipCustomizationsRequest);
|
const setShipCustomizationsResponse = await setShipCustomizations(accountId, setShipCustomizationsRequest);
|
||||||
res.json(setShipCustomizationsResponse);
|
res.json(setShipCustomizationsResponse);
|
||||||
|
|||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { toOid } from "@/src/helpers/inventoryHelpers";
|
import { toOid } from "@/src/helpers/inventoryHelpers";
|
||||||
|
import { colorSchema } from "@/src/models/inventoryModels/inventoryModel";
|
||||||
import { IOrbiter, IPersonalRoomsDatabase, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes";
|
import { IOrbiter, IPersonalRoomsDatabase, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes";
|
||||||
import {
|
import {
|
||||||
IApartment,
|
IApartment,
|
||||||
@ -131,6 +132,7 @@ const tailorShopDefault: ITailorShopDatabase = {
|
|||||||
export const personalRoomsSchema = new Schema<IPersonalRoomsDatabase>({
|
export const personalRoomsSchema = new Schema<IPersonalRoomsDatabase>({
|
||||||
personalRoomsOwnerId: Schema.Types.ObjectId,
|
personalRoomsOwnerId: Schema.Types.ObjectId,
|
||||||
activeShipId: Schema.Types.ObjectId,
|
activeShipId: Schema.Types.ObjectId,
|
||||||
|
ShipInteriorColors: colorSchema,
|
||||||
Ship: orbiterSchema,
|
Ship: orbiterSchema,
|
||||||
Apartment: apartmentSchema,
|
Apartment: apartmentSchema,
|
||||||
TailorShop: { type: tailorShopSchema, default: tailorShopDefault }
|
TailorShop: { type: tailorShopSchema, default: tailorShopDefault }
|
||||||
|
@ -8,7 +8,6 @@ const shipSchema = new Schema<IShipDatabase>(
|
|||||||
{
|
{
|
||||||
ItemType: String,
|
ItemType: String,
|
||||||
ShipOwnerId: Schema.Types.ObjectId,
|
ShipOwnerId: Schema.Types.ObjectId,
|
||||||
ShipInteriorColors: colorSchema,
|
|
||||||
ShipExteriorColors: colorSchema,
|
ShipExteriorColors: colorSchema,
|
||||||
AirSupportPower: String,
|
AirSupportPower: String,
|
||||||
ShipAttachments: { HOOD_ORNAMENT: String },
|
ShipAttachments: { HOOD_ORNAMENT: String },
|
||||||
|
@ -41,6 +41,7 @@ import {
|
|||||||
ExportResources,
|
ExportResources,
|
||||||
ExportUpgrades
|
ExportUpgrades
|
||||||
} from "warframe-public-export-plus";
|
} from "warframe-public-export-plus";
|
||||||
|
import { createShip } from "./shipService";
|
||||||
|
|
||||||
export const createInventory = async (
|
export const createInventory = async (
|
||||||
accountOwnerId: Types.ObjectId,
|
accountOwnerId: Types.ObjectId,
|
||||||
@ -129,6 +130,21 @@ export const addItem = async (
|
|||||||
}
|
}
|
||||||
if (typeName in ExportResources) {
|
if (typeName in ExportResources) {
|
||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId);
|
||||||
|
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 = [
|
const miscItemChanges = [
|
||||||
{
|
{
|
||||||
ItemType: typeName,
|
ItemType: typeName,
|
||||||
@ -143,6 +159,7 @@ export const addItem = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (typeName in ExportCustoms) {
|
if (typeName in ExportCustoms) {
|
||||||
return {
|
return {
|
||||||
InventoryChanges: {
|
InventoryChanges: {
|
||||||
|
@ -2,7 +2,6 @@ import { getPersonalRooms } from "@/src/services/personalRoomsService";
|
|||||||
import { getShip } from "@/src/services/shipService";
|
import { getShip } from "@/src/services/shipService";
|
||||||
import {
|
import {
|
||||||
ISetShipCustomizationsRequest,
|
ISetShipCustomizationsRequest,
|
||||||
IShipDatabase,
|
|
||||||
IShipDecorationsRequest,
|
IShipDecorationsRequest,
|
||||||
IShipDecorationsResponse,
|
IShipDecorationsResponse,
|
||||||
ISetPlacedDecoInfoRequest
|
ISetPlacedDecoInfoRequest
|
||||||
@ -10,25 +9,26 @@ import {
|
|||||||
import { logger } from "@/src/utils/logger";
|
import { logger } from "@/src/utils/logger";
|
||||||
import { Types } from "mongoose";
|
import { Types } from "mongoose";
|
||||||
|
|
||||||
export const setShipCustomizations = async (shipCustomization: ISetShipCustomizationsRequest) => {
|
export const setShipCustomizations = async (
|
||||||
const ship = await getShip(new Types.ObjectId(shipCustomization.ShipId));
|
accountId: string,
|
||||||
|
shipCustomization: ISetShipCustomizationsRequest
|
||||||
let shipChanges: Partial<IShipDatabase>;
|
): Promise<void> => {
|
||||||
if (shipCustomization.IsExterior) {
|
if (shipCustomization.IsExterior) {
|
||||||
shipChanges = {
|
const ship = await getShip(new Types.ObjectId(shipCustomization.ShipId));
|
||||||
|
if (ship.ShipOwnerId.toString() == accountId) {
|
||||||
|
ship.set({
|
||||||
ShipExteriorColors: shipCustomization.Customization.Colors,
|
ShipExteriorColors: shipCustomization.Customization.Colors,
|
||||||
SkinFlavourItem: shipCustomization.Customization.SkinFlavourItem,
|
SkinFlavourItem: shipCustomization.Customization.SkinFlavourItem,
|
||||||
ShipAttachments: shipCustomization.Customization.ShipAttachments,
|
ShipAttachments: shipCustomization.Customization.ShipAttachments,
|
||||||
AirSupportPower: shipCustomization.AirSupportPower!
|
AirSupportPower: shipCustomization.AirSupportPower!
|
||||||
};
|
});
|
||||||
} else {
|
|
||||||
shipChanges = {
|
|
||||||
ShipInteriorColors: shipCustomization.Customization.Colors
|
|
||||||
};
|
|
||||||
}
|
|
||||||
ship.set(shipChanges);
|
|
||||||
|
|
||||||
await ship.save();
|
await ship.save();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const personalRooms = await getPersonalRooms(accountId);
|
||||||
|
personalRooms.ShipInteriorColors = shipCustomization.Customization.Colors;
|
||||||
|
await personalRooms.save();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const handleSetShipDecorations = async (
|
export const handleSetShipDecorations = async (
|
||||||
|
@ -3,10 +3,13 @@ import { ILoadoutDatabase } from "@/src/types/saveLoadoutTypes";
|
|||||||
import { logger } from "@/src/utils/logger";
|
import { logger } from "@/src/utils/logger";
|
||||||
import { Types } from "mongoose";
|
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 {
|
try {
|
||||||
const ship = new Ship({
|
const ship = new Ship({
|
||||||
ItemType: "/Lotus/Types/Items/Ships/DefaultShip",
|
ItemType: typeName,
|
||||||
ShipOwnerId: accountOwnerId
|
ShipOwnerId: accountOwnerId
|
||||||
});
|
});
|
||||||
const newShip = await ship.save();
|
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);
|
const ship = await Ship.findOne({ _id: shipId }, fieldSelection);
|
||||||
|
|
||||||
if (!ship) {
|
if (!ship) {
|
||||||
logger.error(`error finding a ship for account ${shipId}`);
|
logger.error(`error finding a ship with id ${shipId}`);
|
||||||
throw new Error(`error finding a ship for account ${shipId}`);
|
throw new Error(`error finding a ship with id ${shipId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ship;
|
return ship;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { IColor } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
||||||
import {
|
import {
|
||||||
IApartment,
|
IApartment,
|
||||||
IRoom,
|
IRoom,
|
||||||
@ -16,12 +17,14 @@ export interface IOrbiter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IPersonalRooms {
|
export interface IPersonalRooms {
|
||||||
|
ShipInteriorColors: IColor;
|
||||||
Ship: IOrbiter;
|
Ship: IOrbiter;
|
||||||
Apartment: IApartment;
|
Apartment: IApartment;
|
||||||
TailorShop: ITailorShop;
|
TailorShop: ITailorShop;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IPersonalRoomsDatabase {
|
export interface IPersonalRoomsDatabase {
|
||||||
|
ShipInteriorColors: IColor;
|
||||||
personalRoomsOwnerId: Types.ObjectId;
|
personalRoomsOwnerId: Types.ObjectId;
|
||||||
activeShipId: Types.ObjectId;
|
activeShipId: Types.ObjectId;
|
||||||
Ship: IOrbiter;
|
Ship: IOrbiter;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Schema, Types } from "mongoose";
|
import { Types } from "mongoose";
|
||||||
import { IOid } from "@/src/types/commonTypes";
|
import { IOid } from "@/src/types/commonTypes";
|
||||||
import { IColor } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
import { IColor } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
||||||
import { ILoadoutClient } from "./saveLoadoutTypes";
|
import { ILoadoutClient } from "./saveLoadoutTypes";
|
||||||
@ -34,8 +34,7 @@ export interface IShip {
|
|||||||
|
|
||||||
export interface IShipDatabase {
|
export interface IShipDatabase {
|
||||||
ItemType: string;
|
ItemType: string;
|
||||||
ShipOwnerId: Schema.Types.ObjectId;
|
ShipOwnerId: Types.ObjectId;
|
||||||
ShipInteriorColors?: IColor;
|
|
||||||
ShipExteriorColors?: IColor;
|
ShipExteriorColors?: IColor;
|
||||||
AirSupportPower: string;
|
AirSupportPower: string;
|
||||||
ShipAttachments?: IShipAttachments;
|
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…)