forked from OpenWF/SpaceNinjaServer
		
	fix: handle setPlacedDecoInfo for non-ship boot locations (#2349)
Closes #2347 Reviewed-on: OpenWF/SpaceNinjaServer#2349 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									d66f1c58d8
								
							
						
					
					
						commit
						69f9d5ebc5
					
				@ -4,7 +4,8 @@ import {
 | 
				
			|||||||
    ISetShipCustomizationsRequest,
 | 
					    ISetShipCustomizationsRequest,
 | 
				
			||||||
    IShipDecorationsRequest,
 | 
					    IShipDecorationsRequest,
 | 
				
			||||||
    IShipDecorationsResponse,
 | 
					    IShipDecorationsResponse,
 | 
				
			||||||
    ISetPlacedDecoInfoRequest
 | 
					    ISetPlacedDecoInfoRequest,
 | 
				
			||||||
 | 
					    TBootLocation
 | 
				
			||||||
} from "@/src/types/shipTypes";
 | 
					} from "@/src/types/shipTypes";
 | 
				
			||||||
import { logger } from "@/src/utils/logger";
 | 
					import { logger } from "@/src/utils/logger";
 | 
				
			||||||
import { Types } from "mongoose";
 | 
					import { Types } from "mongoose";
 | 
				
			||||||
@ -14,6 +15,7 @@ import { Guild } from "../models/guildModel";
 | 
				
			|||||||
import { hasGuildPermission } from "./guildService";
 | 
					import { hasGuildPermission } from "./guildService";
 | 
				
			||||||
import { GuildPermission } from "../types/guildTypes";
 | 
					import { GuildPermission } from "../types/guildTypes";
 | 
				
			||||||
import { ExportResources } from "warframe-public-export-plus";
 | 
					import { ExportResources } from "warframe-public-export-plus";
 | 
				
			||||||
 | 
					import { RoomsType, TPersonalRoomsDatabaseDocument } from "../types/personalRoomsTypes";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const setShipCustomizations = async (
 | 
					export const setShipCustomizations = async (
 | 
				
			||||||
    accountId: string,
 | 
					    accountId: string,
 | 
				
			||||||
@ -183,6 +185,19 @@ export const handleSetShipDecorations = async (
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const getRoomsForBootLocation = (
 | 
				
			||||||
 | 
					    personalRooms: TPersonalRoomsDatabaseDocument,
 | 
				
			||||||
 | 
					    bootLocation: TBootLocation | undefined
 | 
				
			||||||
 | 
					): RoomsType[] => {
 | 
				
			||||||
 | 
					    if (bootLocation == "SHOP") {
 | 
				
			||||||
 | 
					        return personalRooms.TailorShop.Rooms;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (bootLocation == "APARTMENT") {
 | 
				
			||||||
 | 
					        return personalRooms.Apartment.Rooms;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return personalRooms.Ship.Rooms;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const handleSetPlacedDecoInfo = async (accountId: string, req: ISetPlacedDecoInfoRequest): Promise<void> => {
 | 
					export const handleSetPlacedDecoInfo = async (accountId: string, req: ISetPlacedDecoInfoRequest): Promise<void> => {
 | 
				
			||||||
    if (req.GuildId && req.ComponentId) {
 | 
					    if (req.GuildId && req.ComponentId) {
 | 
				
			||||||
        const guild = (await Guild.findById(req.GuildId))!;
 | 
					        const guild = (await Guild.findById(req.GuildId))!;
 | 
				
			||||||
@ -197,14 +212,14 @@ export const handleSetPlacedDecoInfo = async (accountId: string, req: ISetPlaced
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const personalRooms = await getPersonalRooms(accountId);
 | 
					    const personalRooms = await getPersonalRooms(accountId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const room = personalRooms.Ship.Rooms.find(room => room.Name === req.Room);
 | 
					    const room = getRoomsForBootLocation(personalRooms, req.BootLocation).find(room => room.Name === req.Room);
 | 
				
			||||||
    if (!room) {
 | 
					    if (!room) {
 | 
				
			||||||
        throw new Error("room not found");
 | 
					        throw new Error(`unknown room: ${req.Room}`);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const placedDeco = room.PlacedDecos.id(req.DecoId);
 | 
					    const placedDeco = room.PlacedDecos.id(req.DecoId);
 | 
				
			||||||
    if (!placedDeco) {
 | 
					    if (!placedDeco) {
 | 
				
			||||||
        throw new Error("deco not found");
 | 
					        throw new Error(`unknown deco id: ${req.DecoId}`);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    placedDeco.PictureFrameInfo = req.PictureFrameInfo;
 | 
					    placedDeco.PictureFrameInfo = req.PictureFrameInfo;
 | 
				
			||||||
 | 
				
			|||||||
@ -154,7 +154,7 @@ export interface ISetPlacedDecoInfoRequest {
 | 
				
			|||||||
    DecoId: string;
 | 
					    DecoId: string;
 | 
				
			||||||
    Room: string;
 | 
					    Room: string;
 | 
				
			||||||
    PictureFrameInfo: IPictureFrameInfo;
 | 
					    PictureFrameInfo: IPictureFrameInfo;
 | 
				
			||||||
    BootLocation?: string;
 | 
					    BootLocation?: TBootLocation;
 | 
				
			||||||
    ComponentId?: string;
 | 
					    ComponentId?: string;
 | 
				
			||||||
    GuildId?: string;
 | 
					    GuildId?: string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user