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";
|
|
|
|
|
2023-12-14 17:34:15 +01:00
|
|
|
const createShip = async (accountOwnerId: Types.ObjectId, loadoutId: Types.ObjectId) => {
|
2023-06-05 04:16:49 +08:00
|
|
|
try {
|
2023-12-14 17:34:15 +01:00
|
|
|
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 };
|