SpaceNinjaServer/src/controllers/api/getShipController.ts

26 lines
861 B
TypeScript
Raw Normal View History

2023-06-05 01:22:52 +08:00
import { Account } from "@/src/models/loginModel";
import { Ship } from "@/src/models/shipModel";
2023-06-05 03:13:46 +08:00
2023-06-05 01:22:52 +08:00
import { createShip } from "@/src/services/shipService";
2023-06-05 03:13:46 +08:00
import config from "@/config.json";
import testShipFeature from "@/static/fixed_responses/testShipFeature.json";
2023-05-19 15:22:48 -03:00
2023-06-05 01:22:52 +08:00
// eslint-disable-next-line @typescript-eslint/no-misused-promises
const getShipController: RequestHandler = async (_req, res) => {
const accountId = _req.query.accountId;
const ship = await Ship.findOne({ ShipOwnerId: accountId });
if (!ship) {
const account = await Account.findOne({ _id: accountId });
if (account) {
await createShip(account._id);
const new_ship = await Ship.findOne({ ShipOwnerId: accountId });
res.json(new_ship);
return;
}
}
res.json(ship);
2023-05-19 15:22:48 -03:00
};
export { getShipController };