SpaceNinjaServer/src/controllers/api/getShipController.ts

51 lines
2.1 KiB
TypeScript
Raw Normal View History

2023-05-19 15:22:48 -03:00
import { RequestHandler } from "express";
2024-05-15 21:55:59 +02:00
import { config } from "@/src/services/configService";
import allShipFeatures from "@/static/fixed_responses/allShipFeatures.json";
2024-05-28 13:45:06 +02:00
import { getAccountIdForRequest } from "@/src/services/loginService";
import { createGarden, getPersonalRooms } from "@/src/services/personalRoomsService";
import { getShip } from "@/src/services/shipService";
import { toOid } from "@/src/helpers/inventoryHelpers";
import { IGetShipResponse } from "@/src/types/shipTypes";
import { IPersonalRoomsClient } from "@/src/types/personalRoomsTypes";
2025-01-20 12:19:32 +01:00
import { getLoadout } from "@/src/services/loadoutService";
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);
2024-12-23 09:15:41 +01:00
const ship = await getShip(personalRoomsDb.activeShipId, "ShipAttachments SkinFlavourItem");
const getShipResponse: IGetShipResponse = {
ShipOwnerId: accountId,
LoadOutInventory: { LoadOutPresets: loadout.toJSON() },
Ship: {
...personalRooms.Ship,
ShipId: toOid(personalRoomsDb.activeShipId),
ShipInterior: {
2024-12-23 09:15:41 +01:00
Colors: personalRooms.ShipInteriorColors,
ShipAttachments: ship.ShipAttachments,
SkinFlavourItem: ship.SkinFlavourItem
},
FavouriteLoadoutId: personalRooms.Ship.FavouriteLoadoutId
? toOid(personalRooms.Ship.FavouriteLoadoutId)
: undefined
},
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);
};