2024-02-18 13:58:43 +01:00
|
|
|
import { PersonalRooms } from "@/src/models/personalRoomsModel";
|
2025-01-24 14:13:21 +01:00
|
|
|
import { addItem, getInventory } from "@/src/services/inventoryService";
|
2025-03-15 03:24:39 -07:00
|
|
|
import { TPersonalRoomsDatabaseDocument } from "../types/personalRoomsTypes";
|
2024-02-18 13:58:43 +01:00
|
|
|
|
2025-03-15 03:24:39 -07:00
|
|
|
export const getPersonalRooms = async (accountId: string): Promise<TPersonalRoomsDatabaseDocument> => {
|
2024-02-18 13:58:43 +01:00
|
|
|
const personalRooms = await PersonalRooms.findOne({ personalRoomsOwnerId: accountId });
|
|
|
|
|
|
|
|
if (!personalRooms) {
|
2025-01-03 22:25:03 +01:00
|
|
|
throw new Error(`personal rooms not found for account ${accountId}`);
|
2024-02-18 13:58:43 +01:00
|
|
|
}
|
|
|
|
return personalRooms;
|
|
|
|
};
|
2025-01-24 14:13:21 +01:00
|
|
|
|
2025-03-15 03:24:39 -07:00
|
|
|
export const updateShipFeature = async (accountId: string, shipFeature: string): Promise<void> => {
|
2025-01-24 14:13:21 +01:00
|
|
|
const personalRooms = await getPersonalRooms(accountId);
|
|
|
|
|
|
|
|
if (personalRooms.Ship.Features.includes(shipFeature)) {
|
|
|
|
throw new Error(`ship feature ${shipFeature} already unlocked`);
|
|
|
|
}
|
|
|
|
|
|
|
|
personalRooms.Ship.Features.push(shipFeature);
|
|
|
|
await personalRooms.save();
|
|
|
|
|
|
|
|
const inventory = await getInventory(accountId);
|
|
|
|
await addItem(inventory, shipFeature, -1);
|
|
|
|
await inventory.save();
|
|
|
|
};
|