SpaceNinjaServer/src/controllers/api/getShipController.ts

51 lines
1.9 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 { getPersonalRooms } from "@/src/services/personalRoomsService";
import { getShip } from "@/src/services/shipService";
import { Loadout } from "@/src/models/inventoryModels/loadoutModel";
import { logger } from "@/src/utils/logger";
import { toOid } from "@/src/helpers/inventoryHelpers";
import { IGetShipResponse } from "@/src/types/shipTypes";
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 personalRooms = await getPersonalRooms(accountId);
const loadout = await getLoadout(accountId);
const ship = await getShip(personalRooms.activeShipId, "ShipInteriorColors ShipAttachments SkinFlavourItem");
const getShipResponse: IGetShipResponse = {
ShipOwnerId: accountId,
LoadOutInventory: { LoadOutPresets: loadout.toJSON() },
Ship: {
...personalRooms.toJSON().Ship,
ShipId: toOid(personalRooms.activeShipId),
ShipInterior: {
Colors: ship.ShipInteriorColors,
ShipAttachments: ship.ShipAttachments,
SkinFlavourItem: ship.SkinFlavourItem
}
},
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);
};
export const getLoadout = async (accountId: string) => {
const loadout = await Loadout.findOne({ loadoutOwnerId: accountId });
if (!loadout) {
logger.error(`loadout not found for account ${accountId}`);
throw new Error("loadout not found");
}
return loadout;
2023-05-19 15:22:48 -03:00
};