chore: remove setShipCustomizations
This commit is contained in:
parent
fb8e19403e
commit
52e95fd79d
@ -1,20 +1,35 @@
|
|||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
|
||||||
import { setShipCustomizations } from "@/src/services/shipCustomizationsService";
|
|
||||||
import { ISetShipCustomizationsRequest } from "@/src/types/shipTypes";
|
|
||||||
import { logger } from "@/src/utils/logger";
|
|
||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||||
|
import { getShip } from "@/src/services/shipService";
|
||||||
|
import { getPersonalRooms } from "@/src/services/personalRoomsService";
|
||||||
|
import { Types } from "mongoose";
|
||||||
|
import { Customization } from "@/src/types/shipTypes";
|
||||||
|
|
||||||
export const setShipCustomizationsController: RequestHandler = async (req, res) => {
|
export const setShipCustomizationsController: RequestHandler = async (req, res) => {
|
||||||
try {
|
const accountId = await getAccountIdForRequest(req);
|
||||||
const accountId = await getAccountIdForRequest(req);
|
const shipCustomization = JSON.parse(req.body as string) as ISetShipCustomizationsRequest;
|
||||||
const setShipCustomizationsRequest = JSON.parse(req.body as string) as ISetShipCustomizationsRequest;
|
if (shipCustomization.IsExterior) {
|
||||||
|
const ship = await getShip(new Types.ObjectId(shipCustomization.ShipId));
|
||||||
const setShipCustomizationsResponse = await setShipCustomizations(accountId, setShipCustomizationsRequest);
|
if (ship.ShipOwnerId.toString() == accountId) {
|
||||||
res.json(setShipCustomizationsResponse);
|
ship.set({
|
||||||
} catch (error: unknown) {
|
ShipExteriorColors: shipCustomization.Customization.Colors,
|
||||||
if (error instanceof Error) {
|
SkinFlavourItem: shipCustomization.Customization.SkinFlavourItem,
|
||||||
logger.error(`error in setShipCustomizationsController: ${error.message}`);
|
ShipAttachments: shipCustomization.Customization.ShipAttachments,
|
||||||
res.status(400).json({ error: error.message });
|
AirSupportPower: shipCustomization.AirSupportPower!
|
||||||
|
});
|
||||||
|
await ship.save();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
const personalRooms = await getPersonalRooms(accountId);
|
||||||
|
personalRooms.ShipInteriorColors = shipCustomization.Customization.Colors;
|
||||||
|
await personalRooms.save();
|
||||||
}
|
}
|
||||||
|
res.end();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface ISetShipCustomizationsRequest {
|
||||||
|
ShipId: string;
|
||||||
|
Customization: Customization;
|
||||||
|
IsExterior: boolean;
|
||||||
|
AirSupportPower?: string;
|
||||||
|
}
|
||||||
|
@ -1,36 +1,8 @@
|
|||||||
import { getPersonalRooms } from "@/src/services/personalRoomsService";
|
import { getPersonalRooms } from "@/src/services/personalRoomsService";
|
||||||
import { getShip } from "@/src/services/shipService";
|
import { IShipDecorationsRequest, IShipDecorationsResponse, ISetPlacedDecoInfoRequest } from "@/src/types/shipTypes";
|
||||||
import {
|
|
||||||
ISetShipCustomizationsRequest,
|
|
||||||
IShipDecorationsRequest,
|
|
||||||
IShipDecorationsResponse,
|
|
||||||
ISetPlacedDecoInfoRequest
|
|
||||||
} from "@/src/types/shipTypes";
|
|
||||||
import { logger } from "@/src/utils/logger";
|
import { logger } from "@/src/utils/logger";
|
||||||
import { Types } from "mongoose";
|
import { Types } from "mongoose";
|
||||||
|
|
||||||
export const setShipCustomizations = async (
|
|
||||||
accountId: string,
|
|
||||||
shipCustomization: ISetShipCustomizationsRequest
|
|
||||||
): Promise<void> => {
|
|
||||||
if (shipCustomization.IsExterior) {
|
|
||||||
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 {
|
|
||||||
const personalRooms = await getPersonalRooms(accountId);
|
|
||||||
personalRooms.ShipInteriorColors = shipCustomization.Customization.Colors;
|
|
||||||
await personalRooms.save();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const handleSetShipDecorations = async (
|
export const handleSetShipDecorations = async (
|
||||||
accountId: string,
|
accountId: string,
|
||||||
placedDecoration: IShipDecorationsRequest
|
placedDecoration: IShipDecorationsRequest
|
||||||
|
@ -79,13 +79,6 @@ export interface IPlacedDecosClient extends Omit<IPlacedDecosDatabase, "_id"> {
|
|||||||
id: IOid;
|
id: IOid;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISetShipCustomizationsRequest {
|
|
||||||
ShipId: string;
|
|
||||||
Customization: Customization;
|
|
||||||
IsExterior: boolean;
|
|
||||||
AirSupportPower?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Customization {
|
export interface Customization {
|
||||||
SkinFlavourItem: string;
|
SkinFlavourItem: string;
|
||||||
Colors: IColor;
|
Colors: IColor;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user