SpaceNinjaServer/src/services/shipService.ts
Sainan 2ec2b0278a
All checks were successful
Build / build (20) (push) Successful in 51s
Build / build (18) (push) Successful in 1m14s
Build / build (22) (push) Successful in 1m24s
Build Docker image / docker (push) Successful in 41s
chore: use model.findById where possible (#1315)
Reviewed-on: #1315
2025-03-24 11:32:08 -07:00

32 lines
999 B
TypeScript

import { Ship, TShipDatabaseDocument } from "@/src/models/shipModel";
import { 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;
};