2023-10-03 01:11:32 -04:00
|
|
|
import mongoose, { Schema, PopulatedDoc, Document, 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-10-03 01:11:32 -04:00
|
|
|
import { IUser } from "~/models/user";
|
|
|
|
import { Ficmas, IFicmas } from "~/models/challenges/ficmas";
|
|
|
|
import { IChallenge, Challenge } from "~/models/challenges/gen";
|
|
|
|
import { hasMigrated } from "~/lib/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;
|
|
|
|
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;
|
|
|
|
challenge: PopulatedDoc<IChallenge & Document> | null;
|
|
|
|
ficmas: PopulatedDoc<IFicmas & Document> | null;
|
|
|
|
downloads: number;
|
|
|
|
lastUpdate: Date;
|
|
|
|
posted: Date;
|
2023-10-03 01:11:32 -04: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-10-12 22:28:37 -04:00
|
|
|
hasMigrated && !mongoose.models.Story;
|
|
|
|
Chapter.plugin(AutoIncrement, { id: "chapterid", inc_field: "id" });
|
2023-10-03 01:11:32 -04:00
|
|
|
hasMigrated &&
|
2023-10-12 22:28:37 -04:00
|
|
|
!mongoose.models.Story &&
|
|
|
|
StorySchema.plugin(AutoIncrement, { id: "storyid" });
|
2023-10-03 01:11:32 -04:00
|
|
|
export const Story: Model<IStory> =
|
|
|
|
/* mongoose.models.Story || */ mongoose.model(
|
|
|
|
"Story",
|
|
|
|
StorySchema,
|
|
|
|
"stories",
|
|
|
|
);
|