import mongoose, { Schema, PopulatedDoc, Document, Model } from "mongoose"; import SequenceFactory from "mongoose-sequence"; import { hasMigrated } from "~/lib/dbconfig"; const AutoIncrement = SequenceFactory(mongoose); export interface IChallenge { _id: number; name: string; description: string; deadline: Date; active: boolean; color: string; allowMultiple: boolean; } const challengeSchema = new mongoose.Schema({ _id: { type: Number, }, name: { type: String, required: true, }, description: { type: String, required: true, }, deadline: { type: Date, required: true, }, active: { type: Boolean, default: true, }, color: { type: String, required: true, default: `#${Math.floor(Math.random() * 16777215).toString(16)}`, }, allowMultiple: { type: Boolean, default: true, }, }); hasMigrated && challengeSchema.plugin(AutoIncrement, { id: "challenges" }); export const Challenge: Model = mongoose.models.Challenge || mongoose.model("Challenge", challengeSchema, "challenges");