forked from OpenWF/SpaceNinjaServer
Reviewed-on: OpenWF/SpaceNinjaServer#1373 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
58 lines
1.8 KiB
TypeScript
58 lines
1.8 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/inventoryModels/inventoryModel";
|
|
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;
|
|
if (shipDatabase.ShipExteriorColors) {
|
|
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;
|
|
};
|