next/models/challenges/ficmas.ts
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ a8e113e969
refactor(db/models): remove model existence guards
this way, plugins are registered if `hasMigrated` is true. we've already enabled automatically overwriting models, therefore, the guard's condition will always be false
2023-12-29 16:36:26 -05:00

56 lines
1.0 KiB
TypeScript

import mongoose, {
Schema,
PopulatedDoc,
Document,
Model,
model,
} from "mongoose";
import { IBand } from "@models/band";
import { IUser } from "@models/user";
import SequenceFactory from "mongoose-sequence";
import { hasMigrated } from "@dbconfig";
const AutoIncrement = SequenceFactory(mongoose);
export interface IFicmas {
_id: number;
kink: string;
year: string;
bands: PopulatedDoc<IBand & Document>[];
relationship: string;
wisher: PopulatedDoc<IUser & Document>;
anniversary: boolean;
}
export const FicmasSchema = new mongoose.Schema<IFicmas>({
_id: {
type: Number,
},
kink: {
type: String,
},
year: { type: String },
bands: [
{
type: Number,
ref: "Band",
},
],
relationship: { type: String },
wisher: {
type: Number,
ref: "User",
},
anniversary: {
type: Boolean,
default: false,
},
});
hasMigrated &&
FicmasSchema.plugin(AutoIncrement, { id: "ficmas_wishes", inc_field: "_id" });
export const Ficmas: Model<IFicmas> =
mongoose.models.Ficmas || model("Ficmas", FicmasSchema, "ficmas_wishes");