2023-12-14 17:34:15 +01:00
|
|
|
import { IOid } from "@/src/types/commonTypes";
|
2024-06-16 17:51:20 +02:00
|
|
|
import { IEquipmentSelection } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
|
|
|
import { ILoadoutConfigDatabase, ILoadoutDatabase } from "@/src/types/saveLoadoutTypes";
|
2025-03-15 03:24:39 -07:00
|
|
|
import { Document, Model, Schema, Types, model } from "mongoose";
|
2023-12-14 17:34:15 +01:00
|
|
|
|
|
|
|
const oidSchema = new Schema<IOid>(
|
|
|
|
{
|
|
|
|
$oid: String
|
|
|
|
},
|
|
|
|
{
|
|
|
|
_id: false
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
//create a mongoose schema based on interface M
|
2024-12-23 22:47:58 +01:00
|
|
|
export const EquipmentSelectionSchema = new Schema<IEquipmentSelection>(
|
2023-12-14 17:34:15 +01:00
|
|
|
{
|
2024-05-12 23:35:48 +02:00
|
|
|
ItemId: oidSchema,
|
2023-12-14 17:34:15 +01:00
|
|
|
mod: Number,
|
2024-05-04 23:11:55 +02:00
|
|
|
cus: Number,
|
|
|
|
hide: Boolean
|
2023-12-14 17:34:15 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
_id: false
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
const loadoutConfigSchema = new Schema<ILoadoutConfigDatabase>(
|
|
|
|
{
|
2024-06-26 16:23:52 +02:00
|
|
|
FocusSchool: String,
|
2023-12-14 17:34:15 +01:00
|
|
|
PresetIcon: String,
|
|
|
|
Favorite: Boolean,
|
2024-06-26 16:23:52 +02:00
|
|
|
n: String, // Loadout name
|
|
|
|
s: EquipmentSelectionSchema, // Suit
|
|
|
|
l: EquipmentSelectionSchema, // Primary weapon
|
|
|
|
p: EquipmentSelectionSchema, // Secondary weapon
|
|
|
|
m: EquipmentSelectionSchema, // Melee weapon
|
|
|
|
h: EquipmentSelectionSchema, // Gravimag weapon
|
|
|
|
a: EquipmentSelectionSchema // Necromech exalted weapon
|
2023-12-14 17:34:15 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: false
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
loadoutConfigSchema.virtual("ItemId").get(function () {
|
|
|
|
return { $oid: this._id.toString() } satisfies IOid;
|
|
|
|
});
|
|
|
|
|
|
|
|
loadoutConfigSchema.set("toJSON", {
|
|
|
|
virtuals: true,
|
|
|
|
transform(_doc, ret, _options) {
|
|
|
|
delete ret._id;
|
|
|
|
delete ret.__v;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export const loadoutSchema = new Schema<ILoadoutDatabase, loadoutModelType>({
|
|
|
|
NORMAL: [loadoutConfigSchema],
|
|
|
|
SENTINEL: [loadoutConfigSchema],
|
|
|
|
ARCHWING: [loadoutConfigSchema],
|
|
|
|
NORMAL_PVP: [loadoutConfigSchema],
|
|
|
|
LUNARO: [loadoutConfigSchema],
|
|
|
|
OPERATOR: [loadoutConfigSchema],
|
|
|
|
KDRIVE: [loadoutConfigSchema],
|
|
|
|
DATAKNIFE: [loadoutConfigSchema],
|
|
|
|
MECH: [loadoutConfigSchema],
|
|
|
|
OPERATOR_ADULT: [loadoutConfigSchema],
|
|
|
|
DRIFTER: [loadoutConfigSchema],
|
|
|
|
loadoutOwnerId: Schema.Types.ObjectId
|
|
|
|
});
|
|
|
|
|
|
|
|
loadoutSchema.set("toJSON", {
|
|
|
|
transform(_doc, ret, _options) {
|
|
|
|
delete ret._id;
|
|
|
|
delete ret.__v;
|
|
|
|
delete ret.loadoutOwnerId;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
//create database typefor ILoadoutConfig
|
|
|
|
type loadoutDocumentProps = {
|
|
|
|
NORMAL: Types.DocumentArray<ILoadoutConfigDatabase>;
|
|
|
|
SENTINEL: Types.DocumentArray<ILoadoutConfigDatabase>;
|
|
|
|
ARCHWING: Types.DocumentArray<ILoadoutConfigDatabase>;
|
|
|
|
NORMAL_PVP: Types.DocumentArray<ILoadoutConfigDatabase>;
|
|
|
|
LUNARO: Types.DocumentArray<ILoadoutConfigDatabase>;
|
|
|
|
OPERATOR: Types.DocumentArray<ILoadoutConfigDatabase>;
|
|
|
|
KDRIVE: Types.DocumentArray<ILoadoutConfigDatabase>;
|
|
|
|
DATAKNIFE: Types.DocumentArray<ILoadoutConfigDatabase>;
|
|
|
|
MECH: Types.DocumentArray<ILoadoutConfigDatabase>;
|
|
|
|
OPERATOR_ADULT: Types.DocumentArray<ILoadoutConfigDatabase>;
|
|
|
|
DRIFTER: Types.DocumentArray<ILoadoutConfigDatabase>;
|
|
|
|
};
|
|
|
|
|
2024-06-01 13:03:27 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
2023-12-14 17:34:15 +01:00
|
|
|
type loadoutModelType = Model<ILoadoutDatabase, {}, loadoutDocumentProps>;
|
|
|
|
|
2024-02-18 13:58:43 +01:00
|
|
|
export const Loadout = model<ILoadoutDatabase, loadoutModelType>("Loadout", loadoutSchema);
|
2025-03-15 03:24:39 -07:00
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
|
|
export type TLoadoutDatabaseDocument = Document<unknown, {}, ILoadoutDatabase> &
|
|
|
|
Omit<
|
|
|
|
ILoadoutDatabase & {
|
|
|
|
_id: Types.ObjectId;
|
|
|
|
} & {
|
|
|
|
__v: number;
|
|
|
|
},
|
|
|
|
keyof loadoutDocumentProps
|
|
|
|
> &
|
|
|
|
loadoutDocumentProps;
|