2023-10-03 01:15:29 -04:00
|
|
|
import mongoose, { Schema, PopulatedDoc, Document, Model } from "mongoose";
|
2023-09-25 19:26:13 -04:00
|
|
|
import SequenceFactory from "mongoose-sequence";
|
2023-12-20 17:23:31 -05:00
|
|
|
import { hasMigrated } from "@dbconfig";
|
2023-09-25 19:26:13 -04:00
|
|
|
|
|
|
|
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<IChallenge>({
|
|
|
|
_id: {
|
2023-10-03 01:15:29 -04:00
|
|
|
type: Number,
|
2023-09-25 19:26:13 -04:00
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: String,
|
2023-10-03 01:15:29 -04:00
|
|
|
required: true,
|
2023-09-25 19:26:13 -04:00
|
|
|
},
|
|
|
|
description: {
|
|
|
|
type: String,
|
2023-10-03 01:15:29 -04:00
|
|
|
required: true,
|
2023-09-25 19:26:13 -04:00
|
|
|
},
|
|
|
|
deadline: {
|
|
|
|
type: Date,
|
2023-10-03 01:15:29 -04:00
|
|
|
required: true,
|
2023-09-25 19:26:13 -04:00
|
|
|
},
|
|
|
|
active: {
|
|
|
|
type: Boolean,
|
2023-10-03 01:15:29 -04:00
|
|
|
default: true,
|
2023-09-25 19:26:13 -04:00
|
|
|
},
|
|
|
|
color: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
2023-10-03 01:15:29 -04:00
|
|
|
default: `#${Math.floor(Math.random() * 16777215).toString(16)}`,
|
2023-09-25 19:26:13 -04:00
|
|
|
},
|
|
|
|
allowMultiple: {
|
|
|
|
type: Boolean,
|
2023-10-03 01:15:29 -04:00
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
});
|
2023-09-25 19:26:13 -04:00
|
|
|
|
2023-12-29 16:36:26 -05:00
|
|
|
hasMigrated && challengeSchema.plugin(AutoIncrement, { id: "challenges" });
|
2023-10-03 01:15:29 -04:00
|
|
|
export const Challenge: Model<IChallenge> =
|
2023-12-06 21:28:51 -05:00
|
|
|
// mongoose.models.Challenge ||
|
2023-10-03 01:15:29 -04:00
|
|
|
mongoose.model("Challenge", challengeSchema, "challenges");
|