SpaceNinjaServer/src/services/shipService.ts
OrdisPrime dd99e8782c
saveLoadout and misc. (#99)
Co-authored-by: Matej Voboril <tobiah@pm.me>
2023-12-14 17:34:15 +01:00

22 lines
689 B
TypeScript

import { Ship } from "@/src/models/shipModel";
import new_ship from "@/static/fixed_responses/ship.json";
import { Types } from "mongoose";
const createShip = async (accountOwnerId: Types.ObjectId, loadoutId: Types.ObjectId) => {
try {
const ship = new Ship({
...new_ship,
ShipOwnerId: accountOwnerId,
LoadOutInventory: { LoadOutPresets: loadoutId }
});
await ship.save();
} 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 { createShip };