2023-12-29 20:11:07 -05:00
|
|
|
import mongoose, { PopulatedDoc, Model } from "mongoose";
|
2023-09-25 19:19:32 -04:00
|
|
|
import SequenceFactory from "mongoose-sequence";
|
|
|
|
|
|
|
|
const AutoIncrement = SequenceFactory(mongoose);
|
|
|
|
|
|
|
|
import { Chapter, IChapter } from "./chapter";
|
2023-12-20 17:23:31 -05:00
|
|
|
import { IUser } from "@models/user";
|
|
|
|
import { Ficmas, IFicmas } from "@models/challenges/ficmas";
|
|
|
|
import { IChallenge, Challenge } from "@models/challenges/gen";
|
|
|
|
import { hasMigrated } from "@dbconfig";
|
2023-09-25 19:19:32 -04:00
|
|
|
|
2023-10-03 01:11:32 -04:00
|
|
|
export interface IStory {
|
2023-09-25 19:19:32 -04:00
|
|
|
_id?: number;
|
|
|
|
title: string;
|
2023-12-30 00:46:11 -05:00
|
|
|
author: PopulatedDoc<IUser & Document>;
|
2023-10-03 01:11:32 -04:00
|
|
|
chapters: IChapter[];
|
2023-09-25 19:19:32 -04:00
|
|
|
recs: number;
|
|
|
|
favs: number;
|
|
|
|
reviews: number;
|
|
|
|
views: number;
|
|
|
|
completed: boolean;
|
2023-12-30 00:46:11 -05:00
|
|
|
challenge: PopulatedDoc<IChallenge & Document> | null;
|
|
|
|
ficmas: PopulatedDoc<IFicmas & Document> | null;
|
2023-09-25 19:19:32 -04:00
|
|
|
downloads: number;
|
|
|
|
lastUpdate: Date;
|
|
|
|
posted: Date;
|
2023-12-30 00:46:11 -05:00
|
|
|
coAuthor: PopulatedDoc<IUser & Document> | null;
|
2023-09-25 19:19:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const StorySchema = new mongoose.Schema<IStory>({
|
|
|
|
_id: {
|
2023-10-03 01:11:32 -04:00
|
|
|
type: Number,
|
2023-09-25 19:19:32 -04:00
|
|
|
},
|
|
|
|
title: {
|
2023-10-03 01:11:32 -04:00
|
|
|
type: String,
|
2023-09-25 19:19:32 -04:00
|
|
|
},
|
|
|
|
author: {
|
|
|
|
type: Number,
|
2023-10-03 01:11:32 -04:00
|
|
|
ref: "User",
|
|
|
|
},
|
|
|
|
coAuthor: {
|
|
|
|
type: Number,
|
|
|
|
ref: "User",
|
|
|
|
default: null,
|
2023-09-25 19:19:32 -04:00
|
|
|
},
|
|
|
|
chapters: [Chapter],
|
|
|
|
recs: {
|
|
|
|
type: Number,
|
2023-10-03 01:11:32 -04:00
|
|
|
default: 0,
|
2023-09-25 19:19:32 -04:00
|
|
|
},
|
|
|
|
favs: {
|
|
|
|
type: Number,
|
2023-10-03 01:11:32 -04:00
|
|
|
default: 0,
|
2023-09-25 19:19:32 -04:00
|
|
|
},
|
|
|
|
reviews: {
|
|
|
|
type: Number,
|
2023-10-03 01:11:32 -04:00
|
|
|
default: 0,
|
2023-09-25 19:19:32 -04:00
|
|
|
},
|
|
|
|
views: {
|
|
|
|
type: Number,
|
2023-10-03 01:11:32 -04:00
|
|
|
default: 0,
|
2023-09-25 19:19:32 -04:00
|
|
|
},
|
|
|
|
completed: {
|
|
|
|
type: Boolean,
|
2023-10-03 01:11:32 -04:00
|
|
|
default: false,
|
2023-09-25 19:19:32 -04:00
|
|
|
},
|
|
|
|
challenge: {
|
|
|
|
type: Number,
|
|
|
|
ref: "Challenge",
|
2023-10-03 01:11:32 -04:00
|
|
|
default: null,
|
2023-09-25 19:19:32 -04:00
|
|
|
},
|
|
|
|
ficmas: {
|
|
|
|
type: Number,
|
|
|
|
ref: "Ficmas",
|
2023-10-03 01:11:32 -04:00
|
|
|
default: null,
|
2023-09-25 19:19:32 -04:00
|
|
|
},
|
|
|
|
downloads: {
|
|
|
|
type: Number,
|
2023-10-03 01:11:32 -04:00
|
|
|
default: 0,
|
2023-09-25 19:19:32 -04:00
|
|
|
},
|
|
|
|
lastUpdate: {
|
|
|
|
type: Date,
|
2023-10-03 01:11:32 -04:00
|
|
|
default: new Date(),
|
2023-09-25 19:19:32 -04:00
|
|
|
},
|
|
|
|
posted: {
|
|
|
|
type: Date,
|
2023-10-03 01:11:32 -04:00
|
|
|
default: new Date(),
|
|
|
|
},
|
|
|
|
});
|
2023-12-29 20:11:07 -05:00
|
|
|
hasMigrated && !mongoose.models.Story && Chapter.plugin(AutoIncrement, { id: "chapterid", inc_field: "id" });
|
2023-12-06 21:28:51 -05:00
|
|
|
hasMigrated && StorySchema.plugin(AutoIncrement, { id: "storyid" });
|
2023-12-29 20:11:07 -05:00
|
|
|
export const Story: Model<IStory> = /* mongoose.models.Story || */ mongoose.model("Story", StorySchema, "stories");
|