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 },
|
||||
|
@ -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,27 @@ 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> => {
|
||||
console.log(shipCustomization);
|
||||
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 (
|
||||
|
@ -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;
|
||||
|
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…)