SpaceNinjaServer/src/services/shipService.ts

22 lines
689 B
TypeScript
Raw Normal View History

2023-06-05 04:16:49 +08:00
import { Ship } from "@/src/models/shipModel";
2023-06-05 00:17:01 +02:00
import new_ship from "@/static/fixed_responses/ship.json";
2023-06-05 04:16:49 +08:00
import { Types } from "mongoose";
const createShip = async (accountOwnerId: Types.ObjectId, loadoutId: Types.ObjectId) => {
2023-06-05 04:16:49 +08:00
try {
const ship = new Ship({
...new_ship,
ShipOwnerId: accountOwnerId,
LoadOutInventory: { LoadOutPresets: loadoutId }
});
2023-06-05 04:16:49 +08:00
await ship.save();
} catch (error) {
if (error instanceof Error) {
2023-06-05 00:17:01 +02:00
throw new Error(`error creating ship" ${error.message}`);
2023-06-05 04:16:49 +08:00
}
2023-06-05 00:17:01 +02:00
throw new Error("error creating ship that is not of instance Error");
2023-06-05 04:16:49 +08:00
}
};
export { createShip };