2024-05-06 15:19:42 +02:00
|
|
|
import { Schema, model } from "mongoose";
|
|
|
|
import { IShipDatabase } from "../types/shipTypes";
|
2024-02-18 13:58:43 +01:00
|
|
|
import { toOid } from "@/src/helpers/inventoryHelpers";
|
|
|
|
import { colorSchema } from "@/src/models/inventoryModels/inventoryModel";
|
|
|
|
import { IShipInventory } from "@/src/types/inventoryTypes/inventoryTypes";
|
2023-06-05 04:16:49 +08:00
|
|
|
|
2024-02-18 13:58:43 +01:00
|
|
|
const shipSchema = new Schema<IShipDatabase>(
|
2023-06-05 00:17:01 +02:00
|
|
|
{
|
2024-02-18 13:58:43 +01:00
|
|
|
ItemType: String,
|
|
|
|
ShipOwnerId: Schema.Types.ObjectId,
|
|
|
|
ShipExteriorColors: colorSchema,
|
|
|
|
AirSupportPower: String,
|
|
|
|
ShipAttachments: { HOOD_ORNAMENT: String },
|
|
|
|
SkinFlavourItem: String
|
2023-12-14 17:34:15 +01:00
|
|
|
},
|
|
|
|
{ id: false }
|
|
|
|
);
|
|
|
|
|
2024-02-18 13:58:43 +01:00
|
|
|
shipSchema.virtual("ItemId").get(function () {
|
|
|
|
return toOid(this._id);
|
2023-06-05 04:16:49 +08:00
|
|
|
});
|
|
|
|
|
2023-06-05 00:17:01 +02:00
|
|
|
shipSchema.set("toJSON", {
|
2023-12-14 17:34:15 +01:00
|
|
|
virtuals: true,
|
2023-06-05 04:16:49 +08:00
|
|
|
transform(_document, returnedObject) {
|
2024-02-18 13:58:43 +01:00
|
|
|
const shipResponse = returnedObject as IShipInventory;
|
|
|
|
const shipDatabase = returnedObject as IShipDatabase;
|
2023-06-05 04:16:49 +08:00
|
|
|
delete returnedObject._id;
|
2024-02-18 13:58:43 +01:00
|
|
|
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;
|
2023-12-14 17:34:15 +01:00
|
|
|
}
|
|
|
|
}
|
2023-06-05 04:16:49 +08:00
|
|
|
});
|
|
|
|
|
2024-02-18 13:58:43 +01:00
|
|
|
shipSchema.set("toObject", {
|
|
|
|
virtuals: true
|
2023-06-05 04:16:49 +08:00
|
|
|
});
|
|
|
|
|
2024-02-18 13:58:43 +01:00
|
|
|
export const Ship = model("Ships", shipSchema);
|