From 9fe4d0c9793af3d78988c75dd420d3f063913558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Tue, 3 Oct 2023 01:11:32 -0400 Subject: [PATCH] feat(db/models): add co-author field to stories --- models/stories/index.ts | 62 ++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/models/stories/index.ts b/models/stories/index.ts index 679c857..9360a52 100644 --- a/models/stories/index.ts +++ b/models/stories/index.ts @@ -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"; const AutoIncrement = SequenceFactory(mongoose); import { Chapter, IChapter } from "./chapter"; -import {IUser} from "../../models/user"; -import { Ficmas, IFicmas } from "../../models/challenges/ficmas"; -import { IChallenge, Challenge } from "../../models/challenges/gen"; -import { hasMigrated } from "../../lib/dbconfig"; +import { IUser } from "~/models/user"; +import { Ficmas, IFicmas } from "~/models/challenges/ficmas"; +import { IChallenge, Challenge } from "~/models/challenges/gen"; +import { hasMigrated } from "~/lib/dbconfig"; -export interface IStory extends Document { +export interface IStory { _id?: number; title: string; author: PopulatedDoc; - chapters: IChapter[] + chapters: IChapter[]; recs: number; favs: number; reviews: number; @@ -24,63 +24,75 @@ export interface IStory extends Document { downloads: number; lastUpdate: Date; posted: Date; + coAuthor: PopulatedDoc | null; } const StorySchema = new mongoose.Schema({ _id: { - type: Number + type: Number, }, title: { - type: String + type: String, }, author: { type: Number, - ref: "User" + ref: "User", + }, + coAuthor: { + type: Number, + ref: "User", + default: null, }, chapters: [Chapter], recs: { type: Number, - default: 0 + default: 0, }, favs: { type: Number, - default: 0 + default: 0, }, reviews: { type: Number, - default: 0 + default: 0, }, views: { type: Number, - default: 0 + default: 0, }, completed: { type: Boolean, - default: false + default: false, }, challenge: { type: Number, ref: "Challenge", - default: null + default: null, }, ficmas: { type: Number, ref: "Ficmas", - default: null + default: null, }, downloads: { type: Number, - default: 0 + default: 0, }, lastUpdate: { type: Date, - default: new Date() + default: new Date(), }, posted: { type: Date, - default: new Date() - } -}) -hasMigrated && Chapter.plugin(AutoIncrement, {id: "chapterid", inc_field: "id"}) -hasMigrated && StorySchema.plugin(AutoIncrement, {id: "storyid"}) -export const Story: Model = /* mongoose.models.Story || */ mongoose.model("Story", StorySchema, "stories") + default: new Date(), + }, +}); +hasMigrated && + Chapter.plugin(AutoIncrement, { id: "chapterid", inc_field: "id" }); +hasMigrated && StorySchema.plugin(AutoIncrement, { id: "storyid" }); +export const Story: Model = + /* mongoose.models.Story || */ mongoose.model( + "Story", + StorySchema, + "stories", + );