feat: change loadout display in apartment
This commit is contained in:
parent
fe6a88ef3f
commit
22f380b311
@ -3,7 +3,7 @@ import { RequestHandler } from "express";
|
||||
import { getPersonalRooms } from "@/src/services/personalRoomsService";
|
||||
import { IOid } from "@/src/types/commonTypes";
|
||||
import { Types } from "mongoose";
|
||||
import { TBootLocation } from "@/src/types/shipTypes";
|
||||
import { IFavouriteLoadoutDatabase, TBootLocation } from "@/src/types/shipTypes";
|
||||
|
||||
export const setShipFavouriteLoadoutController: RequestHandler = async (req, res) => {
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
@ -11,17 +11,12 @@ export const setShipFavouriteLoadoutController: RequestHandler = async (req, res
|
||||
const body = JSON.parse(String(req.body)) as ISetShipFavouriteLoadoutRequest;
|
||||
if (body.BootLocation == "LISET") {
|
||||
personalRooms.Ship.FavouriteLoadoutId = new Types.ObjectId(body.FavouriteLoadoutId.$oid);
|
||||
} else if (body.BootLocation == "APARTMENT") {
|
||||
updateTaggedDisplay(personalRooms.Apartment.FavouriteLoadouts, body);
|
||||
} else if (body.BootLocation == "SHOP") {
|
||||
const display = personalRooms.TailorShop.FavouriteLoadouts.find(x => x.Tag == body.TagName!);
|
||||
if (display) {
|
||||
display.LoadoutId = new Types.ObjectId(body.FavouriteLoadoutId.$oid);
|
||||
} else {
|
||||
personalRooms.TailorShop.FavouriteLoadouts.push({
|
||||
Tag: body.TagName!,
|
||||
LoadoutId: new Types.ObjectId(body.FavouriteLoadoutId.$oid)
|
||||
});
|
||||
}
|
||||
updateTaggedDisplay(personalRooms.TailorShop.FavouriteLoadouts, body);
|
||||
} else {
|
||||
console.log(body);
|
||||
throw new Error(`unexpected BootLocation: ${body.BootLocation}`);
|
||||
}
|
||||
await personalRooms.save();
|
||||
@ -33,3 +28,15 @@ interface ISetShipFavouriteLoadoutRequest {
|
||||
FavouriteLoadoutId: IOid;
|
||||
TagName?: string; // given request for SHOP, but not for LISET
|
||||
}
|
||||
|
||||
const updateTaggedDisplay = (arr: IFavouriteLoadoutDatabase[], body: ISetShipFavouriteLoadoutRequest): void => {
|
||||
const display = arr.find(x => x.Tag == body.TagName!);
|
||||
if (display) {
|
||||
display.LoadoutId = new Types.ObjectId(body.FavouriteLoadoutId.$oid);
|
||||
} else {
|
||||
arr.push({
|
||||
Tag: body.TagName!,
|
||||
LoadoutId: new Types.ObjectId(body.FavouriteLoadoutId.$oid)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -2,13 +2,13 @@ import { toOid } from "@/src/helpers/inventoryHelpers";
|
||||
import { colorSchema } from "@/src/models/inventoryModels/inventoryModel";
|
||||
import { IOrbiter, IPersonalRoomsDatabase, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes";
|
||||
import {
|
||||
IApartment,
|
||||
IFavouriteLoadoutDatabase,
|
||||
IGardening,
|
||||
IPlacedDecosDatabase,
|
||||
IPictureFrameInfo,
|
||||
IRoom,
|
||||
ITailorShopDatabase
|
||||
ITailorShopDatabase,
|
||||
IApartmentDatabase
|
||||
} from "@/src/types/shipTypes";
|
||||
import { Schema, model } from "mongoose";
|
||||
|
||||
@ -62,19 +62,34 @@ const roomSchema = new Schema<IRoom>(
|
||||
{ _id: false }
|
||||
);
|
||||
|
||||
const favouriteLoadoutSchema = new Schema<IFavouriteLoadoutDatabase>(
|
||||
{
|
||||
Tag: String,
|
||||
LoadoutId: Schema.Types.ObjectId
|
||||
},
|
||||
{ _id: false }
|
||||
);
|
||||
favouriteLoadoutSchema.set("toJSON", {
|
||||
virtuals: true,
|
||||
transform(_document, returnedObject) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
returnedObject.LoadoutId = toOid(returnedObject.LoadoutId);
|
||||
}
|
||||
});
|
||||
|
||||
const gardeningSchema = new Schema<IGardening>({
|
||||
Planters: [Schema.Types.Mixed] //TODO: add when implementing gardening
|
||||
});
|
||||
|
||||
const apartmentSchema = new Schema<IApartment>(
|
||||
const apartmentSchema = new Schema<IApartmentDatabase>(
|
||||
{
|
||||
Rooms: [roomSchema],
|
||||
FavouriteLoadouts: [Schema.Types.Mixed],
|
||||
FavouriteLoadouts: [favouriteLoadoutSchema],
|
||||
Gardening: gardeningSchema // TODO: ensure this is correct
|
||||
},
|
||||
{ _id: false }
|
||||
);
|
||||
const apartmentDefault: IApartment = {
|
||||
const apartmentDefault: IApartmentDatabase = {
|
||||
Rooms: [
|
||||
{ Name: "ElevatorLanding", MaxCapacity: 1600 },
|
||||
{ Name: "ApartmentRoomA", MaxCapacity: 1000 },
|
||||
@ -111,21 +126,6 @@ const orbiterDefault: IOrbiter = {
|
||||
]
|
||||
};
|
||||
|
||||
const favouriteLoadoutSchema = new Schema<IFavouriteLoadoutDatabase>(
|
||||
{
|
||||
Tag: String,
|
||||
LoadoutId: Schema.Types.ObjectId
|
||||
},
|
||||
{ _id: false }
|
||||
);
|
||||
favouriteLoadoutSchema.set("toJSON", {
|
||||
virtuals: true,
|
||||
transform(_document, returnedObject) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
returnedObject.LoadoutId = toOid(returnedObject.LoadoutId);
|
||||
}
|
||||
});
|
||||
|
||||
const tailorShopSchema = new Schema<ITailorShopDatabase>(
|
||||
{
|
||||
FavouriteLoadouts: [favouriteLoadoutSchema],
|
||||
|
@ -5,7 +5,8 @@ import {
|
||||
IPlacedDecosDatabase,
|
||||
ITailorShop,
|
||||
ITailorShopDatabase,
|
||||
TBootLocation
|
||||
TBootLocation,
|
||||
IApartmentDatabase
|
||||
} from "@/src/types/shipTypes";
|
||||
import { Document, Model, Types } from "mongoose";
|
||||
|
||||
@ -32,7 +33,7 @@ export interface IPersonalRoomsDatabase {
|
||||
personalRoomsOwnerId: Types.ObjectId;
|
||||
activeShipId: Types.ObjectId;
|
||||
Ship: IOrbiter;
|
||||
Apartment: IApartment;
|
||||
Apartment: IApartmentDatabase;
|
||||
TailorShop: ITailorShopDatabase;
|
||||
}
|
||||
|
||||
@ -42,7 +43,7 @@ export type PersonalRoomsDocumentProps = {
|
||||
Ship: Omit<IOrbiter, "Rooms"> & {
|
||||
Rooms: RoomsType[];
|
||||
};
|
||||
Apartment: Omit<IApartment, "Rooms"> & {
|
||||
Apartment: Omit<IApartmentDatabase, "Rooms"> & {
|
||||
Rooms: RoomsType[];
|
||||
};
|
||||
TailorShop: Omit<ITailorShopDatabase, "Rooms"> & {
|
||||
|
@ -64,10 +64,17 @@ export interface IPlanters {
|
||||
export interface IGardening {
|
||||
Planters?: IPlanters[];
|
||||
}
|
||||
|
||||
export interface IApartment {
|
||||
Gardening: IGardening;
|
||||
Rooms: IRoom[];
|
||||
FavouriteLoadouts: string[];
|
||||
FavouriteLoadouts: IFavouriteLoadout[];
|
||||
}
|
||||
|
||||
export interface IApartmentDatabase {
|
||||
Gardening: IGardening;
|
||||
Rooms: IRoom[];
|
||||
FavouriteLoadouts: IFavouriteLoadoutDatabase[];
|
||||
}
|
||||
|
||||
export interface IPlacedDecosDatabase {
|
||||
|
Loading…
x
Reference in New Issue
Block a user