next/models/challenges/ficmas.ts

57 lines
1.1 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 &&
!mongoose.models.Ficmas &&
FicmasSchema.plugin(AutoIncrement, { id: "ficmas_wishes", inc_field: "_id" });
export const Ficmas: Model<IFicmas> =
mongoose.models.Ficmas || model("Ficmas", FicmasSchema, "ficmas_wishes");