next/models/stories/draft.ts
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ a8e113e969
refactor(db/models): remove model existence guards
this way, plugins are registered if `hasMigrated` is true. we've already enabled automatically overwriting models, therefore, the guard's condition will always be false
2023-12-29 16:36:26 -05:00

46 lines
1.0 KiB
TypeScript

import { IStory } from ".";
import { hasMigrated } from "@dbconfig";
import { IBand } from "@models/band";
import { IFicmas } from "@models/challenges/ficmas";
import { IChallenge } from "@models/challenges/gen";
import { IUser } from "@models/user";
import mongoose, { Schema, PopulatedDoc, Document, 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 && DraftSchema.plugin(AutoIncrement, { id: "drafts" });
export const Draft: Model<IDraft> =
/* mongoose.models.Draft || */ mongoose.model("Draft", DraftSchema, "drafts");