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 },
|
||||||
|
@ -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,27 @@ 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> => {
|
||||||
|
console.log(shipCustomization);
|
||||||
if (shipCustomization.IsExterior) {
|
if (shipCustomization.IsExterior) {
|
||||||
shipChanges = {
|
const ship = await getShip(new Types.ObjectId(shipCustomization.ShipId));
|
||||||
ShipExteriorColors: shipCustomization.Customization.Colors,
|
if (ship.ShipOwnerId.toString() == accountId) {
|
||||||
SkinFlavourItem: shipCustomization.Customization.SkinFlavourItem,
|
ship.set({
|
||||||
ShipAttachments: shipCustomization.Customization.ShipAttachments,
|
ShipExteriorColors: shipCustomization.Customization.Colors,
|
||||||
AirSupportPower: shipCustomization.AirSupportPower!
|
SkinFlavourItem: shipCustomization.Customization.SkinFlavourItem,
|
||||||
};
|
ShipAttachments: shipCustomization.Customization.ShipAttachments,
|
||||||
|
AirSupportPower: shipCustomization.AirSupportPower!
|
||||||
|
});
|
||||||
|
await ship.save();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
shipChanges = {
|
const personalRooms = await getPersonalRooms(accountId);
|
||||||
ShipInteriorColors: shipCustomization.Customization.Colors
|
personalRooms.ShipInteriorColors = shipCustomization.Customization.Colors;
|
||||||
};
|
await personalRooms.save();
|
||||||
}
|
}
|
||||||
ship.set(shipChanges);
|
|
||||||
|
|
||||||
await ship.save();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const handleSetShipDecorations = async (
|
export const handleSetShipDecorations = async (
|
||||||
|
@ -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;
|
||||||
|
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…)