next/models/stories/draft.ts

38 lines
863 B
TypeScript
Raw Normal View History

import { IStory } from ".";
import { hasMigrated } from "@dbconfig";
2023-12-29 20:11:07 -05:00
import mongoose, { Schema, Model } from "mongoose";
import SequenceFactory from "mongoose-sequence";
import { Chapter } from "./chapter";
const AutoIncrement = SequenceFactory(mongoose);
2023-12-29 20:11:07 -05:00
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 },
);
2023-12-29 20:11:07 -05:00
hasMigrated && !mongoose.models.Draft && DraftSchema.plugin(AutoIncrement, { id: "drafts" });
2023-12-29 20:11:07 -05:00
export const Draft: Model<IDraft> = /* mongoose.models.Draft || */ mongoose.model("Draft", DraftSchema, "drafts");