SpaceNinjaServer/src/controllers/api/getShipController.ts

40 lines
1.7 KiB
TypeScript
Raw Normal View History

import type { RequestHandler } from "express";
import { config } from "../../services/configService.ts";
2025-08-25 22:40:52 +02:00
import allShipFeatures from "../../../static/fixed_responses/allShipFeatures.json" with { type: "json" };
import { getAccountIdForRequest } from "../../services/loginService.ts";
import { createGarden, getPersonalRooms } from "../../services/personalRoomsService.ts";
import type { IGetShipResponse, IPersonalRoomsClient } from "../../types/personalRoomsTypes.ts";
import { getLoadout } from "../../services/loadoutService.ts";
import { toOid } from "../../helpers/inventoryHelpers.ts";
2023-05-19 15:22:48 -03:00
export const getShipController: RequestHandler = async (req, res) => {
2024-05-28 13:45:06 +02:00
const accountId = await getAccountIdForRequest(req);
const personalRoomsDb = await getPersonalRooms(accountId);
// Setup gardening if it's missing. Maybe should be done as part of some quest completion in the future.
if (personalRoomsDb.Apartment.Gardening.Planters.length == 0) {
personalRoomsDb.Apartment.Gardening = createGarden();
await personalRoomsDb.save();
}
const personalRooms = personalRoomsDb.toJSON<IPersonalRoomsClient>();
const loadout = await getLoadout(accountId);
const getShipResponse: IGetShipResponse = {
ShipOwnerId: accountId,
LoadOutInventory: { LoadOutPresets: loadout.toJSON() },
Ship: {
...personalRooms.Ship,
ShipId: toOid(personalRoomsDb.activeShipId)
},
2024-12-22 20:32:19 +01:00
Apartment: personalRooms.Apartment,
TailorShop: personalRooms.TailorShop
};
2024-06-11 12:56:51 +02:00
if (config.unlockAllShipFeatures) {
getShipResponse.Ship.Features = allShipFeatures;
2023-06-05 04:16:49 +08:00
}
res.json(getShipResponse);
};