38 lines
863 B
TypeScript
38 lines
863 B
TypeScript
import { IStory } from ".";
|
|
import { hasMigrated } from "@dbconfig";
|
|
import mongoose, { Schema, Model } from "mongoose";
|
|
import SequenceFactory from "mongoose-sequence";
|
|
import { Chapter } from "./chapter";
|
|
|
|
const AutoIncrement = SequenceFactory(mongoose);
|
|
|
|
export type IDraft = Omit<IStory, "recs" | "favs" | "reviews" | "views" | "downloads" | "posted">;
|
|
|
|
// const Cha
|
|
|
|
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],
|
|
},
|
|
{ timestamps: true },
|
|
);
|
|
|
|
hasMigrated && !mongoose.models.Draft && DraftSchema.plugin(AutoIncrement, { id: "drafts" });
|
|
|
|
export const Draft: Model<IDraft> = /* mongoose.models.Draft || */ mongoose.model("Draft", DraftSchema, "drafts");
|