fix: make crew member slots optional
it is possible to e.g. only have 2/3 crew members active, then one of the slots is simply absent.
This commit is contained in:
parent
fb8e19403e
commit
5a20c708f3
@ -46,7 +46,8 @@ import {
|
|||||||
ICrewShip,
|
ICrewShip,
|
||||||
ICrewShipPilotWeapon,
|
ICrewShipPilotWeapon,
|
||||||
IShipExterior,
|
IShipExterior,
|
||||||
IHelminthFoodRecord
|
IHelminthFoodRecord,
|
||||||
|
ICrewShipMembersDatabase
|
||||||
} from "../../types/inventoryTypes/inventoryTypes";
|
} from "../../types/inventoryTypes/inventoryTypes";
|
||||||
import { IOid } from "../../types/commonTypes";
|
import { IOid } from "../../types/commonTypes";
|
||||||
import {
|
import {
|
||||||
@ -670,23 +671,22 @@ const crewShipCustomizationSchema = new Schema<ICrewShipCustomization>(
|
|||||||
{ _id: false }
|
{ _id: false }
|
||||||
);
|
);
|
||||||
|
|
||||||
const crewShipMembersSchema = new Schema<ICrewShipMembers>(
|
const crewShipMembersSchema = new Schema<ICrewShipMembersDatabase>(
|
||||||
{
|
{
|
||||||
SLOT_A: Schema.Types.ObjectId,
|
SLOT_A: { type: Schema.Types.ObjectId, required: false },
|
||||||
SLOT_B: Schema.Types.ObjectId,
|
SLOT_B: { type: Schema.Types.ObjectId, required: false },
|
||||||
SLOT_C: Schema.Types.ObjectId
|
SLOT_C: { type: Schema.Types.ObjectId, required: false }
|
||||||
},
|
},
|
||||||
{ _id: false }
|
{ _id: false }
|
||||||
);
|
);
|
||||||
crewShipMembersSchema.set("toJSON", {
|
crewShipMembersSchema.set("toJSON", {
|
||||||
virtuals: true,
|
virtuals: true,
|
||||||
transform(_doc, ret) {
|
transform(_doc, obj) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
const db = obj as ICrewShipMembersDatabase;
|
||||||
ret.SLOT_A = { ItemId: toOid(ret.SLOT_A) };
|
const client = obj as ICrewShipMembers;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
client.SLOT_A = db.SLOT_A ? { ItemId: toOid(db.SLOT_A) } : undefined;
|
||||||
ret.SLOT_B = { ItemId: toOid(ret.SLOT_B) };
|
client.SLOT_B = db.SLOT_B ? { ItemId: toOid(db.SLOT_B) } : undefined;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
client.SLOT_C = db.SLOT_C ? { ItemId: toOid(db.SLOT_C) } : undefined;
|
||||||
ret.SLOT_C = { ItemId: toOid(ret.SLOT_C) };
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -432,15 +432,21 @@ export interface ICrewShip {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ICrewShipMembers {
|
export interface ICrewShipMembers {
|
||||||
SLOT_A: ISlot;
|
SLOT_A?: ISlot;
|
||||||
SLOT_B: ISlot;
|
SLOT_B?: ISlot;
|
||||||
SLOT_C: ISlot;
|
SLOT_C?: ISlot;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISlot {
|
export interface ISlot {
|
||||||
ItemId: IOid;
|
ItemId: IOid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ICrewShipMembersDatabase {
|
||||||
|
SLOT_A?: Types.ObjectId;
|
||||||
|
SLOT_B?: Types.ObjectId;
|
||||||
|
SLOT_C?: Types.ObjectId;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ICrewShipCustomization {
|
export interface ICrewShipCustomization {
|
||||||
CrewshipInterior: IShipExterior;
|
CrewshipInterior: IShipExterior;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user