forked from OpenWF/SpaceNinjaServer
		
	Reviewed-on: OpenWF/SpaceNinjaServer#2694 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
		
			
				
	
	
		
			33 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import type { TShipDatabaseDocument } from "../models/shipModel.ts";
 | 
						|
import { Ship } from "../models/shipModel.ts";
 | 
						|
import type { Types } from "mongoose";
 | 
						|
 | 
						|
export const createShip = async (
 | 
						|
    accountOwnerId: Types.ObjectId,
 | 
						|
    typeName: string = "/Lotus/Types/Items/Ships/DefaultShip"
 | 
						|
): Promise<Types.ObjectId> => {
 | 
						|
    try {
 | 
						|
        const ship = new Ship({
 | 
						|
            ItemType: typeName,
 | 
						|
            ShipOwnerId: accountOwnerId
 | 
						|
        });
 | 
						|
        const newShip = await ship.save();
 | 
						|
        return newShip._id;
 | 
						|
    } catch (error) {
 | 
						|
        if (error instanceof Error) {
 | 
						|
            throw new Error(`error creating ship" ${error.message}`);
 | 
						|
        }
 | 
						|
        throw new Error("error creating ship that is not of instance Error");
 | 
						|
    }
 | 
						|
};
 | 
						|
 | 
						|
export const getShip = async (shipId: Types.ObjectId, fieldSelection: string = ""): Promise<TShipDatabaseDocument> => {
 | 
						|
    const ship = await Ship.findById(shipId, fieldSelection);
 | 
						|
 | 
						|
    if (!ship) {
 | 
						|
        throw new Error(`error finding a ship with id ${shipId.toString()}`);
 | 
						|
    }
 | 
						|
 | 
						|
    return ship;
 | 
						|
};
 |