2023-10-03 01:13:16 -04:00
|
|
|
import { IStory } from ".";
|
2023-12-20 17:23:31 -05:00
|
|
|
import { hasMigrated } from "@dbconfig";
|
2023-12-29 20:11:07 -05:00
|
|
|
import mongoose, { Schema, Model } from "mongoose";
|
2023-09-25 19:19:32 -04:00
|
|
|
import SequenceFactory from "mongoose-sequence";
|
2023-10-03 01:13:16 -04:00
|
|
|
import { Chapter } from "./chapter";
|
2023-09-25 19:19:32 -04:00
|
|
|
|
|
|
|
const AutoIncrement = SequenceFactory(mongoose);
|
|
|
|
|
2023-12-29 20:11:07 -05:00
|
|
|
export type IDraft = Omit<IStory, "recs" | "favs" | "reviews" | "views" | "downloads" | "posted">;
|
2023-10-03 01:13:16 -04:00
|
|
|
|
|
|
|
// const Cha
|
2023-09-25 19:19:32 -04:00
|
|
|
|
2023-12-29 16:36:26 -05:00
|
|
|
const DraftSchema = new Schema<IDraft>(
|
|
|
|
{
|
|
|
|
title: {
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
_id: {
|
|
|
|
type: Number,
|
|
|
|
},
|
|
|
|
coAuthor: {
|
|
|
|
type: Number,
|
|
|
|
ref: "User",
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
author: {
|
|
|
|
type: Number,
|
|
|
|
ref: "User",
|
|
|
|
},
|
|
|
|
chapters: [Chapter],
|
2023-09-25 19:19:32 -04:00
|
|
|
},
|
2023-12-29 16:36:26 -05:00
|
|
|
{ timestamps: true },
|
|
|
|
);
|
2023-09-25 19:19:32 -04:00
|
|
|
|
2023-12-29 20:11:07 -05:00
|
|
|
hasMigrated && !mongoose.models.Draft && DraftSchema.plugin(AutoIncrement, { id: "drafts" });
|
2023-09-25 19:19:32 -04:00
|
|
|
|
2023-12-29 20:11:07 -05:00
|
|
|
export const Draft: Model<IDraft> = /* mongoose.models.Draft || */ mongoose.model("Draft", DraftSchema, "drafts");
|