feat(db/models): add co-author field to stories

This commit is contained in:
parent 490fa1469e
commit 9fe4d0c979
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C

@ -1,19 +1,19 @@
import mongoose, {Schema, PopulatedDoc, Document, Model} from "mongoose"; import mongoose, { Schema, PopulatedDoc, Document, Model } from "mongoose";
import SequenceFactory from "mongoose-sequence"; import SequenceFactory from "mongoose-sequence";
const AutoIncrement = SequenceFactory(mongoose); const AutoIncrement = SequenceFactory(mongoose);
import { Chapter, IChapter } from "./chapter"; import { Chapter, IChapter } from "./chapter";
import {IUser} from "../../models/user"; import { IUser } from "~/models/user";
import { Ficmas, IFicmas } from "../../models/challenges/ficmas"; import { Ficmas, IFicmas } from "~/models/challenges/ficmas";
import { IChallenge, Challenge } from "../../models/challenges/gen"; import { IChallenge, Challenge } from "~/models/challenges/gen";
import { hasMigrated } from "../../lib/dbconfig"; import { hasMigrated } from "~/lib/dbconfig";
export interface IStory extends Document { export interface IStory {
_id?: number; _id?: number;
title: string; title: string;
author: PopulatedDoc<IUser & Document>; author: PopulatedDoc<IUser & Document>;
chapters: IChapter[] chapters: IChapter[];
recs: number; recs: number;
favs: number; favs: number;
reviews: number; reviews: number;
@ -24,63 +24,75 @@ export interface IStory extends Document {
downloads: number; downloads: number;
lastUpdate: Date; lastUpdate: Date;
posted: Date; posted: Date;
coAuthor: PopulatedDoc<IUser & Document> | null;
} }
const StorySchema = new mongoose.Schema<IStory>({ const StorySchema = new mongoose.Schema<IStory>({
_id: { _id: {
type: Number type: Number,
}, },
title: { title: {
type: String type: String,
}, },
author: { author: {
type: Number, type: Number,
ref: "User" ref: "User",
},
coAuthor: {
type: Number,
ref: "User",
default: null,
}, },
chapters: [Chapter], chapters: [Chapter],
recs: { recs: {
type: Number, type: Number,
default: 0 default: 0,
}, },
favs: { favs: {
type: Number, type: Number,
default: 0 default: 0,
}, },
reviews: { reviews: {
type: Number, type: Number,
default: 0 default: 0,
}, },
views: { views: {
type: Number, type: Number,
default: 0 default: 0,
}, },
completed: { completed: {
type: Boolean, type: Boolean,
default: false default: false,
}, },
challenge: { challenge: {
type: Number, type: Number,
ref: "Challenge", ref: "Challenge",
default: null default: null,
}, },
ficmas: { ficmas: {
type: Number, type: Number,
ref: "Ficmas", ref: "Ficmas",
default: null default: null,
}, },
downloads: { downloads: {
type: Number, type: Number,
default: 0 default: 0,
}, },
lastUpdate: { lastUpdate: {
type: Date, type: Date,
default: new Date() default: new Date(),
}, },
posted: { posted: {
type: Date, type: Date,
default: new Date() default: new Date(),
} },
}) });
hasMigrated && Chapter.plugin(AutoIncrement, {id: "chapterid", inc_field: "id"}) hasMigrated &&
hasMigrated && StorySchema.plugin(AutoIncrement, {id: "storyid"}) Chapter.plugin(AutoIncrement, { id: "chapterid", inc_field: "id" });
export const Story: Model<IStory> = /* mongoose.models.Story || */ mongoose.model("Story", StorySchema, "stories") hasMigrated && StorySchema.plugin(AutoIncrement, { id: "storyid" });
export const Story: Model<IStory> =
/* mongoose.models.Story || */ mongoose.model(
"Story",
StorySchema,
"stories",
);