forked from OpenWF/SpaceNinjaServer
The only functionally relevant change is that orbiter scenes are now saved via SkinFlavourItem (as of U39?). The rest is cleanup of the types because the ship customization stuff was duplicated all over the place. Reviewed-on: OpenWF/SpaceNinjaServer#2402 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import { Document, Schema, Types, model } from "mongoose";
|
|
import { IShipDatabase } from "../types/shipTypes";
|
|
import { toOid } from "@/src/helpers/inventoryHelpers";
|
|
import { colorSchema } from "@/src/models/commonModel";
|
|
import { IShipInventory } from "@/src/types/inventoryTypes/inventoryTypes";
|
|
|
|
const shipSchema = new Schema<IShipDatabase>(
|
|
{
|
|
ItemType: String,
|
|
ShipOwnerId: Schema.Types.ObjectId,
|
|
ShipExteriorColors: colorSchema,
|
|
AirSupportPower: String,
|
|
ShipAttachments: { HOOD_ORNAMENT: String },
|
|
SkinFlavourItem: String
|
|
},
|
|
{ id: false }
|
|
);
|
|
|
|
shipSchema.virtual("ItemId").get(function () {
|
|
return toOid(this._id);
|
|
});
|
|
|
|
shipSchema.set("toJSON", {
|
|
virtuals: true,
|
|
transform(_document, returnedObject) {
|
|
const shipResponse = returnedObject as IShipInventory;
|
|
const shipDatabase = returnedObject as IShipDatabase;
|
|
delete returnedObject._id;
|
|
delete returnedObject.__v;
|
|
delete returnedObject.ShipOwnerId;
|
|
|
|
shipResponse.ShipExterior = {
|
|
Colors: shipDatabase.ShipExteriorColors,
|
|
ShipAttachments: shipDatabase.ShipAttachments,
|
|
SkinFlavourItem: shipDatabase.SkinFlavourItem
|
|
};
|
|
delete shipDatabase.ShipExteriorColors;
|
|
delete shipDatabase.ShipAttachments;
|
|
delete shipDatabase.SkinFlavourItem;
|
|
}
|
|
});
|
|
|
|
shipSchema.set("toObject", {
|
|
virtuals: true
|
|
});
|
|
|
|
export const Ship = model("Ships", shipSchema);
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
export type TShipDatabaseDocument = Document<unknown, {}, IShipDatabase> &
|
|
IShipDatabase & {
|
|
_id: Types.ObjectId;
|
|
} & {
|
|
__v: number;
|
|
};
|