2023-06-05 04:16:49 +08:00
|
|
|
import { Schema, model } from "mongoose";
|
2023-06-05 00:17:01 +02:00
|
|
|
import { IShip } from "../types/shipTypes";
|
2023-06-05 04:16:49 +08:00
|
|
|
import { Oid } from "../types/commonTypes";
|
|
|
|
|
2023-06-05 00:17:01 +02:00
|
|
|
const roomSchema = new Schema(
|
|
|
|
{
|
|
|
|
Name: String,
|
|
|
|
MaxCapacity: Number
|
|
|
|
},
|
|
|
|
{ _id: false }
|
|
|
|
);
|
|
|
|
|
|
|
|
const shipSchema = new Schema({
|
|
|
|
Rooms: [roomSchema],
|
|
|
|
Features: [String],
|
|
|
|
ContentUrlSignature: String
|
2023-06-05 04:16:49 +08:00
|
|
|
});
|
|
|
|
|
2023-06-05 00:17:01 +02:00
|
|
|
shipSchema.set("toJSON", {
|
2023-06-05 04:16:49 +08:00
|
|
|
transform(_document, returnedObject) {
|
2023-06-05 00:17:01 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
|
|
|
returnedObject.ShipId = { $oid: returnedObject._id.toString() } satisfies Oid;
|
2023-06-05 04:16:49 +08:00
|
|
|
delete returnedObject._id;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const apartmentSchema = new Schema({
|
|
|
|
Rooms: [roomSchema],
|
|
|
|
FavouriteLoadouts: [Schema.Types.Mixed]
|
|
|
|
});
|
|
|
|
|
2023-06-05 00:17:01 +02:00
|
|
|
apartmentSchema.set("toJSON", {
|
|
|
|
transform(_document, returnedObject) {
|
|
|
|
delete returnedObject._id;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-06-05 04:16:49 +08:00
|
|
|
const shipDatabaseSchema = new Schema({
|
2023-06-05 00:17:01 +02:00
|
|
|
ShipOwnerId: Schema.Types.ObjectId,
|
2023-06-05 04:16:49 +08:00
|
|
|
Ship: shipSchema,
|
|
|
|
Apartment: apartmentSchema
|
|
|
|
});
|
|
|
|
|
|
|
|
shipDatabaseSchema.set("toJSON", {
|
|
|
|
transform(_document, returnedObject) {
|
|
|
|
delete returnedObject._id;
|
|
|
|
delete returnedObject.__v;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-06-05 00:17:01 +02:00
|
|
|
const Ship = model<IShip>("Ship", shipDatabaseSchema);
|
2023-06-05 04:16:49 +08:00
|
|
|
|
|
|
|
export { Ship };
|