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 { getPersonalRooms } from "@/src/services/personalRoomsService";
|
||||||
import { IOid } from "@/src/types/commonTypes";
|
import { IOid } from "@/src/types/commonTypes";
|
||||||
import { Types } from "mongoose";
|
import { Types } from "mongoose";
|
||||||
import { TBootLocation } from "@/src/types/shipTypes";
|
import { IFavouriteLoadoutDatabase, TBootLocation } from "@/src/types/shipTypes";
|
||||||
|
|
||||||
export const setShipFavouriteLoadoutController: RequestHandler = async (req, res) => {
|
export const setShipFavouriteLoadoutController: RequestHandler = async (req, res) => {
|
||||||
const accountId = await getAccountIdForRequest(req);
|
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;
|
const body = JSON.parse(String(req.body)) as ISetShipFavouriteLoadoutRequest;
|
||||||
if (body.BootLocation == "LISET") {
|
if (body.BootLocation == "LISET") {
|
||||||
personalRooms.Ship.FavouriteLoadoutId = new Types.ObjectId(body.FavouriteLoadoutId.$oid);
|
personalRooms.Ship.FavouriteLoadoutId = new Types.ObjectId(body.FavouriteLoadoutId.$oid);
|
||||||
|
} else if (body.BootLocation == "APARTMENT") {
|
||||||
|
updateTaggedDisplay(personalRooms.Apartment.FavouriteLoadouts, body);
|
||||||
} else if (body.BootLocation == "SHOP") {
|
} else if (body.BootLocation == "SHOP") {
|
||||||
const display = personalRooms.TailorShop.FavouriteLoadouts.find(x => x.Tag == body.TagName!);
|
updateTaggedDisplay(personalRooms.TailorShop.FavouriteLoadouts, body);
|
||||||
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)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
|
console.log(body);
|
||||||
throw new Error(`unexpected BootLocation: ${body.BootLocation}`);
|
throw new Error(`unexpected BootLocation: ${body.BootLocation}`);
|
||||||
}
|
}
|
||||||
await personalRooms.save();
|
await personalRooms.save();
|
||||||
@ -33,3 +28,15 @@ interface ISetShipFavouriteLoadoutRequest {
|
|||||||
FavouriteLoadoutId: IOid;
|
FavouriteLoadoutId: IOid;
|
||||||
TagName?: string; // given request for SHOP, but not for LISET
|
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 { colorSchema } from "@/src/models/inventoryModels/inventoryModel";
|
||||||
import { IOrbiter, IPersonalRoomsDatabase, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes";
|
import { IOrbiter, IPersonalRoomsDatabase, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes";
|
||||||
import {
|
import {
|
||||||
IApartment,
|
|
||||||
IFavouriteLoadoutDatabase,
|
IFavouriteLoadoutDatabase,
|
||||||
IGardening,
|
IGardening,
|
||||||
IPlacedDecosDatabase,
|
IPlacedDecosDatabase,
|
||||||
IPictureFrameInfo,
|
IPictureFrameInfo,
|
||||||
IRoom,
|
IRoom,
|
||||||
ITailorShopDatabase
|
ITailorShopDatabase,
|
||||||
|
IApartmentDatabase
|
||||||
} from "@/src/types/shipTypes";
|
} from "@/src/types/shipTypes";
|
||||||
import { Schema, model } from "mongoose";
|
import { Schema, model } from "mongoose";
|
||||||
|
|
||||||
@ -62,19 +62,34 @@ const roomSchema = new Schema<IRoom>(
|
|||||||
{ _id: false }
|
{ _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>({
|
const gardeningSchema = new Schema<IGardening>({
|
||||||
Planters: [Schema.Types.Mixed] //TODO: add when implementing gardening
|
Planters: [Schema.Types.Mixed] //TODO: add when implementing gardening
|
||||||
});
|
});
|
||||||
|
|
||||||
const apartmentSchema = new Schema<IApartment>(
|
const apartmentSchema = new Schema<IApartmentDatabase>(
|
||||||
{
|
{
|
||||||
Rooms: [roomSchema],
|
Rooms: [roomSchema],
|
||||||
FavouriteLoadouts: [Schema.Types.Mixed],
|
FavouriteLoadouts: [favouriteLoadoutSchema],
|
||||||
Gardening: gardeningSchema // TODO: ensure this is correct
|
Gardening: gardeningSchema // TODO: ensure this is correct
|
||||||
},
|
},
|
||||||
{ _id: false }
|
{ _id: false }
|
||||||
);
|
);
|
||||||
const apartmentDefault: IApartment = {
|
const apartmentDefault: IApartmentDatabase = {
|
||||||
Rooms: [
|
Rooms: [
|
||||||
{ Name: "ElevatorLanding", MaxCapacity: 1600 },
|
{ Name: "ElevatorLanding", MaxCapacity: 1600 },
|
||||||
{ Name: "ApartmentRoomA", MaxCapacity: 1000 },
|
{ 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>(
|
const tailorShopSchema = new Schema<ITailorShopDatabase>(
|
||||||
{
|
{
|
||||||
FavouriteLoadouts: [favouriteLoadoutSchema],
|
FavouriteLoadouts: [favouriteLoadoutSchema],
|
||||||
|
@ -5,7 +5,8 @@ import {
|
|||||||
IPlacedDecosDatabase,
|
IPlacedDecosDatabase,
|
||||||
ITailorShop,
|
ITailorShop,
|
||||||
ITailorShopDatabase,
|
ITailorShopDatabase,
|
||||||
TBootLocation
|
TBootLocation,
|
||||||
|
IApartmentDatabase
|
||||||
} from "@/src/types/shipTypes";
|
} from "@/src/types/shipTypes";
|
||||||
import { Document, Model, Types } from "mongoose";
|
import { Document, Model, Types } from "mongoose";
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ export interface IPersonalRoomsDatabase {
|
|||||||
personalRoomsOwnerId: Types.ObjectId;
|
personalRoomsOwnerId: Types.ObjectId;
|
||||||
activeShipId: Types.ObjectId;
|
activeShipId: Types.ObjectId;
|
||||||
Ship: IOrbiter;
|
Ship: IOrbiter;
|
||||||
Apartment: IApartment;
|
Apartment: IApartmentDatabase;
|
||||||
TailorShop: ITailorShopDatabase;
|
TailorShop: ITailorShopDatabase;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +43,7 @@ export type PersonalRoomsDocumentProps = {
|
|||||||
Ship: Omit<IOrbiter, "Rooms"> & {
|
Ship: Omit<IOrbiter, "Rooms"> & {
|
||||||
Rooms: RoomsType[];
|
Rooms: RoomsType[];
|
||||||
};
|
};
|
||||||
Apartment: Omit<IApartment, "Rooms"> & {
|
Apartment: Omit<IApartmentDatabase, "Rooms"> & {
|
||||||
Rooms: RoomsType[];
|
Rooms: RoomsType[];
|
||||||
};
|
};
|
||||||
TailorShop: Omit<ITailorShopDatabase, "Rooms"> & {
|
TailorShop: Omit<ITailorShopDatabase, "Rooms"> & {
|
||||||
|
@ -64,10 +64,17 @@ export interface IPlanters {
|
|||||||
export interface IGardening {
|
export interface IGardening {
|
||||||
Planters?: IPlanters[];
|
Planters?: IPlanters[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IApartment {
|
export interface IApartment {
|
||||||
Gardening: IGardening;
|
Gardening: IGardening;
|
||||||
Rooms: IRoom[];
|
Rooms: IRoom[];
|
||||||
FavouriteLoadouts: string[];
|
FavouriteLoadouts: IFavouriteLoadout[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IApartmentDatabase {
|
||||||
|
Gardening: IGardening;
|
||||||
|
Rooms: IRoom[];
|
||||||
|
FavouriteLoadouts: IFavouriteLoadoutDatabase[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IPlacedDecosDatabase {
|
export interface IPlacedDecosDatabase {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user